//Functions to validate order form submission at M57 order page.

function checkCountry() {
	var countries=document.getElementById("shortcountry");
	var states=document.getElementById("shortstate");
	var selectedcountry=countries.options[countries.selectedIndex].value;

	if (selectedcountry=='US' || selectedcountry=='CA')
	{
		if (document.getElementById("OT").selected == true) {
		
			document.getElementById("nostate").selected = true;			
		}
		
		document.getElementById("shortstate").disabled = false;
		
	} else {
		
		document.getElementById("OT").selected = true;
		document.getElementById("shortstate").disabled = true;

	}

}



function echeck(str) {

		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
		 }

 		 return true
	}





function isValidEmail(str) {

   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);



}


function Validate()
{



if (document.form1.name_f.value == '') {
   alert('Please fill in your first name.');
    return false;
    }

if (document.form1.name_l.value == '') {
   alert('Please fill in your last name.');
    return false;
    }

if (document.form1.address1.value == '') {
   alert('Please fill in your street address.');
    return false;
    }

if (document.form1.city.value == '') {
   alert('Please fill in your city.');
    return false;
    }


if (document.form1.shortstate.value == '') {
   alert('Please select your state.');
    return false;
    }

if (document.form1.zipcode.value == '') {
   alert('Please fill in your zip code.');
    return false;
    }

if (document.form1.shortcountry.value == '') {
   alert('Please select your country.');
    return false;
    }

if (document.form1.phonenumber.value == '') {
   alert('Please fill in your telephone number.');
    return false;
    }


if (document.form1.email.value == '') {
   alert('Please fill in your email address.');
    return false;
    }

if (!echeck(document.form1.email.value)) {
   alert('The email address is not valid.');
    return false;
    }


return true;

}

