function checkRequired(str) {
	if (str.length == 0) {
		return(false);
	}else {
		return(true);
	}
}

function checkInputMatch(str1,str2) {
 	if (str1 == str2)
 		return(true);
 	else
 		return(false);
}

function validEmailAddress(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	//"@" symbol not found
	if (str.indexOf(at)==-1){	   
	   return false;
	}

	//"@" symbol not found or at the beginning of the string str or the end
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){	   
	   return false;
	}

	//"." not found or at the beginning of the string str or the end
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){	  
	   return false;
	}

	//"@" symbol occurs more than once in the string
	if (str.indexOf(at,(lat+1))!=-1){	    
	    return false;
	}

	//"." just before the "@" symbol or just after the "@" symbol
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){	    
	    return false;
	}

	//there is no occurance of the "." at least two characters after the "@" symbol 
	if (str.indexOf(dot,(lat+2))==-1){	   
	    return false;
	}
	
	//there is at least on space or blank in the email address
	 if (str.indexOf(" ")!=-1){	   
	   return false;
	}

    return true;
}



function validateContactForm(){			
	
	if (!checkRequired(document.getElementById("nametext").value)){
		
		document.getElementById("nametext").focus();
		document.getElementById("nametext").select();
		
		alert("Please enter your name.");
		
		return false;
	}
	
	if (!checkRequired(document.getElementById("emailaddresstext").value)){
		
		document.getElementById("emailaddresstext").focus();
		document.getElementById("emailaddresstext").select();
		
		alert("Please enter your email address.");
		
		return false;
	}
	
	if (!validEmailAddress(document.getElementById("emailaddresstext").value)){
		
			document.getElementById("emailaddresstext").focus();
			document.getElementById("emailaddresstext").select();
		
			alert("Please enter a valid email address.");
		
			return false;	
	}
	
	if (!checkRequired(document.getElementById("contactnumbertext").value)){
		
		document.getElementById("contactnumbertext").focus();
		document.getElementById("contactnumbertext").select();
		
		alert("Please enter your contact number.");
		
		return false;
	}
	
	return true;
}

