function checkMail(emailad){
	
    var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check=/@[\w\-]+\./;
    var checkend=/\.[a-zA-Z]{2,3}$/;
    if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
        return false;
    }
    else {
        return true;
    }
	
}

function getInputs( form ){

	resultInputs = "";

	arrForm = form.getElementsByTagName('select');

	for( x = 0 ; x < arrForm.length ; x++  ){

		if( form.getElementsByTagName('select')[x].title != "" )
		resultInputs += form.getElementsByTagName('select')[x].name+";"+form.getElementsByTagName('select')[x].title+",";

	}

	arrForm = form.getElementsByTagName('input');

	for( x = 0 ; x < arrForm.length ; x++  ){

		if( form.getElementsByTagName('input')[x].title != "" )
		resultInputs += form.getElementsByTagName('input')[x].name+";"+form.getElementsByTagName('input')[x].title+",";

	}

	arrForm = form.getElementsByTagName('textarea');

	for( x = 0 ; x < arrForm.length ; x++  ){

		if( form.getElementsByTagName('textarea')[x].title != "" )
		resultInputs += form.getElementsByTagName('textarea')[x].name+";"+form.getElementsByTagName('textarea')[x].title+",";

	}

	resultInputs = resultInputs.substr(0,(resultInputs.length-1))

	return resultInputs;

}

/**
* Required forms
* @Event OnSubmit
* @since 11/09/2006
* @author Michael Rodrigues Mafort <michaelmafort@gmail.com.com>
* @access public
* @sample required(this)
*/

function required(form){

	inputName = getInputs(form);
	arrData = inputName.split(",");
	control = 0;

	for( i = arrData.length-1; i > -1 ; i-- ){

		elem_obj = new Array();
		elem_obj = arrData[i].split(";");
		id = elem_obj[0];
		fieldName = elem_obj[1];
		
		document.getElementById(id).style.borderRight = "0";
		
		if( ( (document.getElementById(id).name == "mail_str") || (document.getElementById(id).name == "mail_aux") ) && document.getElementById(id).value != "" ){
		
			if( ( checkMail(document.getElementById(id).value)==false ) && (document.getElementById(id).value != "")){
				control = 1;
				document.getElementById(id).style.borderRight = "2px solid red";
			}
		}
		
		if( document.getElementById(id).value == "" ){

			control = 1;

			document.getElementById(id).style.borderRight = "2px solid red";

		}

	}

	if( control == 1 ){

		alert( 'Preecha corretamente os campos assinalados em vermelho.' );

		return false;

	}

	return true;

}

