// JavaScript Document
/* Apply Text box CSS and Error Text Box CSS */
function resetTextBoxCSS(object){
	object.style.border='1px solid #d8d8d8';
	object.style.background='#ffffff';
}
function applyErrorTextBoxCSS(object){
	object.style.border='1px solid #c9010b';
	object.style.background='#ffd5d7';
}

function check_form(form_name,exceptions){
	//get the fields that will not be checked
	var except_name = exceptions.split(',');
	
	var check_form = true;

	form = document.getElementById(form_name);

	//get all the fields of the form
	for (c=0;c<form.length;c++){
		//check the type of fields
		if(form[c].type=='text' || form[c].type=='password' || form[c].type=='textarea' || form[c].type=='checkbox' || form[c].type=='radio' || form[c].type=='select-one' || form[c].type=='select-multiple'){
			//check if the field is an exception
			var exception_check = false;
			
			for(x=0;x<except_name.length;x++){
				if(form[c].name==except_name[x]){
					 exception_check = true;
				}
			}
			
			if(exception_check==false){
				if(form[c].value==''){
					applyErrorTextBoxCSS(form[c]);
					check_form = false;
				}
				else{
					if((form[c].name=='email')||(form[c].name=='senderemail')||(form[c].name=='recipientemail')){
						// Validate Emailaddress
						if(check_email(form[c].value)==false){
							applyErrorTextBoxCSS(form[c]);
							check_form = false;					
							var error_type = 'email';
						}
						else{
							resetTextBoxCSS(form[c]);
						}
					}
					else{
						resetTextBoxCSS(form[c]);
					}
				}
			}
		}
	}
	
	if(check_form==false){
		if(error_type!='email'){
			alert('Please complete the fields highlighted in red or indicated by a * correctly');
		}
		return false;
	}
	else{
		return true;
	}
}
