
// Rollover images used on the Contact Us page
cu_go_button_off = new Image;
cu_go_button_on = new Image;
cu_go_button_off.src="images/Contact_Us/cu_go.gif";
cu_go_button_on.src="images/Contact_Us/cu_go_hit.gif";


function submitContactUs() {
	if(validateForm()) {
		setEnvironmentDetails();
		document.contactusform.frmAction.value = "submit";
		document.contactusform.submit();
	}
}

function validateForm(){
	var xmsg ='';
 
	if(isBlank(document.contactusform.firstname.value)){
   		xmsg += 'You need to fill in your first name. ';
	}
 
	if(isBlank(document.contactusform.surname.value)){
   		xmsg += 'You need to fill in your last name. ';
	}
  
	if(!checkMail(document.contactusform.email.value,false)){
		xmsg += 'Sure you got the email address right? ';
	}
	
	var i = document.contactusform.question_type.selectedIndex;
	var qtype = document.contactusform.question_type.options[i].value;
	if (qtype == 'default') {
		xmsg += 'You need to select the type of question. ';
	}
	
	if(isBlank(document.contactusform.query.value,false)){
		xmsg += 'You need to fill in your question. ';
	}
  
	if(xmsg != ''){
   		alert(xmsg);
   		return(false);
	}else{
   		return(true);
	}
}

function checkMail(email_field, produce_alert){
	var ret_bool = true;
 	var x = '';
 	x = email_field;
 	if(!x == ''){
   		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
   		if (filter.test(x)){
     		ret_bool = true;
   		} else {
     		if(produce_alert)
       		alert('NO! Incorrect email address');
     		ret_bool = false;
   		}
 	} else {
   	if(produce_alert)
     	alert('Please enter an email address');
   		ret_bool = false;
 	}
 	return (ret_bool);
}

function isBlank(s){
 	if((s == null)||(s == ""))
   		return true;
 	else
   		return false;
}

function setEnvironmentDetails() {
	document.contactusform.browser.value = navigator.userAgent;
	var scr = 'height: ' + screen.height + 'px. ' +
			  'width: ' + screen.width + 'px. ' +
			  'colours: ' + screen.colorDepth + 'bpp';
	document.contactusform.screen.value = scr;
}
