//State selection box for mailForm - no matter division
function getStates(){
	lst=document.forms["mailForm"].custState;
	lst.options[0]=new Option("Alabama", "AL");
	lst.options[1]=new Option("Alaska", "AK");
	lst.options[2]=new Option("Arizona", "AZ");
	lst.options[3]=new Option("Arkansas", "AR");
	lst.options[4]=new Option("California", "CA");
	lst.options[5]=new Option("Colorado", "CO");
	lst.options[6]=new Option("Connecticut", "CT");
	lst.options[7]=new Option("Deleware", "DE");
	lst.options[8]=new Option("District of Columbia", "DC");
	lst.options[9]=new Option("Florida", "FL");
	lst.options[10]=new Option("Georgia", "GA");
	lst.options[11]=new Option("Hawaii", "HI");
	lst.options[12]=new Option("Idaho", "ID");
	lst.options[13]=new Option("Illinois", "IL");
	lst.options[14]=new Option("Indiana", "IN");
	lst.options[15]=new Option("Iowa", "IA");
	lst.options[16]=new Option("Kansas", "KS");
	lst.options[17]=new Option("Kentucky", "KY");
	lst.options[18]=new Option("Louisiana", "LA");
	lst.options[19]=new Option("Maine", "ME");
	lst.options[20]=new Option("Maryland", "MD");
	lst.options[21]=new Option("Massechusetts", "MA");
	lst.options[22]=new Option("Michigan", "MI");
	lst.options[23]=new Option("Minnesota", "MN");
	lst.options[24]=new Option("Mississippi", "MS");
	lst.options[25]=new Option("Missouri", "MO");
	lst.options[26]=new Option("Montana", "MT");
	lst.options[27]=new Option("Nebraska", "NE");
	lst.options[28]=new Option("Nevada", "NV");
	lst.options[29]=new Option("New Hampshire", "NH");
	lst.options[30]=new Option("New Jersey", "NJ");
	lst.options[31]=new Option("New Mexico", "NM");
	lst.options[32]=new Option("New York", "NY");
	lst.options[33]=new Option("North Carolina", "NC");
	lst.options[34]=new Option("North Dakota", "ND");
	lst.options[35]=new Option("Ohio", "OH");
	lst.options[36]=new Option("Oklahoma", "OK");
	lst.options[37]=new Option("Oregon", "OR");
	lst.options[38]=new Option("Pennsylvania", "PA");
	lst.options[39]=new Option("Rhode Island", "RI");
	lst.options[40]=new Option("South Carolina", "SC");
	lst.options[41]=new Option("South Dakota", "SD");
	lst.options[42]=new Option("Tennessee", "TN");
	lst.options[43]=new Option("Texas", "TX");
	lst.options[44]=new Option("Utah", "UT");
	lst.options[45]=new Option("Vermont", "VT");
	lst.options[46]=new Option("Virginia", "VA");
	lst.options[47]=new Option("Washington", "WA");
	lst.options[48]=new Option("West Virginia", "WV");
	lst.options[49]=new Option("Wisconsin", "WI");
	lst.options[50]=new Option("Wyoming", "WY");
	lst.options[15].selected=true;
}
//Check for valid email
function emailCheck (emailStr) {
	/* 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 pattern applies if the "user" is a quoted string (in which case, there are no rules 
	about which characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses, rather than symbolic names.  
	E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username. For example, in 
	john.doe@somewhere.com, john and doe are words.  Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	/* Finally, let's start trying to figure out if the supplied address is
	valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	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. */
		var msg="Email address seems incorrect (check @ and .'s)";
		return msg;
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		alert("The username doesn't seem to be valid.")
		document.mailForm.custEmail.focus()
		return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!")
				document.mailForm.custEmail.focus()
				return false
		    }
	    }
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.")
		document.mailForm.custEmail.focus()
		return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	three-letter word (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
		// the address must end in a two letter or three letter word.
		alert("The address must end in a three-letter domain, or two letter country.")
		document.mailForm.custEmail.focus()
		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
		var errStr="This address is missing a hostname!"
		alert(errStr)
		document.mailForm.custEmail.focus()
		return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}
//Validate form entries
function validate(){
	var pass=0;
	for(var a=1; a<document.forms['advancedSearch'].elements.length; a++){
		if(document.forms['advancedSearch'].elements[a].checked==true){
			pass=1;
			break;
		}
	}
	if (pass==0){
		alert("Please make a selection before continuing.");
		return false;
	}
	else {
		document.forms['advancedSearch'].submit();
	}
}
function validateRequest(){
	var err=0;
	//put something in here for the image validation
	for (var a=0;a<document.images.length;a++){
		if (document.images[a].name=='validator'){
			if (document.images[a].id!=document.forms['requestInformation'].code.value){
				alert("Invalid Access Code!  Try again.");
				document.forms['requestInformation'].code.focus();
				return false;
			}
		}
	}
	//contact name
	if (document.forms["requestInformation"].contact.value==""){
		document.getElementById("contact").style.color="#ff0000";
		err=1;
	}
	//email address
	if (document.forms["requestInformation"].email.value==""){
		document.getElementById("email").style.color="#ff0000";
		err=1;
	}
	else{
		msg=emailCheck(document.forms["requestInformation"].email.value);
		if (msg!=true){
			document.getElementById("email").style.color="#ff0000";
			document.forms["requestInformation"].email.focus();
			alert(msg);
			return false;
		}
	}
	
	if (err==0){
		return true;	
	}
	else {
		alert ("Missing Information");
		return false;
		
	}
}
function validateQuote(){
	var err=0;
	//put something in here for the image validation
	for (var a=0;a<document.images.length;a++){
		if (document.images[a].name=='validator'){
			if (document.images[a].id!=document.forms['quoteform'].code.value){
				alert("Invalid Access Code!  Try again.");
				document.forms['quoteform'].code.focus();
				return false;
			}
		}
	}
	//product
	if (document.forms["quoteform"].labelId.value=="" || document.forms["quoteform"].labelId.value=="Please select a product"){
		document.getElementById("labelId").style.color="#ff0000";
		err=1;
	}
	else {
		alert("why is this not black?");
		document.getElementById("labelId").style.color="#000000";
	}
	//intended use
	if (document.forms["quoteform"].intendedUse.value=="" || document.forms["quoteform"].intendedUse.value=="Select One"){
		document.getElementById("intendedUse").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("intendedUse").style.color="#000000";
	}
	//temperature
	if (document.forms["quoteform"].temperature.value==""){
		document.getElementById("temperature").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("temperature").style.color="#000000";
	}
	//condition
	if (document.forms["quoteform"].environmentalCondition.value==""){
		document.getElementById("environmentalCondition").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("environmentalCondition").style.color="#000000";
	}
	//size
	if (document.forms["quoteform"].size.value=="" || document.forms["quoteform"].size.value=="Select One"){
		document.getElementById("size").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("size").style.color="#000000";
	}
	//other size
	if (document.forms["quoteform"].size.value=="Other" && document.forms["quoteform"].sizeOther.value==""){
		document.getElementById("sizeOther").style.color="#ff0000";
		err=2;
	}
	else {
		document.getElementById("sizeOther").style.color="#000000";
	}
	//corners
	if (document.forms["quoteform"].corners.value=="" || document.forms["quoteform"].corners.value=="Select One"){
		document.getElementById("corners").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("corners").style.color="#000000";
	}
	//adhesive
	if (document.forms["quoteform"].adhesive.value=="" || document.forms["quoteform"].adhesive.value=="Select One"){
		document.getElementById("adhesive").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("adhesive").style.color="#000000";
	}
	//number of holes
	if (document.forms["quoteform"].num_holes.value=="" || document.forms["quoteform"].num_holes.value=="Select One"){
		document.getElementById("num_holes").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("num_holes").style.color="#000000";
	}
	//hole size
	if (document.forms["quoteform"].hole_size.value=="" || document.forms["quoteform"].hole_size.value=="Select One"){
		document.getElementById("hole_size").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("hole_size").style.color="#000000";
	}
	//bg color
	if (document.forms["quoteform"].background_color.value=="" || document.forms["quoteform"].background_color.value=="Select One"){
		document.getElementById("colors").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("colors").style.color="#000000";
	}
	//copy color
	if (document.forms["quoteform"].copy_color.value=="" || document.forms["quoteform"].copy_color.value=="Select One"){
		document.getElementById("colors").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("colors").style.color="#000000";
	}
	//serial number
	if (document.forms["quoteform"].serial_number.value=="" || document.forms["quoteform"].serial_number.value=="Select One"){
		document.getElementById("serial_number").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("serial_number").style.color="#000000";
	}
	//barcode
	if (document.forms["quoteform"].barcode.value=="" || document.forms["quoteform"].barcode.value=="Select One"){
		document.getElementById("barcode").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("barcode").style.color="#000000";
	}
	//quantity
	if (document.forms["quoteform"].quantity.value=="" || document.forms["quoteform"].quantity.value=="Select One"){
		document.getElementById("quantity").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("quantity").style.color="#000000";
	}
	//logo attachment
	/*if (document.forms["quoteform"].logo.value=="Yes" && document.forms["quoteform"].attachFile[0].value==""){
		document.getElementById("logo").style.color="#ff0000";
		err=3;
	}*/
	//contact name
	if (document.forms["quoteform"].contact.value==""){
		document.getElementById("contact").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("contact").style.color="#000000";
	}
	//address
	if (document.forms["quoteform"].address1.value==""){
		document.getElementById("address").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("address").style.color="#000000";
	}
	//city
	if (document.forms["quoteform"].city.value==""){
		document.getElementById("city").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("city").style.color="#000000";
	}
	//state
	if (document.forms["quoteform"].state.value==""){
		document.getElementById("state").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("state").style.color="#000000";
	}
	//zip
	if (document.forms["quoteform"].zipcode.value==""){
		document.getElementById("zip").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("zip").style.color="#000000";
	}
	//phone
	if (document.forms["quoteform"].phone.value==""){
		document.getElementById("phone").style.color="#ff0000";
		err=1;
	}
	else {
		document.getElementById("state").style.color="#000000";
	}
	//email address
	if (document.forms["quoteform"].email.value==""){
		document.getElementById("email").style.color="#ff0000";
		err=1;
	}
	else{
		msg=emailCheck(document.forms["quoteform"].email.value);
		if (msg!=true){
			document.getElementById("email").style.color="#ff0000";
			document.forms["quoteform"].email.focus();
			alert(msg);
			return false;
		}
		else {
			document.getElementById("email").style.color="#000000";
		}
	}
	
	if (err==0){
		return true;	
	}
	else {
		if (err==2){
			alert("You have selected Other for size but have not specified the size needed");
			return false;
		}
		else {
			alert ("Missing Information");
			return false;
		}		
	}
}
function addCount(isChecked){
	var c=parseInt(document.forms['labelInfoForm'].selCount.value);
	if(isChecked==true){
		if (c==5){
			alert('You can only have up to 5 items checked.');
			return false;
		}
		else {
			c++;
			document.forms['labelInfoForm'].selCount.value=c;
		}
	}
	else {
		c--;
		document.forms['labelInfoForm'].selCount.value=c;
	}
}
function ValidateItemSelection2(form,type){
	var oForm = document.forms['labelInfoForm'];
	var nCount = oForm.selCount.value;

	if (type=='compare'){
		if (nCount > 1 && nCount <= 5){	
		    oForm.action='compare_labels.php';
		    oForm.submit();
			return true;
		}
		else {
			alert('Please select between 2 and 5 items.');
			return false;		
		}
	}
	else if (type=='quote'){
		//if (nCount > 0 && nCount <= 5){	
		    oForm.action='quote.php';
		    oForm.submit();
			return true;
		//}
		//else {
			//alert('Please select between 1 and 5 items.');
			//return false;		
		//}
	}
	else if (type=='request'){
		if (nCount >= 1 && nCount <= 5)	{	
		    
		    oForm.submit();
			return true;
		}
		else {
		 alert('Please select between 1 and 5 items.');
		 return false;		
		}
	}
}
function getSpecs(labelId){
	var lblIdNum=labelId.substr(0, labelId.indexOf(':'));
	jsrsExecute('select_rs.php', putInfo, 'getLabelSpecs', lblIdNum);
}
function putInfo(stuff){
	var lst=Array();
	var specs=Array();
	var szlst=Array();	//sizes
	var ctlst=Array();	//corners
	var adlst=Array();	//adhesive
	var nhlst=Array();	//num holes
	var hslst=Array();	//hole size
	var bglst=Array();	//bg color
	var cclst=Array();	//copy color
	var snlst=Array();	//serial num
	var bclst=Array();	//barcode
	stuff=stuff.substring(0,(stuff.length-1));
	var lbl_specs=stuff.split('~');
	//label sizes
	szlst=lbl_specs[0].split('|');
	var sizes=document.forms["quoteform"].size;
	sizes.options.length=0;	
	sizes.options[0]=new Option('Select One', '');
	for(var a=0;a<szlst.length;a++){
		sizes.options[a+1]=new Option(szlst[a], szlst[a]);
	}
	var b=sizes.options.length;
	sizes.options[b]=new Option('Other', 'Other');
	//corners
	ctlst=lbl_specs[1].split('|');
	var corners=document.forms["quoteform"].corners;
	corners.options.length=0;			
	corners.options[0]=new Option('Select One', '');
	for(var a=0;a<ctlst.length;a++){	
		if(ctlst[0]=="NA"){
			corners.options[0]=new Option('Not Applicable', ctlst[a]);
		}
		else {
			corners.options[a+1]=new Option(ctlst[a], ctlst[a]);
		}
	}
	//adhesive
	adlst=lbl_specs[2].split('|');
	var adh=document.forms["quoteform"].adhesive;
	adh.options.length=0;
	adh.options[0]=new Option('Select One', '');
	for(var a=0;a<adlst.length;a++){		
		if(adlst[0]=="NA"){
			adh.options[0]=new Option('Not Applicable', adlst[a]);
		}
		else {
			adh.options[a+1]=new Option(adlst[a], adlst[a]);
		}
	}
	//number of holes
	nhlst=lbl_specs[3].split('|');
	var numh=document.forms["quoteform"].num_holes;
	numh.options.length=0;	
	numh.options[0]=new Option('Select One', '');
	for(var a=0;a<nhlst.length;a++){		
		if(nhlst[0]=="NA"){
			numh.options[0]=new Option('Not Applicable', nhlst[a]);
		}
		else {
			numh.options[a+1]=new Option(nhlst[a], nhlst[a]);
		}
	}
	//hole sizes
	hslst=lbl_specs[4].split('|');
	var hsz=document.forms["quoteform"].hole_size;
	hsz.options.length=0;	
	hsz.options[0]=new Option('Select One', '');
	for(var a=0;a<hslst.length;a++){		
		if(hslst[0]=="NA"){
			hsz.options[0]=new Option('Not Applicable', hslst[a]);
		}
		else {
			hsz.options[a+1]=new Option(hslst[a], hslst[a]);
		}
	}
	//background color
	bglst=lbl_specs[5].split('|');
	var bclr=document.forms["quoteform"].background_color;
	bclr.options.length=0;	
	bclr.options[0]=new Option('Select One', '');
	for(var a=0;a<bglst.length;a++){		
		bclr.options[a+1]=new Option(bglst[a], bglst[a]);
	}
	//copy color
	cclst=lbl_specs[6].split('|');
	var cclr=document.forms["quoteform"].copy_color;
	cclr.options.length=0;			
	cclr.options[0]=new Option('Select One', '');
	for(var a=0;a<cclst.length;a++){
		cclr.options[a+1]=new Option(cclst[a], cclst[a]);
	}
	if(lbl_specs[7]=='n'){
		document.forms["quoteform"].logo[1].disabled=true;
	}
	//serial number
	snlst=lbl_specs[8].split('|');
	var sern=document.forms["quoteform"].serial_number;
	sern.options.length=0;		
	sern.options[0]=new Option('Select One', '');
	for(var a=0;a<snlst.length;a++){
		if(snlst[0]=="NA"){
			sern.options[0]=new Option('Not Applicable', snlst[a]);
		}
		else {
			sern.options[a+1]=new Option(snlst[a], snlst[a]);
		}
	}
	//barcode
	bclst=lbl_specs[9].split('|');
	var barc=document.forms["quoteform"].barcode;
	barc.options.length=0;			
	barc.options[0]=new Option('Select One', '');
	for(var a=0;a<bclst.length;a++){
		if(bclst[0]=="NA"){
			barc.options[0]=new Option('Not Applicable', bclst[a]);
		}
		else {
			barc.options[a+1]=new Option(bclst[a], bclst[a]);
		}
	}
}
function holeDisable(){
	var numh=document.forms["quoteform"].num_holes;
	var hsz=document.forms["quoteform"].hole_size;
	if (document.forms['quoteform'].adhesive.value=='Pressure Sensitive'){
		numh.options.length=0;	
		hsz.options.length=0;	
		numh.options[0]=new Option('Not Applicable', 'NA');
		hsz.options[0]=new Option('Not Applicable', 'NA');
		numh.disabled=true;		
		hsz.disabled=true;
	}
	else {
		numh.disabled=false; 
		hsz.disabled=false;
	}
}
