var allOn = true;
function setSelected(thisItem, parentItem){
	var currentSelectedItem = thisItem;
	
	var mySpans = document.getElementById(parentItem + "_div").getElementsByTagName("img");
    	for (var t=0,spn; spn=mySpans[t]; t++) {
        	spn.src = 'images/1pxTransparent.gif';
        }
	currentSelectedItem.src = 'images/checkmark.png';
	document.getElementById(parentItem).value = currentSelectedItem.title;
	
}
function SelectAll(MyForm,MyBox){
var countBoxes = eval("document."+MyForm+"."+MyBox+".length");
	if(!countBoxes){
		eval("document."+MyForm+"."+MyBox+".checked =  allOn");
	}
	else{
		for (var i=0; i<countBoxes ;i++){
			eval("document."+MyForm+"."+MyBox+"[i].checked =  allOn");
		}
	}
allOn = !allOn;
}

function cartMoreInfo(thisEl){
	if(document.getElementById(thisEl).style.display == 'none'){
		document.getElementById(thisEl).style.display = 'block';
	}
	else{
		document.getElementById(thisEl).style.display = 'none';
	}
}

function cleanField(obj){
	obj.value = obj.value.replace(/[^\d]/g,"");
	if(obj.value.length == 0 || obj.value == 0){obj.value=1}
}

var mycallBack = function(){
	processContent();
}
		<!--- The error handler pops an alert with the error code and message. --->
var myerrorHandler = function(errorCode,errorMessage) {
}

function setDynaList(arrDL){
 var theForm = findObj(arrDL[2]);var theForm2 = findObj(arrDL[4]);var oList1 = theForm.elements[arrDL[1]];
 var oList2 = theForm2.elements[arrDL[3]];var arrList = arrDL[5];clearDynaList(oList2);
 if (oList1.selectedIndex == -1){oList1.selectedIndex = 0;}
 populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);return true;
}
 
function clearDynaList(oList){
 for (var i = oList.options.length; i >= 0; i--){oList.options[i] = null;}oList.selectedIndex = -1;
}
 
function populateDynaList(oList, nIndex, aArray){
 for (var i = 0; i < aArray.length; i= i + 3){
  if (aArray[i] == nIndex){oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);}}
 if (oList.options.length == 0){oList.options[oList.options.length] = new Option("[none available]",0);}oList.selectedIndex = 0;
}

function findObj(theObj, theDoc){
  var p, i, foundObj;if(!theDoc) theDoc = document;if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {theDoc = parent.frames[theObj.substring(p+1)].document;theObj = theObj.substring(0,p);}
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);return foundObj;
}

function cwSameShipping(obj){
	//Is the checkboxed checked or not?
	var retVal = (!obj.checked)? true : false;
	var i,j,curObj;
	//Create a list of common fields minus their cst and cstShp prefixes respectively
	var arrCommonFields = new Array('Address1','Address2','City','Zip','Phone','Email');
	var arrCommonFields_length = arrCommonFields.length;
	//Create a list of special fields that have need other work done before they can have a value set or be enabled/disabled
	var arrSpecialFields = new Array('CompanyName','Name','Country','StateProv');
	//An array of all fields, both common and special for the purpose of enabling/disabling the fields
	var arrAllFields = arrCommonFields.concat(arrSpecialFields);
	var arrAllFields_length = arrAllFields.length;
	//Loop through common fields and set the shipping fields to the customer values
	for(i=0; i<arrCommonFields_length;i++){
		findObj('cstShp'+arrCommonFields[i]).value = findObj('cst'+arrCommonFields[i]).value;
	}
	//Combine the First & Last Name fields for the Full name field used in the Shipping Form
	findObj('cstShpName').value = findObj('cstCompanyName').value;
	//Set the Ship Country, then populate the state/prov list before setting its selected index.	
	findObj('cstShpCountry').selectedIndex = findObj('cstCountry').selectedIndex;
	//setDynaList(arrDL2);
	findObj('cstShpStateProv').selectedIndex = findObj('cstStateProv').selectedIndex;
	//Loop through all fields and disable them if the box is checked, otherwise enable the fields.
	for(j=0; j<arrAllFields_length;j++){
		curObj = findObj('cstShp'+arrAllFields[j]);
		if(curObj){			
			if(!retVal){curObj.setAttribute("readonly","readonly");}
			else{curObj.removeAttribute("readonly");}
		}
	}
return retVal;
}

function dwfaq_getCSSPropertyValue(obj,cP,jP){//v1.1 
//Copyright � 2004-2005 Angela C. Buraglia & DWfaq.com
//All Rights Reserved. Not for distribution. support@dwfaq.com
//Support Newsgroup: news://support.dwfaq.com/support
	if(typeof(obj)!='object'){var obj=document.getElementById(obj);}
	if(typeof(obj.currentStyle)!='object'){
		return (typeof(document.defaultView) == 'object' && document.defaultView.getComputedStyle(obj,''))?
		document.defaultView.getComputedStyle(obj,'').getPropertyValue(cP):
		obj.style.getPropertyValue(cP);}
	else{
		return (navigator.appVersion.indexOf('Mac')!=-1)?
		obj.currentStyle.getPropertyValue(cP):
		obj.currentStyle.getAttribute((jP)?jP:cP);}
}

function dwfaq_ToggleOMaticDisplay(){//v1.0
//Copyright � 2004 Angela C. Buraglia & DWfaq.com
//All Rights Reserved. Not for distribution. support@dwfaq.com
//Support Newsgroup: news://support.dwfaq.com/support
	var obj,cS,args=dwfaq_ToggleOMaticDisplay.arguments;document.MM_returnValue=(typeof(args[0].href)!='string')?true:false;
	for(var i=1;i<args.length;i++){obj=document.getElementById(args[i]);
		if(obj){cS=dwfaq_getCSSPropertyValue(obj,'display');
			if(!obj.dwfaq_OD){obj.dwfaq_OD=(cS!='none'&&cS!='')?cS:(obj.tagName.toUpperCase()=='TR' && cS!=='none')?'':
			(obj.tagName.toUpperCase()=='TR' && typeof(obj.currentStyle)!='object')?'table-row':'block';}
			obj.style.display=(cS!='none')?'none':obj.dwfaq_OD}}
}

function dwfaq_ToggleOMaticClass(){//v1.1
//Copyright � 2004-2005 Angela C. Buraglia & DWfaq.com
//All Rights Reserved. Not for distribution. support@dwfaq.com
//Support Newsgroup: news://support.dwfaq.com/support
	var obj,args=dwfaq_ToggleOMaticClass.arguments;document.MM_returnValue=(typeof(args[0].href)!='string')?true:false;
	for(var i=1;i<args.length-1;i+=2){obj=document.getElementById(args[i]);
		if(obj){if(!obj.dwfaq_OC){obj.dwfaq_OC=(obj.className=='')?true:obj.className;}
			if(obj.dwfaq_OC&&obj.className==args[i+1]){
				(obj.dwfaq_OC==true)?obj.className='':obj.className=obj.dwfaq_OC;}
			else{obj.className=args[i+1];}}}
}

function cwShowProductImage(imageURL,imageTitle){
	imgWindow = window.open('','imgWindow','scrollbars=no,width=500,height=500,left=100,top=100');
	with (imgWindow.document){
		writeln('<html><head><title>Loading...</title><style type="text/css">body{margin:0px;}</style>');
		writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');
		writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');
			writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function fitToImage(){');
			writeln('var img = document.getElementById("imgProduct");');
			writeln('var imgWidth = img.width;');
			writeln('var imgHeight = img.height;');
			writeln('if(isIE){');
				writeln('var windowWidth = document.body.clientWidth;');
				writeln('var windowHeight = document.body.clientHeight;}');
			writeln('if(isNN){');
				writeln('var windowWidth = window.innerWidth;');
				writeln('var windowHeight = window.innerHeight;');
			writeln('}');
			writeln('window.resizeBy((windowWidth - imgWidth)*-1, (windowHeight - imgHeight)*-1);}'); 
		writeln('function updateTitle(){document.title = "'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		writeln('</head><body onload="fitToImage();updateTitle();self.focus()" onblur="self.close()">');
		writeln('<div align="center"><img id="imgProduct" src="'+imageURL+'"></div></body></html>');
		close();
	}
	return false;
}

function cwSetDependentList(objCurrentList, listNumber){
	var arSelOptions = new Array();
	var arNextListOptions = new Array();
	var arMatchedOptions = new Array();
	var lastList = false;
	var finalOptionPos = -1;
	var objList = "";
	var i, j, k

	//Determine if this is the first list in the group
	if(listNumber > 0){
		//This is not the first list in the group, so loop through all lists and get their current selected values
		for(i=0; i<=listNumber; i++){
			//Get the current list as an object
			objList = document.getElementById("sel" + i);			
			//Get the current lists value and tack it to the end of the selected options array
			arSelOptions[i] = objList.options[objList.selectedIndex].value;
		}
	}
	else{
		//This is the first list in the group
		arSelOptions[0] = objCurrentList.options[objCurrentList.selectedIndex].value;
	}
	//Search through the options array to find all matches.
	if(!document.getElementById("sel" + (listNumber + 1))){
		lastList = true;
	}

	k = 0;
	var arOptions_length = arOptions.length;
	var arSelOptions_length = arSelOptions.length;
	for(i=0; i<arOptions_length; i++){
		for(j=0; j<arSelOptions_length; j++){
			//If there's a mismatched option, exit the loop
			if(arOptions[i]["optionIDs"][j] != arSelOptions[j]){break;}
			//We survived the if statement and matched all items, so we have a match
			if(j == arSelOptions_length - 1){
				if(lastList){
					//If this is the last list selected, then specify the final SKU selected
					finalOptionPos = i;
					break;
				}
				else{
					//We're not done yet, so just collect additional options
					//If we haven't already added the next option to the list, add it now.
					if(cwIndexInArray(arMatchedOptions, arOptions[i]["optionIDs"][j+1]) == -1){
						arNextListOptions[k] = Array(arOptions[i]["optionIDs"][j+1], arOptions[i]["optionNames"][j+1]);
						arMatchedOptions[k] = arOptions[i]["optionIDs"][j+1];
						k = k + 1;
					}
				}
			}
		}
		//If we've already specified the final SKU selected, break out of the parent for loop
		if(finalOptionPos != -1){break;}
	}

	if(lastList){
		var objDiv = document.getElementById("divPrice");
		//This is the last list, set the price div's value appropriately
		if(objDiv){
			if(finalOptionPos != -1){
				objDiv.innerHTML = arOptions[finalOptionPos]["price"];
			}
			else{
				objDiv.innerHTML = objDiv.getAttribute("title");
			}
		}
	}
	else{
		//We have the options for the next list, fill it up
		var nextList = document.getElementById("sel" + (listNumber + 1));
		cwClearList(nextList);
		cwPopulateList(nextList, arNextListOptions);
		cwSetDependentList(nextList, listNumber + 1)
	}
}
function cwIndexInArray(ar,str){
	for(var i=0; i<ar.length; i++){if(ar[i] == str){return i;}}
	return -1;
}
function cwClearList(objList){
	for(var i = objList.options.length; i >= 0; i--){objList.options[i] = null;}
	objList.selectedIndex = -1;
}

function cwPopulateList(objList, arr){
	var arr_length = arr.length;
	for(var i=0; i<arr_length; i++){objList.options[objList.options.length] = new Option(arr[i][1], arr[i][0]);}
	if(objList.options.length == 0){objList.options[objList.options.length] = new Option("No options available...",0);}
	objList.selectedIndex = 0;
}

function openEnvelopeImprint(thisOption) {
	
	var thisItem = document.getElementById(thisOption);
	
	if ((thisItem.value == 61)||(thisItem.value == 114)) {
		document.getElementById("envelopeimprint").style.display = "block";
	}
	else {
		//thisItem.value = thisItem.value;
		if(document.getElementById("envelopeimprint") != null)
			{
			document.getElementById("envelopeimprint").style.display = "none";
			}
	}
}
function proofAddEmail(){
	
	var thisProof = document.getElementById('info_option_11_Select');
		
	if(thisProof.value == "Yes")
	{
	document.getElementById('info_option_11_row').style.display='block';
	}
	else
	{
		document.getElementById('info_option_11_row').style.display='none';
	}
	
	console.log(thisProof.value);
}

function proofEmail(){

	document.getElementById('info_option_11').value = document.getElementById('info_option_11_Select').value + ' - ' + document.getElementById('info_option_11_EmailAddress').value;
	
}

function openSesame() {
	if(document.getElementById("hidePwdRequest").style.display == "none" )
		document.getElementById("hidePwdRequest").style.display="block";
	else
		document.getElementById("hidePwdRequest").style.display="none";
}