// JavaScript Document
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str, trial) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (trial) {
			 if (str.indexOf("@hotmail.")!=-1 || str.indexOf("@live.")!=-1 || str.indexOf("@gmail.")!=-1 || str.indexOf("@googlemail.")!=-1 || str.indexOf("@yahoo.")!=-1){
				alert("So that we may validate your request, please do not use a free email account such as hotmail, google or yahoo.")
				return false
			 }
		 }

		 return true					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
 function checkContactForm(trialrequest) {
	var senderemail=document.emailform.sendersemail;
	var sendername=document.emailform.sendername;
	var senderorg=document.emailform.senderorg;
	var senderrole=document.emailform.senderrole;
	var subject=document.emailform.subject;
	var message=document.emailform.message;
	var checkok = true;
	var alertmessage = "";
	
	if ((sendername.value==null)||(sendername.value=="")){
		alertmessage += "Please enter your name\n";
		sendername.focus();
		checkok = false;
	}
	if ((senderemail.value==null)||(senderemail.value=="")){
		alertmessage += "Please enter your email address\n";
		//alert("Please enter your email address");
		senderemail.focus();
		checkok = false;
	} else if (echeck(senderemail.value, trialrequest)==false){
		alertmessage += "Please enter a valid email address\n";
		senderemail.value="";
		senderemail.focus();
		checkok = false;
	}
	if ((senderorg.value==null)||(senderorg.value=="")){
		alertmessage += "Please enter your organisation\n";
		senderorg.focus();
		checkok = false;
	}
	if ((senderrole.value==null)||(senderrole.value=="")){
		alertmessage += "Please enter your job \n";
		senderrole.focus();
		checkok = false;
	}
	if ((subject.value==null)||(subject.value=="")){
		alertmessage += "Please enter a subject\n";
		subject.focus();
		checkok = false;
	}
	if ((message.value==null)||(message.value=="")){
		alertmessage += "Please enter your message\n";
		message.focus();
		checkok = false;
	}
	if (checkok) {
		document.emailform.submit();
	} else {
		alert(alertmessage);
	}
}
