//### Numeric Check #####

function ISnumeric(argNum)

{

 if(argNum=="")

 {

 	return false;

 }

 var valid = "0123456789-"

 var ok = "yes";

 var temp;

 for (var i=0; i<argNum.length; i++) 

	{

		temp = "" + argNum.substring(i, i+1);

		if (valid.indexOf(temp) == "-1")

		{ 

		

		 return false;

		  break; 

	    } 

	}

   return true;

}//end function 



//####### Email Syntex Check #######

function validateEmail(email)

{

	

	// This function is used to validate a given e-mail 

	// address for the proper syntax

	

	if (email == ""){

		return false;

	}

	badStuff = ";:/,' \"\\";

	for (i=0; i<badStuff.length; i++){

		badCheck = badStuff.charAt(i)

		if (email.indexOf(badCheck,0) != -1){

			return false;

		}

	}

	posOfAtSign = email.indexOf("@",1)

	if (posOfAtSign == -1){

		return false;

	}

	if (email.indexOf("@",posOfAtSign+1) != -1){

		return false;

	}

	posOfPeriod = email.indexOf(".", posOfAtSign)

	if (posOfPeriod == -1){

		return false;

	}

	if (posOfPeriod+2 > email.length){

		return false;

	}

	return true

}//end function



//### Clear Field #####

function clearField(frm)

{

   if(document.subscribe.email.value=="Enter Email Address")

   {

	document.subscribe.email.value="";

   }	

}





//### Email Check ###########

function emailCheck (emailStr)

{

	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	var emailPat=/^(.+)@(.+)$/;

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	var validChars="\[^\\s" + specialChars + "\]";

	var quotedUser="(\"[^\"]*\")";

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	var atom=validChars + '+';

	var word="(" + atom + "|" + quotedUser + ")";

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null)

	{

		return false;

	}

	var user=matchArray[1];

	var domain=matchArray[2];



	// Start by checking that only basic ASCII characters are in the strings (0-127).



	for (i=0; i<user.length; i++) 

	{

		if (user.charCodeAt(i)>127) 

		{

			//alert("Ths username contains invalid characters.");

			return false;

   		}

	}

	for (i=0; i<domain.length; i++) 

	{

		if (domain.charCodeAt(i)>127) 

		{

			//alert("Ths domain name contains invalid characters.");

			return false;

   		}

	}



	if (user.match(userPat)==null) 

	{

		return false;

	}

	

	var IPArray=domain.match(ipDomainPat);

	if (IPArray!=null) 

	{



		for (var i=1;i<=4;i++) 

		{

			if (IPArray[i]>255) 

			{

				return false;

   			}

		}

		return true;

	}

 

	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 (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 

	{

		return false;

	}



	// Make sure there's a host name preceding the domain.



	if (len<2) 

	{

		return false;

	}



// If we've gotten this far, everything's valid!

return true;

}//end function



//### Verify Action #####

function verify(msg)

{

	if(confirm(msg))

		return true;

	else

		return false;	

}//end function



//######### Pop Window ###########

function PopupPic(img_src)

{ 

  //window.open("large.php?imgsrc="+img_src,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,maximize=0,width='+width+',height='+height');

  window.open("large.php?imgsrc="+img_src,"mydoc","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,maximize=0");

}//end function 



function winBRopen(theURL,height,width) 

{ 

var winleft = (screen.width - 500) / 2;

var winUp = (screen.height - 500) / 4;





winProp = 'width='+width+',height='+height+',left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,toolbar=0,menubar=0';



Win = window.open(theURL,'', winProp)

	if (parseInt(navigator.appVersion) >= 4) 

		{

 		Win.window.focus(); 

 		}

}





//using in login.php

function checkfields(frm)

{

	frm.bfirstname.value = frm.sfirstname.value;

	frm.blastname.value = frm.slastname.value;

	frm.btitle.value = frm.stitle.value;

	frm.borganization.value = frm.sorganization.value;

	frm.baddress.value = frm.saddress.value;

	frm.baddress2.value = frm.saddress2.value;

	frm.bcity.value = frm.scity.value;

	frm.bstate.value = frm.sstate.value;

	frm.bzip.value = frm.szip.value;

	//frm.bcountry.value = frm.scountry.value;

	frm.bphone.value = frm.sphone.value;

	frm.bfax.value = frm.sfax.value;

	frm.bemail.value = frm.semail.value;

}//end function



//using in login.php

function chk_shipinfo_frm(frm)

{

 if(frm.sfirstname.value=='')

  {

    alert("Please specify the firstname!");

    frm.sfirstname.focus();

    return false;

  }

  if(frm.slastname.value=='')

  {

    alert("Please specify the lastname!");

    frm.slastname.focus();

    return false;

  }

  /*

  if(frm.stitle.value=='')

  {

    alert("Please specify the title!");

    frm.stitle.focus();

    return false;

  }

  

  if(frm.sorganization.value=='')

  {

    alert("Please specify the organization!");

    frm.sorganization.focus();

    return false;

  }

  */

  if(frm.saddress.value=='')

  {

    alert("Please specify the address!");

    frm.saddress.focus();

    return false;

  }

  /*if(frm.saddress2.value=='')

  {

    alert("Please specify the address2!");

    frm.saddress2.focus();

    return false;

  }*/

  if(frm.scity.value=='')

  {

    alert("Please specify the city!");

    frm.scity.focus();

    return false;

  }

  if(frm.sstate.value=='')

  {

    alert("Please specify the state!");

    frm.sstate.focus();

    return false;

  }

  if(frm.szip.value=='')

  {

    alert("Please specify the zip!");

    frm.szip.focus();

    return false;

  }

  /*

  if(frm.scountry.value=='')

  {

    alert("Please specify the country!");

    frm.scountry.focus();

    return false;

  }

  */

  if(frm.sphone.value=='')

  {

    alert("Please specify the phone!");

    frm.sphone.focus();

    return false;

  }

  if (!ISnumeric(frm.sphone.value))

   {

	alert("Please input a valid phone number.");

	frm.sphone.focus();

	return false;

   }

  if(frm.sfax.value!='')

  {

  	if (!ISnumeric(frm.sfax.value))

   	{

	alert("Please input a valid fax number.");

	frm.sfax.focus();

	return false;

   	}  

  }

  

  if(frm.semail.value=='')

  {

    alert("Please specify the email!");

    frm.semail.focus();

    return false;

  }

  if(!emailCheck(frm.semail.value))

  {

     alert("Email is in an invalid format - Please RE-Enter");

     frm.semail.focus();

     return false;

  }

  if(frm.password.value=='')

  {

    alert("Please specify the password!");

    frm.password.focus();

    return false;

  }

  

 frm.submit();

  

}//end function



//used in login.php

function chk_billinfo_frm(frm)

{

  

  if(frm.bfirstname.value=='')

  {

    alert("Please specify the firstname!");

    frm.bfirstname.focus();

    return false;

  }

  if(frm.blastname.value=='')

  {

    alert("Please specify the lastname!");

    frm.blastname.focus();

    return false;

  }

  /*

  if(frm.btitle.value=='')

  {

    alert("Please specify the title!");

    frm.btitle.focus();

    return false;

  }

  

  if(frm.borganization.value=='')

  {

    alert("Please specify the organization!");

    frm.borganization.focus();

    return false;

  }

  */

  if(frm.baddress.value=='')

  {

    alert("Please specify the address!");

    frm.baddress.focus();

    return false;

  }

  /*if(frm.baddress2.value=='')

  {

    alert("Please specify the address2!");

    frm.baddress2.focus();

    return false;

  }*/

  if(frm.bcity.value=='')

  {

    alert("Please specify the city!");

    frm.bcity.focus();

    return false;

  }

  if(frm.bstate.value=='')

  {

    alert("Please specify the state!");

    frm.bstate.focus();

    return false;

  }

  if(frm.bzip.value=='')

  {

    alert("Please specify the zip!");

    frm.bzip.focus();

    return false;

  }

  /*

  if(frm.bcountry.value=='')

  {

    alert("Please specify the country!");

    frm.bcountry.focus();

    return false;

  }

  */

  if(frm.bphone.value=='')

  {

    alert("Please specify the phone!");

    frm.bphone.focus();

    return false;

  }

  if (!ISnumeric(frm.bphone.value))

   {

	alert("Please input a valid phone number.");

	frm.bphone.focus();

	return false;

   }

   

  if(frm.bfax.value!='')

  {

    if (!ISnumeric(frm.bfax.value))

       {

	alert("Please input a valid fax number.");

	frm.bfax.focus();

	return false;

        }

  }      

  

  if(frm.bemail.value=='')

  {

    alert("Please specify the email!");

    frm.bemail.focus();

    return false;

  }

  if(!emailCheck(frm.bemail.value))

  {

     alert("Email is in an invalid format - Please RE-Enter");

     frm.bemail.focus();

     return false;

  }

  

  frm.submit();

}//end function	



//used in login.php

function chk_payment_frm(frm)

{

  

  theDate = new Date();

  cMonth=theDate.getMonth()

  cYear=theDate.getFullYear();

  

    

  if(frm.month.value=='')

  {

    alert("Please specify the month of card expiry!");

    frm.month.focus();

    return false;

  }

  if(frm.year.value=='')

  {

    alert("Please specify the year of expiry!");

    frm.year.focus();

    return false;

  }

  if(frm.month.value < cMonth)

  {

  	if (frm.year.value <= cYear)

	{

  		alert("your card validity date expired!");

    		frm.year.focus();

    		return false;

  	}	

  }	

  if(frm.cardno.value=='')

  {

    alert("Please specify the credit card number!");

    frm.cardno.focus();

    return false;

  }

  if(frm.security_code.value=='')

  {

    alert("Please specify the security code !");

    frm.security_code.focus();

    return false;

  }



  frm.submit();	

}//end function	



//used in cart.php

function chk_product(frm)
{
	var tColor = parseInt(document.getElementById('totalColors').value);
	if(tColor!=0)
	{
		for(var i=1;i<tColor+1;i++)
		{
			var sel = 'colorSelectBox'+i;
			var txtField = 'txtColor'+i;
			if(document.getElementById(sel).options[document.getElementById(sel).selectedIndex].value == '')
			{
				alert("You must select a " + document.getElementById(txtField).value + " first!");	
				document.getElementById(sel).focus();
				return false;		
			}			
		}
	}
	if ((frm.qty.value=="")||(frm.qty.value==0))
	{
		alert("Quanitity cant not be blank or zero!");	
		frm.qty.focus();
		return false;	
	}
	if (frm.qty.value!="")
	{
    	var chkmod;
		chkmod=frm.qty.value % frm.chkqty.value;
		if(chkmod!=0)
		{
	    	alert("Quanitity must be in multiple of "+ frm.chkqty.value +" !");	
			frm.qty.focus();
			return false;	
		}	
	}
	if (!ISnumeric(frm.qty.value))
   	{
		alert("Please input a valid number.");
		frm.qty.focus();
		return false;
   	}
	frm.submit();	   		
}//end function	



//used in common.inc.php

function chk_search(frm)

{

	if ((frm.searhtext.value==""))

	{

	    	alert("Enter some text for search!");	

		frm.searhtext.focus();

		return false;	

	}

	frm.submit();	

}//end function	



//used in login.php

function chk_login_frm(frm)

{

  if(frm.email.value=='')

  {

    alert("Please specify the email!");

    frm.email.focus();

    return false;

  }

  if(!emailCheck(frm.email.value))

  {

     alert("Email is in an invalid format - Please RE-Enter");

     frm.email.focus();

     return false;

  }

  if(frm.password.value=='')

  {

    alert("Please specify the password!");

    frm.password.focus();

    return false;

  }	

}//end function	



//used in login.php

function chk_forgot(frm)

{

  if(frm.email.value=='')

  {

    alert("Please specify the email!");

    frm.email.focus();

    return false;

  }

  if(!emailCheck(frm.email.value))

  {

     alert("Email is in an invalid format - Please RE-Enter");

     frm.email.focus();

     return false;

  }	

}//end function	





//uesd in compare.php

function chk_offer(frm)

{

  if(frm.modelno.value=='')

  {

    alert("Please specify manufacturer model no!");

    frm.modelno.focus();

    return false;

  }

  /*

  if(frm.color.value=='')

  {

    alert("Please select the color!");

    frm.color.focus();

    return false;

  }

  */

  if(frm.cprice.value=='')

  {

    alert("Please specify the price!");

    frm.cprice.focus();

    return false;

  }

  if(frm.cqty.value=='')

  {

    alert("Please specify the quantity!");

    frm.cqty.focus();

    return false;

  }

  if(frm.fname.value=='')

  {

    alert("Please specify the first name!");

    frm.fname.focus();

    return false;

  }

  if(frm.email.value=='')

  {

    alert("Please specify the email!");

    frm.email.focus();

    return false;

  }

  if(!emailCheck(frm.email.value))

  {

     alert("Email is in an invalid format - Please RE-Enter");

     frm.email.focus();

     return false;

  }

  if(frm.szip.value=='')

  {

    alert("Please specify the zip code!");

    frm.szip.focus();

    return false;

  }

}//end function	



//used in common.in.php

function chk_subscribe(frm)

{



  if((frm.email.value=='')||(frm.email.value=='Enter Email Address'))

  {

    alert("Please specify the email!");

    frm.email.focus();

    return false;

  }

  if(!emailCheck(frm.email.value))

  {

     alert("Email is in an invalid format - Please RE-Enter");

     frm.email.focus();

     return false;

  }

  frm.submit();	

}//end function	



//used in request_quote.php

function chk_request_quote(frm)

{

  if(frm.name.value=='')

  {

    alert("Please specify the name!");

    frm.name.focus();

    return false;

  }

  if((frm.email.value==''))

  {

    alert("Please specify the email!");

    frm.email.focus();

    return false;

  }

  if(!emailCheck(frm.email.value))

  {

     alert("Email is in an invalid format - Please RE-Enter");

     frm.email.focus();

     return false;

  }

  /*

  if(frm.company.value=='')

  {

    alert("Please specify the company name!");

    frm.company.focus();

    return false;

  }

  

  if(frm.address1.value=='')

  {

    alert("Please specify the address 1!");

    frm.address1.focus();

    return false;

  }

  if(frm.city.value=='')

  {

    alert("Please specify the city!");

    frm.city.focus();

    return false;

  }

  if(frm.state.value=='')

  {

    alert("Please specify the state!");

    frm.state.focus();

    return false;

  }

  if(frm.zip.value=='')

  {

    alert("Please specify the zip!");

    frm.zip.focus();

    return false;

  }

  */

  if(frm.phone.value=='')

  {

    alert("Please specify the phone!");

    frm.phone.focus();

    return false;

  }

  if(frm.manufacturer.value=='')

  {

    alert("Please specify the manufacturer part number(s)!");

    frm.manufacturer.focus();

    return false;

  }

  if(frm.quantity.value=='')

  {

    alert("Please specify the quantity!");

    frm.quantity.focus();

    return false;

  }

  if(frm.ship_zip.value=='')

  {

    alert("Please specify the ship to zip code!");

    frm.ship_zip.focus();

    return false;

  }	

}//end function	



//used in request_catalog.php

function chk_request_catalog(frm)

{

  if(frm.fname.value=='')

  {

    alert("Please specify the first name!");

    frm.fname.focus();

    return false;

  }

  if(frm.lname.value=='')

  {

    alert("Please specify the last name!");

    frm.lname.focus();

    return false;

  }

  /*

  if(frm.jobtitle.value=='')

  {

    alert("Please specify the job title!");

    frm.jobtitle.focus();

    return false;

  }

  

  if(frm.organizations.value=='')

  {

    alert("Please specify the organizations name!");

    frm.organizations.focus();

    return false;

  }

  */

  

  if(frm.address1.value=='')

  {

    alert("Please specify the address1!");

    frm.address1.focus();

    return false;

  }

  /*

  if(frm.address2.value=='')

  {

    alert("Please specify the address2!");

    frm.address2.focus();

    return false;

  }

  */

  if(frm.city.value=='')

  {

    alert("Please specify the city!");

    frm.city.focus();

    return false;

  }

  if(frm.state.value=='')

  {

    alert("Please specify the state!");

    frm.state.focus();

    return false;

  }

  if(frm.zip.value=='')

  {

    alert("Please specify the zip!");

    frm.zip.focus();

    return false;

  }

  /*

  if(frm.country.value=='')

  {

    alert("Please specify the country!");

    frm.country.focus();

    return false;

  }

  */

  if(frm.email.value=='')

  {

    alert("Please specify the email!");

    frm.email.focus();

    return false;

  }

}//end function  



//used in contact_us.php

function chk_contact_us(frm)

{

  if(frm.name.value=='')

  {

    alert("Please specify the name!");

    frm.name.focus();

    return false;

  }

  /*

  if(frm.organizations.value=='')

  {

    alert("Please specify the organizations name!");

    frm.organizations.focus();

    return false;

  }

  if(frm.address1.value=='')

  {

    alert("Please specify the Street Address!");

    frm.address1.focus();

    return false;

  }

  if(frm.city.value=='')

  {

    alert("Please specify the city!");

    frm.city.focus();

    return false;

  }

  if(frm.state.value=='')

  {

    alert("Please specify the state!");

    frm.state.focus();

    return false;

  }

  if(frm.zip.value=='')

  {

    alert("Please specify the zip!");

    frm.zip.focus();

    return false;

  }

  if(frm.phone.value=='')

  {

    alert("Please specify the phone!");

    frm.phone.focus();

    return false;

  }

  */

  if(frm.email.value=='')

  {

    alert("Please specify the email!");

    frm.email.focus();

    return false;

  }	

}//end function	

function chk_shipbillinfo_frm(frm)
{
 if(frm.elements['sfirstname'].value=='')
  {
    alert("Please specify the firstname for shipping address!");
    frm.elements['sfirstname'].focus();
    return false;
  }

  if(frm.slastname.value=='')
  {
    alert("Please specify the lastname for shipping address!");
    frm.slastname.focus();
    return false;
  }
  if(frm.saddress.value=='')
  {
    alert("Please specify the address for shipping address!");
    frm.saddress.focus();
    return false;
  }
  if(frm.scity.value=='')
  {
    alert("Please specify the city for shipping address!");
    frm.scity.focus();
    return false;
  }
  if(frm.sstate.value=='')
  {
    alert("Please specify the state for shipping address!");
    frm.sstate.focus();
    return false;
  }
  if(frm.szip.value=='')
  {
    alert("Please specify the zip for shipping address!");
    frm.szip.focus();
    return false;
  }

  if(frm.sphone.value=='')
  {
    alert("Please specify the phone for shipping address!");
    frm.sphone.focus();
    return false;
  }

  if (!ISnumeric(frm.sphone.value))
   {
	alert("Please input a valid phone number for shipping address.");
	frm.sphone.focus();
	return false;
   }

  if(frm.sfax.value!='')
  {
  	if (!ISnumeric(frm.sfax.value))
   	{
	alert("Please input a valid fax number for shipping address.");
	frm.sfax.focus();
	return false;
   	}  
  }
  if(frm.semail.value=='')
  {
    alert("Please specify the email for shipping address!");
    frm.semail.focus();
    return false;
  }
  if(!emailCheck(frm.semail.value))
  {
     alert("Email is in an invalid format for shipping address - Please RE-Enter");
     frm.semail.focus();
     return false;
  }

  	//////////////////////////////////billig form-//////////////////////////
	if(!frm.sameinfo.checked == true)
	{
	  if(frm.bfirstname.value=='')
	  {
		alert("Please specify the firstname for billing address!");
		frm.bfirstname.focus();
		return false;
	  }
	  if(frm.blastname.value=='')
	  {
		alert("Please specify the lastname for billing address!");
		frm.blastname.focus();
		return false;
	  }
	
	  if(frm.baddress.value=='')
	  {
		alert("Please specify the address for billing address!");
		frm.baddress.focus();
		return false;
	  }
	  if(frm.bcity.value=='')
	  {
		alert("Please specify the city for billing address!");
		frm.bcity.focus();
		return false;
	  }
	  if(frm.bstate.value=='')
	  {
		alert("Please specify the state for billing address!");
		frm.bstate.focus();
		return false;
	  }
	  if(frm.bzip.value=='')
	  {
		alert("Please specify the zip for billing address!");
		frm.bzip.focus();
		return false;
	  }
	
	  if(frm.bphone.value=='')
	  {
		alert("Please specify the phone for billing address!");
		frm.bphone.focus();
		return false;
	  }
	  if (!ISnumeric(frm.bphone.value))
	   {
		alert("Please input a valid phone number for billing address.");
		frm.bphone.focus();
		return false;
	   }
	  if(frm.bfax.value!='')
	  {
		if (!ISnumeric(frm.bfax.value))
	   {
		alert("Please input a valid fax number for billing address.");
		frm.bfax.focus();
		return false;
		}
	  }      
	  if(frm.bemail.value=='')
	  {
		alert("Please specify the email for billing address!");
		frm.bemail.focus();
		return false;
	  }
	  if(!emailCheck(frm.bemail.value))
	  {
		 alert("Email is in an invalid format for billing address - Please RE-Enter");
		 frm.bemail.focus();
		 return false;
	  }
	}
	return true;
}//end function	