// validateforms.js

function validateMandatoryFields(){
	valid = true;

    if (document.contactform.firstname.value == "" ){
        alert("Please fill in the 'First Name' field.");
        valid = false;
    }
    if (document.contactform.lastname.value == "" ){
        alert("Please fill in the 'Last Name' field.");
        valid = false;
    }
    if (document.contactform.phonenumber.value == "" ){
        alert("Please fill in the 'Phone Number' field.");
        valid = false;
    }
    if (document.contactform.spam.value == "" ){
        alert("Please fill in single number from 5-10 in the 'Anti Spam1' field.");
        valid = false;
    }else{
        if ( (document.contactform.spam.value < 5 ) ||
        		(document.contactform.spam.value > 10 )){
            alert("Please fill in single number from 5-10 in the 'Anti Spam2' field.");
            valid = false;
        }
    }
    
    return valid;
}

function emailValid(str){

		var at = "@";
		var dot = ".";
		var lat = str.indexOf(at);
		var lstr = str.length;
		var ldot = str.indexOf(dot);
		valid = true;
		
		if (str.indexOf(at) != -1){//empty field is not validated
			//test presence of at sign
			if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr){
			   alert("Invalid e-mail address entered in field. 2");
			   valid = false;
			}
			//test presence of dot
			if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr){
			   alert("Invalid e-mail address entered in field. 3");
			   valid = false;
			}
	        
	        if (str.indexOf(at,(lat + 1)) != -1){
		    	alert("Invalid e-mail address entered in field. 4");
		        valid = false;
		    }
			if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot){
		   		alert("Invalid e-mail address entered in field. 5");
			    valid = false;
		 	}

		 	if (str.indexOf(dot,(lat + 2)) == -1){
		   		alert("Invalid e-mail address entered in field. 6");
		   		valid = false;
		 	}
		
		 	if (str.indexOf(" ") != -1){
		   		alert("Invalid e-mail address entered in field. 7");
		   		valid = false;
		 	}		    
		}

/*		if (str.indexOf(at) == -1){
		   alert("Invalid e-mail address entered in field. 1");
		   valid = false;
		}

		if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr){
		   alert("Invalid e-mail address entered in field. 2");
		   valid = false;
		}

		if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr){
		   alert("Invalid e-mail address entered in field. 3");
		   valid = false;
		}

		 if (str.indexOf(at,(lat + 1)) != -1){
		   alert("Invalid e-mail address entered in field. 4");
		   valid = false;
		 }

		 if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot){
		   alert("Invalid e-mail address entered in field. 5");
		   valid = false;
		 }

		 if (str.indexOf(dot,(lat + 2)) == -1){
		   alert("Invalid e-mail address entered in field. 6");
		   valid = false;
		 }
		
		 if (str.indexOf(" ") != -1){
		   alert("Invalid e-mail address entered in field. 7");
		   valid = false;
		 }*/

 		 return valid;					
}


