
function valkitform(f)
{
var name = f.name.value;
var company=f.company.value;
var email=f.email.value;
var phone=f.phone.value;
var mail=f.mailing.value;
var city=f.citystatezip.value;
var random=f.random.value;


if(email == "")
{
alert('Please Enter Email ID');
return false;
}

if(random=="")
{
alert("Please Enter Verification Code");
return false;
}


if (document.kit.checkbox.checked == false &&
document.kit.checkbox2.checked == false &&
document.kit.checkbox3.checked == false)
{
alert ('You didn\'t choose any of the checkboxes!');
return false;
}



if(email!="")
	{
		var re=EmailVal(email);
		if(re==false)
		{
			alert("Please Enter valid Mail ID");
			f.email.focus();
			return re;
		}
	}



else
{
return true;
}

}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function searchfrmVal()
{
	
var search=document.form1.textfield.value;

	
	if(search=="")
	{
		alert("Please Enter Search Key");return false;
	}
	else
	{
		document.form1.action="../darcoid_search.php";
	}
}
function pdfsub(data)
{
	f=document.pdfdown;
	//alert(f);
	//alert(data);
	f.file.value=data;
	f.action="../pdfdownload.php";
	f.submit();
}

function rfqformsub(frmname)
{
//f=document.frmname;
	document.forms[frmname].action="rfq-form.php";
	document.forms[frmname].submit();
}

/*
	Parameter : string postcode 
    RETURN: Boolean value TRUE/FALSE
*/
function postcodeVal(zip)
{
	var zipChk=true;
	if(zip.length!=5 || zip==0)
	{
		zipChk=false;
	}
	else
	{
		var rz1=chkNumericAndChars(zip,"0123456789");
		if(rz1==false)
		{
			zipChk==false;
		}
		/*var rz1=chkNumericAndChars(zip,"abcdefghijklmnopqrstuvwxyz -*. ABCDEFGHIJKLMNOPQRSTUVWXYZ");
		var rz=chkNumericAndChars(zip,"0123456789.-*abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ");  
		if(rz1==true)
		{
			zipChk=false;
		}
		else if(rz==false)
		{
			zipChk=false;
		}
		else
		{
		}*/
	}
	return zipChk;
}

 //---Email validation function------------------------------------------
function EmailVal (emailStr) 
{
	var strValidChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var strValidUserChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890._&";
	var strValidDomainChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.@";
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) 
	{

		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */

		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic {0-9)(a-z)(A-Z)
	var strChar=user.charAt(0);
	if(strValidChars.indexOf(strChar) == -1)
	{
		return false;
	}
	if(chkNumericAndChars(user,strValidUserChars)==false)
	{
		return false;
	}

	if(chkNumericAndChars(domain,strValidDomainChars)==false)
	{
		return false;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1)
		{
			return false;
		}
		if(isNaN(domArr[i])==false)
		{
			return false;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2)
	{
		//alert("This address is missing a hostname!");
		return false;
	}

	// If we've gotten this far, everything's valid!
		return true;
}
//-----------------------------------------------------------------------


 //--------Validation for Numerics enter and some special chars---------------------------
 function chkNumericAndChars(numb,allowChars)
 {
	var strValidChars =allowChars;
	var strChar;
	var blnres=true;
	var flag=0;
	for(i=0;i<numb.length;i++)
	{
	  strChar = numb.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
	  {
		blnres=false;	  
		break;
	  }
	}

	return blnres;
  }
 //-------------------------------------------------------------

 //Common Validation for firstname,surname,town,region and country
 function nameValidator(name)
 {
	 var strAlphaNumerics="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 	 var strAllowbleChars="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@$#&";
	 var boolFN1=chkNumericAndChars(name,strAllowbleChars);
	 var strName1=name.charAt(0);
	 if(strAlphaNumerics.indexOf(strName1)==-1 || boolFN1==false)
	 {
	 	return false;
	 }
 }


 //-----------FUnction to trim the values passed --------------------------------------------------
 /*
	parameter string
	return:string with left and right trim.

 */
function Trim(sString)
{
	return leftTrim(rightTrim(sString));
}
 /*
	parameter: string
	return:string with left trim.

 */
function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}
/*
	parameter: string
	return:string with right trim.

 */
function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
//---------------------------------------------------------------------------------------------------

function valRFQform(f)
{
var Phone=Trim(f.BillingPhone.value);
var Fax=Trim(f.Fax.value);
//var Phone=Trim(f.p1.value)+Trim(f.p2.value)+Trim(f.p3.value);
var Ext = Trim(f.p4.value);
//var Fax = Trim(f.f1.value)+Trim(f.f2.value)+Trim(f.f3.value);	
	//var Company=Trim(f.Company.value);
var Email=Trim(f.Email.value);
	//var EmailConfirm=Trim(f.EmailConfirm.value);
	//var FirstName=Trim(f.BillingFirstName.value);
	//var LastName=Trim(f.BillingLastName.value);
	//var Address=Trim(f.BillingAddress.value);
	//var City=Trim(f.BillingCity.value);
	//var State=f.BillingState.value;
	//var HowDidYouHear=f.HowDidYouHear.value;
	//var Zip=Trim(f.BillingZip.value);
	//var Comments=Trim(f.Comments.value);

	/*if(Company=="")
	{

		alert("Please Enter Company");
		f.Company.focus();
		return false
	}
	if(Email=="")
	{
	  //alert("hai");
	  alert("Please Enter Email Id");
	  f.Email.focus();
	  return false;
	}
	
	if(EmailConfirm=="")
	{
	  //alert("hai");
	  alert("Please Enter Confirm Email");
	  f.EmailConfirm.focus();
	  return false;
	}
	if(FirstName=="")
	{
		alert("Please Enter First Name");
		f.BillingFirstName.focus();
		return false;
	}	
	if(LastName=="")
	{
		alert("Please Enter Last Name");
		f.BillingLastName.focus();
		return false;
	}
	if(Address=="")
	{
		alert("Please Enter Address");
		f.BillingAddress.focus();
		return false;
	}	
	if(City=="")
	{
		alert("Please Enter City");
		f.BillingCity.focus();
		return false;
	}	

	if(State=="" || State==0)
	{
		alert("Please Select State");
		f.BillingState.focus();
		return false;
	}

if( HowDidYouHear=="" ||  HowDidYouHear==0)
	{
		alert("Please Select HowDidYouHear");
		f. HowDidYouHear.focus();
		return false;
	}




	if(Zip=="")
	{
		alert("Please Enter Zip/PostCode");
		f.BillingZip.focus();
		return false;
	}*/
	if(Phone=="")
	{
		alert("Please Enter Phone");
		f.BillingPhone.focus();
		return false;
	}
	if(Email!="")
	{
		var re=EmailVal(Email);
		if(re==false)
		{
			alert("Please Enter valid Mail ID");
			f.Email.focus();
			return re;
		}
	}
	/*
	
	if(Company!="")
	{
		var companyName1=Company;
		var boolFNchk=nameValidator(companyName1);
		if(boolFNchk==false)
		{
			alert("Enter Valid Company");
			f.Company.focus();
			return false;
		}
	}
	
	
	
	
	
	
	if(Email!=EmailConfirm)
	{
		alert("Email Entries Are Not Matched");
		f.EmailConfirm.focus();
		return false;
	}
	if(FirstName!="")
	{
		var firstName1=FirstName;
		var boolFNchk=nameValidator(firstName1);
		if(boolFNchk==false)
		{
			alert("Enter Valid Firstname");
			f.BillingFirstName.focus();
			return false;
		}
	}
	if(LastName!="")
	{
		var lastName1=LastName;
		var boolLNchk=nameValidator(lastName1);
		if(boolLNchk==false)
		{
			alert("Enter Valid Lastname");
			f.BillingLastName.focus();
			return false;
		}
	}
	if(City!="")
	{
		var town1=City;
		var boolFNchk=nameValidator(town1);
		if(boolFNchk==false)
		{
			alert("Enter Valid City");
			f.BillingCity.focus()
			return false;
		}
	}
	if(Zip!="")		
	{
		var zipChk1=postcodeVal(Zip);
		if(zipChk1==false)
		{
			alert("Enter Valid Zip/Postcode");
			f.BillingZip.focus();
			return false;
		}
	}*/
	if(Phone!="")
	{


		var rp=chkNumericAndChars(Phone,"0123456789()-+./")

		if(rp==false || Phone.length<10 || Phone.length>27 || Phone==0)
		{
			alert("Enter Valid Phone No");
			f.BillingPhone.focus();
			return false;
 		}
		if(Ext != '')
		{
			var rf = chkNumericAndChars(Ext,"0123456789")	
			if(rp==false || Ext.length < 3  || Ext==0)
			{
				alert("Enter Valid Ext");
				f.p4.focus();
				return false;
	 		}
	
		}
	}
	
	if(Fax!="")
	{
		var rp=chkNumericAndChars(Fax,"0123456789()-+./")
		if(rp==false || Fax.length<10 || Fax.length>27 || Fax==0)
		{
			alert("Enter Valid Fax");
			f.Fax.focus();
			return false;
 		}
	}
	//alert(f.HowDidYouHear[0].checked);
	/*if(f.HowDidYouHear[0].checked==false && f.HowDidYouHear[1].checked==false && f.HowDidYouHear[2].checked==false && f.HowDidYouHear[3].checked==false && f.HowDidYouHear[4].checked==false && f.HowDidYouHear[5].checked==false && f.HowDidYouHear[6].checked==false)
	{
		alert("Please Select How did you hear about us");
		return false;
	}*/

	else

	return true;
}
function phonenumberonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	var valid_code = new Array(7);
	valid_code[0] ="test"+40;
	valid_code[1] ="test"+41;
	valid_code[2] ="test"+43;
	valid_code[3] ="test"+45;	
	valid_code[4] ="test"+47;
	valid_code[5] ="test"+88;
	valid_code[6] ="test"+120;
	var arr2str = valid_code.toString();  //Converting the String content to String 
	if (unicode!=8)
	{			
		if ((unicode < 48 || unicode >57) &&  (unicode != 9) &&   (unicode != 13) )
		{	
			test1 = "test"+unicode;
			if(arr2str.search(test1) >= 0 )
			{
				return true;	
			}
			return false;

		}
	}
	else
	{
		return true;
	}
	
}
