// JavaScript Document
function acceptOnlyNumbers1()
 {
 	var isNS4 = (navigator.appName=="Netscape")?1:0;
	if(!isNS4){if(event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;}else{if(event.which < 45 || event.which > 57) returnfalse;}
 }
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

function jumbcursor(ctrl)
{
	var phonectrval = ctrl.value;

	if(ctrl == document.index.phone1)
	{
		if((phonectrval.length) == 3)
		{

			document.index.phone2.focus();
		}

	}else if(ctrl == document.index.phone2)
	{
		if(phonectrval.length == 3)
		{
			document.index.phone3.focus();
		}
	}
}

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){
		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;

}

function validate()
{
	if(trim(document.index.fn.value) == "")
	{
		alert("Please enter your First Name.");
		document.index.fn.focus();
		document.index.fn.value = "";
		return false;
	}
	if(trim(document.index.ln.value) == "")
	{
		alert("Please enter your Last Name.");
		document.index.ln.focus();
		document.index.ln.value = "";
		return false;
	}
   
   var chks = document.index.elements['g'];
   var hasChecked = true;
   for (var i=0;i<chks.length;i++)
	{
		if (chks[i].checked)
		{			
			hasChecked = false;
			break;
		}		
	}
	if (hasChecked)
	{
		alert("Please select your Gender.");
		chks[0].focus();
		return false;
	}
	
	if(document.index.month.selectedIndex == 0)
	{
		alert("Please select your Month of Birth.");
		document.index.month.focus();
		return false;
	} 
	if(document.index.day.selectedIndex == 0)
	  {
		alert("Please select your Day of Birth.");
		document.index.day.focus();
		return false;
	} 
	if(document.index.year.selectedIndex == 0)
	{
		alert("Please select your Year of Birth.");
		document.index.year.focus();
		return false;
	}
	var dob= trim(document.index.month.value) + "-" + trim(document.index.day.value) + "-" + trim(document.index.year.value);
	var  age = getAge(dob,3);
    if(age < 18)
	  {
		alert("You must be at least 18 years of age to use our site.");
		return false;
	  }

	if(trim(document.index.a.value) == "")
	{
		alert("Please enter your Address.");
		document.index.a.focus();
		document.index.a.value = "";
		return false;
	}
	if(document.index.s.selectedIndex == 0)
	{
		alert("Please select your State.");
		document.index.s.focus();
		return false;
	}
   	
   var zip = document.index.z.value;
	
	if(trim(zip) == "")
	{
		alert("Please enter your Zip Code.");
		document.index.z.focus();
		document.index.z.value = "";
		return false;
	}
	
	if(trim(zip) != "")
	{
		var zip_len = (zip.length);
		if(zip_len<5)
		 {
		 	alert("Zip Code should be 5 Digits");		
			document.index.z.focus();
			return false;
		 } 
	}
	
	var phone1 = document.index.phone1.value;
	var phone2 = document.index.phone2.value;
	var phone3 = document.index.phone3.value;
	
	if(trim(phone1) == "")
	{
		alert("Please enter your Phone Number.");
		document.index.phone1.focus();
		document.index.phone1.value = "";
		return false;
	}
		 
	if(trim(phone1) != "")
	{
		var phone1_len = (phone1.length);
		if(phone1_len != 3)
		 {
		 	alert("3 Numbers needed.");		
			document.index.phone1.focus();
			return false;
		 } 
	}
	
	if(trim(phone2) == "")
	{
		alert("Please enter your Phone Number.");
		document.index.phone2.focus();
		document.index.phone2.value = "";
		return false;
	}
	
	if(trim(phone2) != "")
	{
		var phone2_len = (phone2.length);
		if(phone2_len != 3)
		 {
		 	alert("3 Numbers needed.");		
			document.index.phone2.focus();
			return false;
		 } 
	}
	
	if(trim(phone3) == "")
	{
		alert("Please enter your Phone Number.");
		document.index.phone3.focus();
		document.index.phone3.value = "";
		return false;
	}
	
	if(trim(phone3) != "")
	{
		var phone3_len = (phone3.length);
		if(phone3_len != 4)
		 {
		 	alert("4 Numbers needed.");		
			document.index.phone3.focus();
			return false;
		 } 
	}
    
	if(document.getElementById('flagAjax').value  == 0 )
	{
	    alert("The information you entered was not correct. Please try again.");
		document.index.phone1.focus();
		return false;
	}
	
	if(trim(document.index.em.value) == "")
	{
		alert("Please provide your Email Address.");
		document.index.em.focus();
		return false;
	}
	if(!echeck(trim(document.index.em.value)))
	{
		alert('Email Address is not valid.');
	    document.index.em.focus();
    	return false;
	}
    
	if(document.index.agreedtersm.checked == false)
	{
		alert("Please read and accept the Terms and Conditions and Privacy Policy and check the box.");
		document.index.agreedtersm.focus();
		return false;
	}
	
 return true;
 
}
