debug = false;

aboutusnormOK = false;
aboutusoverOK = false;
homenormOK = false;
homeoverOK = false;
cataloguenormOK = false;
catalogueoverOK = false;
shippingnormOK = false;
shippingoverOK = false;
usernormOK = false;
useroverOK = false;
featureditemsnormOK = false;
featureditemsoverOK = false;
contactnormOK = false;
contactoverOK = false;
shoppingcartnormOK = false;
shoppingcartoverOK = false;

hockeySmallNormOK = false;
hockeySmallOverOK = false;
baseballSmallNormOK = false;
baseballSmallOverOK = false;
footballSmallNormOK = false;
footballSmallOverOK = false;
miscellaneousSmallNormOK = false;
miscellaneousSmallOverOK = false;

baseballLargeNormOK = false;
baseballLargeOverOK = false;
footballLargeNormOK = false;
footballLargeOverOK = false;
hockeyLargeNormOK = false;
hockeyLargeOverOK = false;
miscellaneousLargeNormOK = false;
miscellaneousLargeOverOK = false;

baseballplayerNormOK = false;
baseballplayerBatOK = false;
baseballplayerMitOK = false;
baseballplayerHatOK = false;
baseballplayerJerseyOK = false;
baseballplayerBallOK = false;

basketballplayerNormOK = false;
basketballplayerBallOK = false;
basketballplayerJerseyOK = false;

footballplayerNormOK = false;
footballplayerHelmetOK = false;
footballplayerJerseyOK = false;

hockeyplayerJerseyOK = false;
hockeyplayerGloveOK = false;
hockeyplayerHelmetOK = false;
hockeyplayerKneepadOK = false;
hockeyplayerStickOK = false;
hockeyplayerNormOK = false;

squareOverOK = false;
squareNormOK = false;

var squareNorm = new Image(105,100);
squareNorm.src = "graphics/squarenorm.gif";
squareNorm.onLoad=imgLoaded('squareNorm');

var squareOver = new Image(105,100);
squareOver.src = "graphics/squareover.gif";
squareOver.onLoad=imgLoaded('squareOver');

//First build the array of states.
arrCountry = new Array();
arrCountry[0] = "Canada";
arrCountry[1] = "United States";

//Build the array of provinces
arrSub0 = new Array();
arrSub0[0] = "Alberta";
arrSub0[1] = "BritishColumbia";
arrSub0[2] = "Manitoba";
arrSub0[3] = "Newfoundland";
arrSub0[4] = "NewBrunswick";
arrSub0[5] = "NorthwestTerritories";
arrSub0[6] = "NovaScotia";
arrSub0[7] = "Nunavut";
arrSub0[8] = "Ontario";
arrSub0[9] = "PrinceEdwardIsland";
arrSub0[10] = "Saskatchewan";
arrSub0[11] = "Quebec";
arrSub0[12] = "YukonTerritory";

arrGst = new Array();
arrGst[0] = .07;
arrGst[1] = .08;
arrGst[2] = .08;
arrGst[3] = .08;
arrGst[4] = .08;
arrGst[5] = .08;
arrGst[6] = 0;
arrGst[7] = .08;
arrGst[8] = .07;
arrGst[9] = .08;
arrGst[10] = .08;
arrGst[11] = .08;
arrGst[12] = .08;
arrGst[13] = .08;

arrPst = new Array();
arrPst[0] = .10;
arrPst[1] = .10;
arrPst[2] = .10;
arrPst[3] = .10;
arrPst[4] = .10;
arrPst[5] = .10;
arrPst[6] = 0;
arrPst[7] = .10;
arrPst[8] = .10;
arrPst[9] = .10;
arrPst[10] = .10;
arrPst[11] = .10;
arrPst[12] = .10;
arrPst[13] = .10;

arrHst = new Array();
arrHst[0] = 0;
arrHst[1] = 0;
arrHst[2] = 0;
arrHst[3] = 0;
arrHst[4] = 0;
arrHst[5] = 0;
arrHst[6] = .15;
arrHst[7] = 0;
arrHst[8] = 0;
arrHst[9] = 0;
arrHst[10] = 0;
arrHst[11] = 0;
arrHst[12] = 0;
arrHst[13] = 0;

//Build the array of states.
arrSub1 = new Array();
arrSub1[0] = "Alabama";
arrSub1[1] = "Alaska";
arrSub1[2] = "Arizona";
arrSub1[3] = "Arkansas";
arrSub1[4] = "California";
arrSub1[5] = "Colorado";
arrSub1[6] = "Connecticut";
arrSub1[7] = "Delaware";
arrSub1[8] = "Florida";
arrSub1[9] = "Georgia";
arrSub1[10] = "Hawaii";
arrSub1[11] = "Idaho";
arrSub1[12] = "Illinois";
arrSub1[13] = "Indiana";
arrSub1[14] = "Iowa";
arrSub1[15] = "Kansas";
arrSub1[16] = "Kentucky";
arrSub1[17] = "Louisiana";
arrSub1[18] = "Maine";
arrSub1[19] = "Maryland";
arrSub1[20] = "Massachusetts";
arrSub1[21] = "Michigan";
arrSub1[22] = "Minnesota";
arrSub1[23] = "Mississippi";
arrSub1[24] = "Missouri";
arrSub1[25] = "Montana";
arrSub1[26] = "Nebraska";
arrSub1[27] = "Nevada";
arrSub1[28] = "NewHampshire";
arrSub1[29] = "NewJersey";
arrSub1[30] = "NewMexico";
arrSub1[31] = "NewYork";
arrSub1[32] = "NorthCarolina";
arrSub1[33] = "NorthDakota";
arrSub1[34] = "Ohio";
arrSub1[35] = "Oklahoma";
arrSub1[36] = "Oregon";
arrSub1[37] = "Pennsylvania";
arrSub1[38] = "RhodeIsland";
arrSub1[39] = "SouthCarolina";
arrSub1[40] = "SouthDakota";
arrSub1[41] = "Tennessee";
arrSub1[42] = "Texas";
arrSub1[43] = "Utah";
arrSub1[44] = "Vermont";
arrSub1[45] = "Virginia";
arrSub1[46] = "Washington";
arrSub1[47] = "WashingtonDC";
arrSub1[48] = "WestVirginia";
arrSub1[49] = "Wisconsin";
arrSub1[50] = "Wyoming";


function imgLoaded(whtImg){
	//alert(eval(whtImg+'OK'))
	eval(whtImg+'OK = true');
	//alert(eval(whtImg+'OK'))
}

function swapImg(whatImg,chgTo){
	if(eval(chgTo+'OK')){
		eval("document."+whatImg+".src = "+chgTo+".src");
	}
}

function jumpHistory(howMuch){
	window.history.go(howMuch);
}

function addToCart(whtForm,whtField,itemID){
	eval("fldVal = document."+whtForm+".qty"+whtField+".value");
	eval("top.location = 'index.cfm?fuseaction=addToCart&itemQty="+fldVal+"&itemid="+itemID+"'");
}

function submitForm(whtForm){
	eval("document."+whtForm+".submit()")
}

function chkForm(frmName,frmFields,fieldType){
	okToSubmit = true;
	alertFormError = "You have not filled out the form correctly.\n\nThe following form errors have been encountered:\n";
	arrFormFields = frmFields.split(',');
	arrFieldTypes = fieldType.split(',');
	if(debug){
		alert("form fields array: "+arrFormFields);
	}
	if(debug){
		alert("form name: "+frmName);
	}

	/* loop through all items to be checked */
	for(i=0; i<arrFormFields.length; i++){
		fieldName = "";
		fieldName = arrFormFields[i];
		fieldName = fieldName.replace("str_","");
		fieldName = fieldName.replace("cbo_","");
		fieldName = fieldName.replace("_"," ");		
		/* check if field is null */
		if(arrFieldTypes[i]==1){
			if(debug){
				alert('Check field '+i+' to see if null');
			}
			if(eval('document.'+frmName+'.'+arrFormFields[i]+'.value')==''){
				if(debug){
					alert('Field '+i+' is null');
				}
				alertFormError = alertFormError + "- The field "+fieldName+" is required but was not filled in.\n"
				okToSubmit = false;
			}
			else{
				if(debug){
					alert('Field '+i+' has a value of '+eval('document.'+frmName+'.'+arrFormFields[i]+'.value'));
				}
			}
		}

		/* check to see if atleast one select item is selected */
		else if(arrFieldTypes[i]==2){
			if(debug){
				alert('Check field '+i+' to see if any thing in select box is selected');
			}
			if(eval('document.'+frmName+'.'+arrFormFields[i]+'.selectedIndex')==-1){
				okToSubmit = false;
				alertFormError = alertFormError + "- The field "+fieldName+" is required but you did not pick anything from the select box.\n"
			}
		}		

		/* check to see if form is filled in, all numbers and in dollar format */		
		else if(arrFieldTypes[i]==3){
			decimalPos = -1;
			posAfter = -1;
			tstString = "";
			numOK = true;
			decCnt = 0;
			if(debug){
				alert('Check field '+i+' to see if is filled in');
			}
			if(eval('document.'+frmName+'.'+arrFormFields[i]+'.value')==""||eval('document.'+frmName+'.'+arrFormFields[i]+'.value')=="."||eval('document.'+frmName+'.'+arrFormFields[i]+'.value')=="0"){
				okToSubmit = false;
				alertFormError = alertFormError + "- The field "+fieldName+" is required but was not filled in.\n"
			}
			else{
				if(debug){
					alert('Check field '+i+' to see if is all numbers');
				}
				eval('tstString = document.'+frmName+'.'+arrFormFields[i]+'.value')
				for (var charCnt=0;charCnt < tstString.length;charCnt++){					
					if(debug){
						alert('Checking '+tstString.charAt(charCnt)+' to see if is number');
					}
					if((isNaN(tstString.charAt(charCnt))&&(tstString.charAt(charCnt)!="."))||(decCnt==1&&(tstString.charAt(charCnt)=="."))){
						if(debug){
							alert(tstString.charAt(charCnt)+' is not a number');
						}
						numOK = false;
					}	
					if(tstString.charAt(charCnt)=="."){
						decimalPos = charCnt;
						decCnt ++;
					}
				}
				if (!numOK){
					okToSubmit = false;
					alertFormError = alertFormError + "- The field "+fieldName+" must be a number. Only one decimal point is allowed.\n"
				}
				else{
					if (decimalPos == -1){
					}
					else{
						posAfter = (tstString.length-1)-decimalPos;
					}
					if(debug){
						alert('Number length '+tstString.length);
						alert('Decimal position '+decimalPos);
						alert('Places after decimal '+posAfter);
					}
					if (posAfter>2){
						okToSubmit = false;
					}
				}
			}
		}			

		/* if filled in check if all numbers and in dollar format */		
		else if(arrFieldTypes[i]==4){
			decimalPos = -1;
			posAfter = -1;
			tstString = "";
			numOK = true;
			decCnt = 0;
			if(debug){
				alert('Check field '+i+' to see if is filled in');
			}
			if(eval('document.'+frmName+'.'+arrFormFields[i]+'.value')=="."||eval('document.'+frmName+'.'+arrFormFields[i]+'.value')=="0"){
					okToSubmit = false;
					alertFormError = alertFormError + "- The field "+fieldName+" must be a number greater than zero.\n"
			}
			else if(eval('document.'+frmName+'.'+arrFormFields[i]+'.value')!=""){		
				if(debug){
					alert('Check field '+i+' to see if is all numbers');
				}
				eval('tstString = document.'+frmName+'.'+arrFormFields[i]+'.value')
				for (var charCnt=0;charCnt < tstString.length;charCnt++){					
					if(debug){
						alert('Checking '+tstString.charAt(charCnt)+' to see if is number');
					}
					if((isNaN(tstString.charAt(charCnt))&&(tstString.charAt(charCnt)!="."))||(decCnt==1&&(tstString.charAt(charCnt)=="."))){		
						if(debug){
							alert(tstString.charAt(charCnt)+' is not a number');
						}
						numOK = false;
					}	
					if(tstString.charAt(charCnt)=="."){
						decimalPos = charCnt;
						decCnt ++;
					}
				}
				if (!numOK){
					okToSubmit = false;
					alertFormError = alertFormError + "- The field "+fieldName+" must be a number. Only one decimal point is allowed.\n"
				}
				else{
					if (decimalPos == -1){
					}
					else{
						posAfter = (tstString.length-1)-decimalPos;
					}
					if (posAfter>2){
						okToSubmit = false;
						alertFormError = alertFormError + "- The field "+fieldName+" has too many decimal places.\n"
					}
				}
			}
		}

	}
	if(debug){
		alert(okToSubmit);
	}
	if (!okToSubmit){
		if(debug){
			alert('do not submit');
		}
		alert(alertFormError);
		return false;
	}
	else{
		if(debug){
			alert('ok to submit');
		}
		return true;
	}
}

function populateMainOptions(frmName,optFld,fieldName,arrOpt,arrVal){
	eval("document."+frmName+"."+optFld+".options.length = 0");	
	eval("loopCount = "+arrOpt+".length");
	for(i=0; i<=loopCount-1; i++){
		eval("document."+frmName+"."+optFld+".options["+i+"] = new Option('"+eval(arrOpt)[i]+"','"+eval(arrVal)[i]+"')");
	}
	eval("chgSubOptions('"+frmName+"','"+optFld+"','"+fieldName+"','arrSub','arrSub',0)");
}

function chgSubOptions(frmName,optFld,fieldName,arrOptPrefix,arrValPrefix,selIndex){
	eval("document."+frmName+"."+fieldName+".options.length = 0");
	eval("numArray = document."+frmName+"."+optFld+".selectedIndex");
	whtOptArray = arrOptPrefix+numArray;
	whtValArray = arrValPrefix+numArray;
	eval("loopCount = "+whtOptArray+".length");
	if (debug){
		eval("alert(whtOptArray+' length is '+"+whtOptArray+".length)");
		alert("loop for "+loopCount+" times")
	}
	if(loopCount>0){
		for(i=0; i<=loopCount-1; i++){
			if (debug){
				alert('test'+i);
				alert('selIndes = '+selIndex);
			}
			eval("document."+frmName+"."+fieldName+".options["+i+"] = new Option('"+eval(whtOptArray)[i]+"','"+eval(whtValArray)[i]+"')");
		}
	}
	else{
		eval("document."+frmName+"."+fieldName+".options[0] = new Option('no subcategories',-1)");
	}
	if (selIndex==-1){
		eval("document."+frmName+"."+fieldName+".selectedIndex = 0");
	}
	else{
		if (debug){
			alert("Subcategory has value");
		}
		for(i=0; i<=loopCount-1; i++){
			eval("chkVal = "+i);
			if (debug){
				alert('Value to match is: '+selIndex);
				alert('Checking against: '+chkVal);
			}
			if (selIndex == chkVal){
				if (debug){
					alert('Match made: '+selIndex+' & '+chkVal);
				}
				selInx = i;
			}
		}
		eval("document."+frmName+"."+fieldName+".selectedIndex = "+selInx);
	}
}

function popWin(whtURL,nameWin,winProps){
	eval(nameWin+" = window.open('"+whtURL+"','"+nameWin+"','"+winProps+"')");
}

function toDollarsAndCents(frmName,formField){
	numOK = true;
	decCnt = 0;
	alertFormError = "";
	if(eval('document.'+frmName+'.'+formField+'.value')!=""){		
		if(debug){
			alert('Check field '+formField+' to see if is all numbers');
		}
		eval('tstString = document.'+frmName+'.'+formField+'.value')
		for (var charCnt=0;charCnt < tstString.length;charCnt++){					
			if(debug){
				alert('Checking '+tstString.charAt(charCnt)+' to see if is number');
			}
			if(isNaN(tstString.charAt(charCnt))&&(tstString.charAt(charCnt)!=".")){		
				if(debug){
					alert(tstString.charAt(charCnt)+' is not a number');
				}
				numOK = false;
			}		
			if(tstString.charAt(charCnt)=="."){
				decCnt ++;
			}
		}
		if(!numOK){
			alertFormError = alertFormError+"The field "+formField+" must be a number. Only decimal points are allowed.\n"
		}
		if(decCnt>1){
			numOK = false;
			alertFormError = alertFormError+"The field "+formField+" has too many decimals in it.\n"
		}
		if(debug){
			alert(numOK);
		}
		if(numOK){
			var s = "" + Math.round(tstString * 100) / 100
			var i = s.indexOf('.')
			if(debug){
				alert(i);
			}
			if (i < 0){
				if(debug){
					alert(s);
				}
				eval("document."+frmName+"."+formField+".value = '"+s+".00"+"'");
			}
			else{
				var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
				if (i + 2 == s.length) t += "0"
				eval("document."+frmName+"."+formField+".value = '"+t+"'");
			}
		}
		else{
			alert(alertFormError);
		}
	}
}

function numDollarsAndCents(strNum){
tstString = strNum;
	var s = "" + Math.round(tstString * 100) / 100
	var i = s.indexOf('.')
	if(debug){
		alert(i);
	}
	if (i < 0){
		if(debug){
			alert(s);
		}
		s = s+'.00'
		return s;
	}
	else{
		var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
		if (i + 2 == s.length) t += "0"
		return t;
	}
}

function adjustTax(frmName,optFld,fieldName){
	eval("numSelCountry = document."+frmName+"."+optFld+".selectedIndex");
	//alert(numSelCountry);
	eval("strCountry = document."+frmName+"."+optFld+".options["+numSelCountry+"].value");
	strCountry = strCountry.toLowerCase()
	//alert(strCountry);
	if (strCountry == "united states"){
		//alert("no tax!");
		eval("document."+frmName+".txAmnt.value = 0");
		eval("document."+frmName+".USER3.value = 0");
		eval("document."+frmName+".ttlAmnt.value = numDollarsAndCents(parseFloat(document."+frmName+".startAmount.value))");
		eval("document."+frmName+".AMOUNT.value = numDollarsAndCents(parseFloat(document."+frmName+".startAmount.value))");
	}
	else{
		//alert("check province");
		eval("adjustTaxCan('"+frmName+"','"+fieldName+"')");
	}
}

function adjustTaxCan(frmName,fieldName){
	pstRt = 0;
	gstRt = 0;
	hstRt = 0;
	pstAmt = 0;
	gstAmt = 0;
	hstAmt = 0;
	ttlTaxAmt = 0;
	ttlAmt = 0;
	eval("numSelProv = document."+frmName+"."+fieldName+".selectedIndex");
	//alert(numSelProv)
	eval("hstRt = parseFloat(arrHst["+numSelProv+"])");
	//alert(hstRt);
	if (parseFloat(hstRt) != 0){
		eval("hstAmt = hstRt * parseFloat(document."+frmName+".startAmount.value)");
		hstAmt = numDollarsAndCents(hstAmt);
		hstAmt = parseFloat(hstAmt);
		//alert("HST amount: "+hstAmt);
		ttlTaxAmt = hstAmt
		//alert("Total tax: "+ttlTaxAmt);
		eval("document."+frmName+".txAmnt.value = numDollarsAndCents("+ttlTaxAmt+")");
		eval("document."+frmName+".USER4.value = numDollarsAndCents("+ttlTaxAmt+")");
		eval("ttlAmt = "+ttlTaxAmt+" + parseFloat(document."+frmName+".startAmount.value)");
		//alert(ttlAmt);
		eval("document."+frmName+".AMOUNT.value = numDollarsAndCents("+ttlAmt+")");
		eval("document."+frmName+".ttlAmnt.value = numDollarsAndCents("+ttlAmt+")");
	}
	else{
		eval("gstRt = parseFloat(arrGst["+numSelProv+"])");
		eval("gstAmt = gstRt * parseFloat(document."+frmName+".startAmount.value)");
		gstAmt = numDollarsAndCents(gstAmt);
		gstAmt = parseFloat(gstAmt);
		//alert("GST amount: "+gstAmt);
		eval("pstRt = parseFloat(arrPst["+numSelProv+"])");
		eval("pstAmt = pstRt * parseFloat(document."+frmName+".startAmount.value)");
		pstAmt = numDollarsAndCents(pstAmt);
		pstAmt = parseFloat(pstAmt);
		//alert("PST amount: "+pstAmt);
		ttlTaxAmt = gstAmt + pstAmt;
		ttlTaxAmt = numDollarsAndCents(ttlTaxAmt);
		ttlTaxAmt = parseFloat(ttlTaxAmt);
		//alert("Total tax: "+ttlTaxAmt);
		eval("document."+frmName+".txAmnt.value = numDollarsAndCents("+ttlTaxAmt+")");
		eval("document."+frmName+".USER4.value = numDollarsAndCents("+ttlTaxAmt+")");
		eval("ttlAmt = "+ttlTaxAmt+" + parseFloat(document."+frmName+".startAmount.value)");
		//alert(ttlAmt);
		eval("document."+frmName+".AMOUNT.value = numDollarsAndCents("+ttlAmt+")");
		eval("document."+frmName+".ttlAmnt.value = numDollarsAndCents("+ttlAmt+")");
	}
}

function savePurchInfo(frmName){
	eval("strName = document."+frmName+".NAME.value");
	eval("document.cookie='strName="+strName+"'");
	eval("strAddress = document."+frmName+".ADDRESS.value");
	eval("document.cookie='strAddress="+strAddress+"'");
	eval("strCity = document."+frmName+".CITY.value");
	eval("document.cookie='strCity="+strCity+"'");
	eval("selCountry = document."+frmName+".COUNTRY.selectedIndex");
	eval("document.cookie='selCountry="+selCountry+"'");
	eval("selState = document."+frmName+".STATE.selectedIndex");
	eval("document.cookie='selState="+selState+"'");
	eval("strZip = document."+frmName+".ZIP.value");
	eval("document.cookie='strZip="+strZip+"'");
	eval("strPhone = document."+frmName+".PHONE.value");
	eval("document.cookie='strPhone="+strPhone+"'");
	eval("strEmail = document."+frmName+".EMAIL.value");
	eval("document.cookie='strEmail="+strEmail+"'");
}

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function popPersonInfo(frmName){
	strName = get_cookie('strName');
	if (strName != "")	{
		eval("document."+frmName+".NAME.value = '"+strName+"'");
	}
	strAddress = get_cookie('strAddress');
	if (strAddress != "")	{
		eval("document."+frmName+".ADDRESS.value = '"+strAddress+"'");
	}
	strCity = get_cookie('strCity');
	if (strCity != "")	{
		eval("document."+frmName+".CITY.value = '"+strCity+"'");
	}
	selCountry = get_cookie('selCountry');
	if (selCountry != "")	{
		eval("document."+frmName+".COUNTRY.selectedIndex = '"+selCountry+"'");
	}
	chgSubOptions('payFlow','COUNTRY','STATE','arrSub','arrSub','');
	selState = get_cookie('selState');
	if (selState != "")	{
		eval("document."+frmName+".STATE.selectedIndex = '"+selState+"'");
	}
	strZip = get_cookie('strZip');
	if (strZip != "")	{
		eval("document."+frmName+".ZIP.value = '"+strZip+"'");
	}
	strPhone = get_cookie('strPhone');
	if (strPhone != "")	{
		eval("document."+frmName+".PHONE.value = '"+strPhone+"'");
	}
	strEmail = get_cookie('strEmail');
	if (strEmail != "")	{
		eval("document."+frmName+".EMAIL.value = '"+strEmail+"'");
	}
}