//*****************************************
function ignoreChar(string, ch) 
{
	var temp = "";
	string = '' + string;
	splitstring = string.split(ch);
	for(i = 0; i < splitstring.length; i++)
	temp += splitstring[i];
	return temp;
}

function insertChar(string, ch) 
{
	var temp = "";
	temp=string.substring(0, 3) + ch;
	//alert (string.substring(0, 3));
	//alert (string.substring(3, 6));
	//alert (string.substring(6, 10));
	temp+=string.substring(3, 6) + ch+string.substring(6, 10);

	//alert (temp);
	return temp;
}
//*******************************************

function CheckZip(obj)
{
		var sValue=obj.value;
		var iDigits = obj.value.length;
		var GoodChars = "0123456789"
		var i = 0
		if( !(iDigits==5 || iDigits==0))
			//alert("Please enter valid zip code4 digits.");
			return false;
        if( (iDigits==5))
        {
		   for (i =0; i <= iDigits -1; i++) 
		   {
			if (GoodChars.indexOf(sValue.charAt(i)) == -1) 
			{
				//alert("Please 2.");
				return false;
			} 
		   } 
		}
	return true;

}

function CheckZip2(obj)
{
		var sValue=obj.value;
		var iDigits = obj.value.length;
		var GoodChars = "0123456789"
		var i = 0
		//if(SpacesOnly(obj)) {
		    //alert("Please 0.");return false; }
		if( !(iDigits==4 || iDigits==0))
			//alert("Please enter valid zip code4 digits.");
			return false;
        if( (iDigits==4))
        {
		   for (i =0; i <= iDigits -1; i++) 
		   {
			if (GoodChars.indexOf(sValue.charAt(i)) == -1) 
			{
				//alert("Please 2.");
				return false;
			} 
		   } 
		}
	return true;

}


//***********************************************************

function SpacesOnly(field)
{
	//alert ('so');
	if (field.length != 0)
	 {
		
	  foundchar = false
	  for (i = 0; i <= field.length - 1; i++)
	   {
	   
	    if (field.substring(i,1) != ' ')
	    //alert ('in loop');
		 {
			
		  foundchar = true;
		  break;
		 }
	   }
	   if (foundchar)
		return false;
	 }
	return true;
}
//*********************************************************
	function CheckEmail()
	{
	//alert("email");
	var email=document.forms[0].email.value.toLowerCase();
	if (email.length == 0 || SpacesOnly(email))
		{
			document.forms[0].email.focus;	
			return false;
		}
		
	if (email.indexOf("@")==-1) 
		{			
		document.forms[0].email.value="";
		document.forms[0].email.focus;
		return false;
		}
	if (email.indexOf("..")!=-1) 
		{			
		document.forms[0].email.value="";
		document.forms[0].email.focus;
		return false;
		}	
	if (email.indexOf("@.")!=-1) 
		{			
		document.forms[0].email.value="";
		document.forms[0].email.focus;
		return false;
		}	
	if (email.charAt(0)=="@") 
		{			
		document.forms[0].email.value="";
		document.forms[0].email.focus;
		return false;
		}
	if (email.charAt(email.length-1)==".") 
		{			
		document.forms[0].email.value="";
		document.forms[0].email.focus;
		return false;
		}
	if (email.indexOf(".gov")==-1 && email.indexOf(".com")==-1 && email.indexOf(".us")==-1
		&& email.indexOf(".net")==-1 && email.indexOf(".edu")==-1 && email.indexOf(".org")==-1)
		{			
		document.forms[0].email.value="";
		document.forms[0].email.focus;
		return false;
		}
		
		return true;
	
	}
	
	//*******************************************
	function CheckPhone(field)
	{
		var sValue;
		//alert("ph");
		sValue=ignoreChar(field.value, " ");
		sValue=ignoreChar(sValue, "-");
		//field.value=sValue;
		//var sval1=ignoreChar(sValue, "(");
		//sval1=ignoreChar(sval1, ")");
		//var iDig1 = sval1.length;
		sValue=ignoreChar(sValue, "(");
		sValue=ignoreChar(sValue, ")");
		var iDigits = sValue.length;

		var GoodChars = "0123456789";
		var i = 0;
		
		if( !(iDigits==10))
			{
				return false;
			}
			
		for (i =0; i <= iDigits -1; i++) 
		{
			if (GoodChars.indexOf(sValue.charAt(i)) == -1) 
			{
				return false;
			} 
		} 
		document.forms[0].phone.value=insertChar(sValue, "-");
		
		return true;
		
			
		
	}
	
//******************check empty text and select objects***************************
	function CheckEmptyText(obj)
	{
		if (obj.type=="select-one")
			st=new String(obj.options[obj.selectedIndex].value);
		else
			st=new String(obj.value);
		if (st.length == 0 || SpacesOnly(st))
		{	
			obj.focus();
			return false;
		}
		else
			return true;
	}	
	
	
//************************************        
function ValidateForm() {
//alert ("val");
    var form = document.forms[0];
//this is for "

                strTFName= form.fname.value
		strTLName= form.lname.value
		strTAddress= form.address.value
		strTApt= form.apt.value
		strTCity= form.city.value
		strTZip= form.zip.value

		testFname = strTFName.indexOf('"')

		if (testFname != -1)
		{
			alert("please remove double quotes from First Name")
			return false
		}
		

		testLName = strTLName.indexOf('"')

		if (testLName != -1)
		{
			alert("please remove double quotes from Last Name")
			return false
		}

		testAddress = strTAddress.indexOf('"')

		if (testAddress != -1)
		{
			alert("please remove double quotes from Address")
			return false
		}


		testApt = strTApt.indexOf('"')

		if  (testApt  != -1)
		{
			alert("please remove double quotes from Apartment")
			return false
		}


		testCity = strTCity.indexOf('"')

		if  (testCity  != -1)
		{
			alert("please remove double quotes from City")
			return false
		}

		testZip = strTZip.indexOf('"')

		if  (testZip  != -1)
		{
			alert("please remove double quotes from Zip")
			return false
		}






















// Validate Name
    if((ignoreChar(form.fname.value, " ") == "") || (form.fname.value == null)) {
  		alert("Please enter your first name.");
  		form.fname.value="";
		form.fname.focus();
        return false;
    }
    if((ignoreChar(form.lname.value, " ")== "") || (form.lname.value == null))  {
  		alert("Please enter your last name.");
  		form.lname.value="";
		form.lname.focus();
        return false;
    }
    
// Validate email

	if (!CheckEmail())
	{alert("Please, enter valid e-mail address"); return false;}  
	
// Valdate Eighteen	
	 
 // if (form.agecheck[1].selected==true) { 
//				alert("For this offer, you need to be 18 years of age or older.");
//				document.location.href="http://www.trojanCONDOMS.com";  //form.agecheck;
//				return false;
//		} 	 
 
			
 
    // Validate Gender	
   // if (!CheckEmptyText(form.gender))
	//{
		//alert("Please select gender.");
		//return false;
	//}
    
    //if (form.age[0].selected==true) { 
	//			alert("Please select year born.");
	//			form.age.focus();
	//			return false;
	//	} 			
		
	//if (form.gender[0].selected==true) { 
			//	alert("Please select gender.");
				//form.gender.focus();
				//return false;
		//} 	
		
		
 
   if((ignoreChar(form.address.value, " ") == "") || (form.address.value == null))  {
  		alert("Please enter address.");
  		form.address.value="";
		form.address.focus();
        return false;
    }

 
    	
		if((ignoreChar(form.city.value, " ") == "") || (form.city.value == null))  {
  		alert("Please enter city name.");
  		form.city.value="";
		form.city.focus();
        return false;
    }
	 if (form.state[0].selected==true) { 
				alert("Please select state.");
				form.state.focus();
				return false;
				}
	if((ignoreChar(form.zip.value, " ") == "") || (form.zip.value == null)) {
  		alert("Please enter zip code.");
  		form.zip.value="";
		form.zip.focus();
        return false;
    }
   
   if(!CheckZip(form.zip))
      {
      alert("Please enter proper zip.");
		form.zip.value="";
		form.zip.focus();
        return false;
      }
     	    
   
     
	

	return true;	
}	
//**************************************************



//******************************************************
function Checked(obj)
{
    var blOpt=false;
    var nav=navigator.userAgent.toUpperCase();
    //alert (nav);
    if (nav.indexOf("MAC")== -1) 
      {
		for (var i=0; i<obj.length; i++) 
			{ 
				if (obj[i].checked==true) 
					{ 
						blOpt=true;
						break; 
					} 
			} 
		}
	else
		{
			blOpt=true;
		}
		
	 if(blOpt==false)
	   {
		alert("Please check your answer.");
		return false;
       }
       
    return true;   
    
} 
    
    //*************************** 