// Global variables:



//---------------Verify Enquiry fields----------------------------------------


function VerifyEnquiry() {

	var themessage = "Please fill in the following fields: \n\n";
	
	//first construct the message
	if (document.form1.name.value == "") {
		themessage = themessage + " - Name\n";
	}
	
	if (ValidateForm() == false) {
		themessage = themessage + " - Email Address eg. yourname@domain.com \n";
	}
	
	if (document.form1.comment.value == ""){
		themessage = themessage + " - Comment\n";
	}
	
	if (document.form1.captcha.value == "" || document.form1.captcha.value != "9642") {
		themessage = themessage + " - please enter the correct code";
	}
	
	//then set the focus in the right order
	if (document.form1.captcha.value == "" || document.form1.captcha.value != "9642") {
		document.form1.captcha.focus();
		document.form1.captcha.select();
	}
	
	if (document.form1.comment.value == "") {
		document.form1.comment.focus();
		//document.form1.first_name.select();
	}
	
	if (ValidateForm() == false) {
		document.form1.email.focus();
		document.form1.email.select();
	}
	
	if (document.form1.name.value == ""){
		document.form1.name.focus();
		document.form1.name.select();
	}
	
	
	
	//decide to submit or not
	if (themessage == "Please fill in the following fields: \n\n") {
		document.form1.submit();
		return false;
	} else { 
		alert(themessage);
		return false;
   }
   
}


//---------------Verify RM field boxes----------------------------------------
//This is the right menu inlcude on the services pages
//verify information on the contact enquiry form
function rmVerify() {

	var themessage = "Please fill in the following fields: \n\n";
	
	//first construct the message
	if (document.form2.name.value == "" || document.form2.name.value == "Name") {
		themessage = themessage + " - Name\n";
	}
	
	if (ValidateForm() == false) {
		themessage = themessage + " - Email Address eg. yourname@domain.com \n";
	}
	
	if (document.form2.captcha.value == "" || document.form2.captcha.value != "9642") {
		themessage = themessage + " - please enter the correct code";
	}
	
	//then select the correct text box
	if (document.form2.captcha.value == "" || document.form2.captcha.value != "9642") {
		document.form2.captcha.focus();
		document.form2.captcha.select();
	}
	
	if (ValidateForm() == false) {
		document.form2.email.focus();
		document.form2.email.select();
	}
	
	if (document.form2.name.value == "" || document.form2.name.value == "Name") {
		document.form2.name.focus();
		document.form2.name.select();
	}
	
	
	
	//decide to submit or not
	if (themessage == "Please fill in the following fields: \n\n") {
		document.form2.submit();
		return false;
	} else { 
		alert(themessage);
		return false;
   }
   
}

//---------------Email Address Validation --------------------------
//validate email address
function ValidateForm() {

	var emailID = document.getElementById('email');

	if ((emailID.value==null)||(emailID.value=="")){
		return false;
	}
	if (echeck(emailID.value)==false){
		return false;
	}
	
	return true;
 }
 
//validate email address continued
function echeck(str) {
		
		//alert("part2");
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;				
}


//---------------Max length of text input-------------------------
//sets the max length of the textinput in contact page
function ismaxlength(obj){

	var mlength=500;

	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value=obj.value.substring(0,mlength);
	}
}


//---------------Clear the RM field boxes----------------------------------------
//Services pages - clear default values of the input fields
function rmFieldOnFocus(id,FieldValue,action) {
	
	if (action == "focus") {
		if (document.getElementById(id).value == FieldValue) {
			document.getElementById(id).value = "";
		}
	}
	
	if (action == "blur") {
		if (document.getElementById(id).value == '') {
			document.getElementById(id).value = FieldValue;
		}
	}
}






















