/****************** wholesale login *****************/

wsl = {
 	wholesaleID: 'wholesale',
	loginID: 'login',
	signupID: 'signup',
	switchLinkID1: 'switchLink1',
	switchLinkID2: 'switchLink2',
	
	loginSwapClass: 'loginSwap',
	hideClass: 'hide',
	
	init:function() {
		var wholesale=document.getElementById(wsl.wholesaleID); //look to the wholesale div
		
		var signupDIV=document.getElementById(wsl.signupID); //look to the sign up div		
		var loginDIV=document.getElementById(wsl.loginID); //look to the sign up div
		if (!DOMhelp.cssjs('check',loginDIV,wsl.hideClass)) { 
			DOMhelp.cssjs('add',signupDIV,wsl.hideClass);
		} 

		var switchLinkDIV=document.getElementById(wsl.switchLinkID1); //look to the switchLink up div
		if (switchLinkDIV) { DOMhelp.cssjs('remove',switchLinkDIV,wsl.hideClass); } //remove the hide class from the switchLinks
		var switchLinkDIV=document.getElementById(wsl.switchLinkID2); //look to the switchLink up div
		if (switchLinkDIV) { DOMhelp.cssjs('remove',switchLinkDIV,wsl.hideClass); } //remove the hide class from the switchLinks
		
		var links=wholesale.getElementsByTagName('a'); //grab all the links in the document
		if(!links) {return;}		
		
		//loop through all the links
		for(var i=0;i<links.length;i++) {
			if(DOMhelp.cssjs('check',links[i],wsl.loginSwapClass)) {
				DOMhelp.addEvent(links[i],'click',wsl.loginSignupSwap,false); //handle the click
				links[i].onclick=DOMhelp.safariClickFix;
			}
		}
	},
	loginSignupSwap:function() {
		var signupDIV=document.getElementById(wsl.signupID); //look to the sign up div
		var loginDIV=document.getElementById(wsl.loginID); //look to the sign up div
		
		if(DOMhelp.cssjs('check',loginDIV,wsl.hideClass)) {
			DOMhelp.cssjs('add',signupDIV,wsl.hideClass); //add the hide from the sign up DIV
			DOMhelp.cssjs('remove',loginDIV,wsl.hideClass); //remove the hide to the login DIV	
		} else {
			DOMhelp.cssjs('remove',signupDIV,wsl.hideClass); //remove the hide from the sign up DIV
			DOMhelp.cssjs('add',loginDIV,wsl.hideClass); //add the hide to the login DIV	
		}
	}
}
DOMhelp.addEvent(window,'load',wsl.init,false); //wsl - WholeSale Login



sba = {
 	wholesaleID: 'wholesale',
 	sameBillID: 'billSame',
 	
 	shipContact: 'shipContact',
 	shipCompany: 'shipCompany',
 	shipStreet1: 'shipStreet1',
 	shipStreet2: 'shipStreet2',
 	shipCity: 'shipCity',
 	shipState: 'shipState',
 	shipZip: 'shipZip',
 	shipCountry: 'shipCountry',
 	
 	billContact: 'billContact',
 	billCompany: 'billCompany',
 	billStreet1: 'billStreet1',
 	billStreet2: 'billStreet2',
 	billCity: 'billCity',
 	billState: 'billState',
 	billZip: 'billZip',
 	billCountry: 'billCountry',
 	
 	init:function() {
		var checkbox=document.getElementById(sba.sameBillID); //get radio button
		if(!checkbox){return;} //could not find the radio button

		DOMhelp.addEvent(checkbox,'click',sba.addBillAddress,false);
	},
	addBillAddress:function(e) {	 
	 	var sameBillChoice=DOMhelp.getTarget(e);

		var shipContact = document.getElementById(sba.shipContact); //
		var billContact = document.getElementById(sba.billContact); //			
		
		var shipCompany = document.getElementById(sba.shipCompany); //
		var billCompany = document.getElementById(sba.billCompany); //	
		
		var shipStreet1 = document.getElementById(sba.shipStreet1); //
		var billStreet1 = document.getElementById(sba.billStreet1); //		
		
		var shipStreet2 = document.getElementById(sba.shipStreet2); //
		var billStreet2 = document.getElementById(sba.billStreet2); //		
		
		var shipCity = document.getElementById(sba.shipCity); //
		var billCity = document.getElementById(sba.billCity); //
		
		var shipState = document.getElementById(sba.shipState); //
		var billState = document.getElementById(sba.billState); //			
		
		var shipZip = document.getElementById(sba.shipZip); //
		var billZip = document.getElementById(sba.billZip); //		
		
		var shipCountry = document.getElementById(sba.shipCountry); //
		var billCountry = document.getElementById(sba.billCountry); //
				 
	 	if(sameBillChoice.checked) {
			billContact.value=shipContact.value;			
			billCompany.value=shipCompany.value;			
			billStreet1.value=shipStreet1.value;			
			billStreet2.value=shipStreet2.value;			
			billCity.value=shipCity.value;			
			billState.value=shipState.value;			
			billZip.value=shipZip.value;			
			billCountry.value=shipCountry.value;													
		} else {
			billContact.value='';			
			billCompany.value='';			
			billStreet1.value='';			
			billStreet2.value='';			
			billCity.value='';			
			billState.value='';			
			billZip.value='';			
			billCountry.value='';	
		}
	}
}
DOMhelp.addEvent(window,'load',sba.init,false); //sba - Same Billing Address Function



keepCredit = {
	showCredit: 'showCreditOption',
	paymentType: 'payType',
	storeCredit: 'storeCredit',
	
	noHideOption: 'credit',
	storeCreditOption: 'yes',
	
	creditCardInputID: 'creditCardInput',
	creditCardInputID2: 'creditCardInput2',

	hideClass: 'hide',
	creditCardInputClass: 'creditCardInput',
	
	init:function() {
		var payType = document.getElementsByName(keepCredit.paymentType);
		for(var i=0;i<payType.length;i++) {
			if (payType[i].checked)
				var payTypeChoice = payType[i].value;
		}
	 	
	 	var showCreditDIV = document.getElementsByName(keepCredit.showCredit);
	 	
	 	if (payTypeChoice != keepCredit.noHideOption) {
			for(var i=0;i<showCreditDIV.length;i++) {
				DOMhelp.cssjs('add',showCreditDIV[i],keepCredit.hideClass);
			}
		}
		
		var payType = document.getElementsByName(keepCredit.paymentType);
		for(var i=0;i<payType.length;i++) {
			DOMhelp.addEvent(payType[i],'click',keepCredit.creditShopSwap,false); //handle the click
		}
		
		var storeCredit = document.getElementsByName(keepCredit.storeCredit);
		for(var i=0;i<storeCredit.length;i++) {
			if (storeCredit[i].checked)
				var storeCreditChoice = storeCredit[i].value;
		}

		var ccInput = document.getElementById(keepCredit.creditCardInputID);
		var ccInput2 = document.getElementById(keepCredit.creditCardInputID2);
		
		if (storeCreditChoice != keepCredit.storeCreditOption) {
			DOMhelp.cssjs('add',ccInput,keepCredit.hideClass);
			DOMhelp.cssjs('add',ccInput2,keepCredit.hideClass);
		}
		
		var storeCredit = document.getElementsByName(keepCredit.storeCredit);
		for(var i=0;i<storeCredit.length;i++) {
			DOMhelp.addEvent(storeCredit[i],'click',keepCredit.storeCreditHid,false); //handle the click
		}		
	},
	creditShopSwap:function() {		
		var payType = document.getElementsByName(keepCredit.paymentType);

		for(var i=0;i<payType.length;i++) {
			if (payType[i].checked)
				var payTypeChoice = payType[i].value;
		} 
		
		var storeCredit = document.getElementsByName(keepCredit.storeCredit);
		for(var i=0;i<storeCredit.length;i++) {
			if (storeCredit[i].checked)
				var storeCreditChoice = storeCredit[i].value;
		}		
	
	 	var showCreditDIV = document.getElementsByName(keepCredit.showCredit);

	 	if (payTypeChoice != keepCredit.noHideOption) {
			for(var i=0;i<showCreditDIV.length;i++) {
			 	if (!DOMhelp.cssjs('check',showCreditDIV[i],keepCredit.creditCardInputClass))
					DOMhelp.cssjs('add',showCreditDIV[i],keepCredit.hideClass);
				else if (storeCreditChoice == keepCredit.storeCreditOption)
					DOMhelp.cssjs('add',showCreditDIV[i],keepCredit.hideClass);
			}
		} else {
			for(var i=0;i<showCreditDIV.length;i++) {
			 	if (!DOMhelp.cssjs('check',showCreditDIV[i],keepCredit.creditCardInputClass))
					DOMhelp.cssjs('remove',showCreditDIV[i],keepCredit.hideClass);
				else if (storeCreditChoice == keepCredit.storeCreditOption)
					DOMhelp.cssjs('remove',showCreditDIV[i],keepCredit.hideClass);
			}			
		}
	},
	storeCreditHid:function() {
		var storeCredit = document.getElementsByName(keepCredit.storeCredit);
		for(var i=0;i<storeCredit.length;i++) {
			if (storeCredit[i].checked)
				var storeCreditChoice = storeCredit[i].value;
		}

		var ccInput = document.getElementById(keepCredit.creditCardInputID);
		var ccInput2 = document.getElementById(keepCredit.creditCardInputID2);
		
		if (storeCreditChoice != keepCredit.storeCreditOption) {
			DOMhelp.cssjs('add',ccInput,keepCredit.hideClass);
			DOMhelp.cssjs('add',ccInput2,keepCredit.hideClass);
		} else {
			DOMhelp.cssjs('remove',ccInput,keepCredit.hideClass);
			DOMhelp.cssjs('remove',ccInput2,keepCredit.hideClass);
		}		
	}
}
DOMhelp.addEvent(window,'load',keepCredit.init,false); //if choose credit card and if to keep options



scca = {
 	sameAddress: 'ccSameAddress',
 	
 	billStreet1: 'billStreet1',
 	billStreet2: 'billStreet2',
 	billCity: 'billCity',
 	billState: 'billState',
 	billZip: 'billZip',
 	billCountry: 'billCountry',
 	
 	CCStreet1: 'CCstreet1',
 	CCStreet2: 'CCstreet2',
 	CCCity: 'CCcity',
 	CCState: 'CCstate',
 	CCZip: 'CCzip',
 	CCCountry: 'CCcountry', 	
 	
 	init:function() {
		var checkbox=document.getElementById(scca.sameAddress); //get checkbox
		if(!checkbox){return;} //could not find the radio button

		DOMhelp.addEvent(checkbox,'click',scca.addBillAddress,false);
	},
	addBillAddress:function(e) {	 
	 	var sameBillChoice=DOMhelp.getTarget(e);
		
		var billStreet1 = document.getElementById(scca.billStreet1); //
		var CCStreet1 = document.getElementById(scca.CCStreet1); //		
		
		var billStreet2 = document.getElementById(scca.billStreet2); //
		var CCStreet2 = document.getElementById(scca.CCStreet2); //		
		
		var billCity = document.getElementById(scca.billCity); //
		var CCCity = document.getElementById(scca.CCCity); //
		
		var billState = document.getElementById(scca.billState); //
		var CCState = document.getElementById(scca.CCState); //			
		
		var billZip = document.getElementById(scca.billZip); //
		var CCZip = document.getElementById(scca.CCZip); //		
		
		var billCountry = document.getElementById(scca.billCountry); //
		var CCCountry = document.getElementById(scca.CCCountry); //
				 
	 	if(sameBillChoice.checked) {		
			CCStreet1.value=billStreet1.value;			
			CCStreet2.value=billStreet2.value;			
			CCCity.value=billCity.value;			
			CCState.value=billState.value;			
			CCZip.value=billZip.value;			
			CCCountry.value=billCountry.value;													
		} else {			
			CCStreet1.value='';			
			CCStreet2.value='';			
			CCCity.value='';			
			CCState.value='';			
			CCZip.value='';			
			CCCountry.value='';	
		}
	}
}
DOMhelp.addEvent(window,'load',scca.init,false); //scca - Same Credit Card Address


function IsNumeric(strString)
//  check for valid numeric strings	
{
var strValidChars = "0123456789";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

//  test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
  {
  strChar = strString.charAt(i);
  if (strValidChars.indexOf(strChar) == -1)
     {
     blnResult = false;
     }
  }
return blnResult;
}

pct = {
	designSelect: 'designSelect',
	styleSelect: 'styleSelect',
	swatchSelect: 'swatchSelect',
	sizeSelect: 'sizeSelect',
	quantityInput: 'quantityInput',
	quantityUpdate: 'quantityUpdate',
	
	addToOrderSubmit: 'addToOrder',

	noChoice: '0',
	hideClass: 'hide',
	quantityUpdateClass: 'quantityUpdate',
	offColor: '#aaa',
	onColor: '#222',
	quantityStart: 'qty',
	
	init:function() {
		var design=document.getElementById(pct.designSelect); //
		if(!design){return;} //could not find the radio button
		
		DOMhelp.addEvent(design,'change',pct.designChange,false);
		DOMhelp.addEvent(design,'change',pct.submitStatus,false);
		
		for(var i=0;i<design.length;i++) {
			var style=document.getElementById(pct.styleSelect + design.options[i].value); //get checkbox
			DOMhelp.addEvent(style,'change',pct.styleChange,false);
			DOMhelp.addEvent(style,'change',pct.submitStatus,false);
		}
		
		var swatch = new Array();
		var design_array=document.getElementById(pct.designSelect);
		
		for(var i=0;i<design_array.length;i++) {
		 	var style_array=document.getElementById(pct.styleSelect + design_array.options[i].value);
		 	
			for(var j=0;j<style_array.length;j++) {
				tempSwatch=document.getElementById(pct.swatchSelect + design_array[i].value + '-' + style_array[j].value);
				
				if (tempSwatch)
					swatch[swatch.length] = tempSwatch;
			}
		}
		for(var i=0;i<swatch.length;i++) {
			DOMhelp.addEvent(swatch[i],'change',pct.submitStatus,false);
		}	
		
		var size=document.getElementById(pct.sizeSelect);
		DOMhelp.addEvent(size,'change',pct.submitStatus,false);
		
		var quantity=document.getElementById(pct.quantityInput);
		quantity.value = pct.quantityStart;
		DOMhelp.addEvent(quantity,'click',pct.orderQuantityClick,false);
		DOMhelp.addEvent(quantity,'change',pct.orderQuantityChange,false);
		DOMhelp.addEvent(quantity,'blur',pct.orderQuantityBlur,false);
		DOMhelp.addEvent(quantity,'change',pct.submitStatus,false);
		DOMhelp.addEvent(quantity,'keyup',pct.submitStatus,false);
		
		var quantityUpdateInput=document.getElementsByTagName("input");
		for(var i=0;i<quantityUpdateInput.length;i++)
		{
			if (DOMhelp.cssjs('check',quantityUpdateInput[i],pct.quantityUpdateClass)) {
				DOMhelp.addEvent(quantityUpdateInput[i],'keyup',pct.checkQuantityUpdate,false);
				DOMhelp.addEvent(quantityUpdateInput[i],'change',pct.emptyQuantityUpdate,false);
			}
		}
		
		designChoice = design.value;

		if (designChoice == pct.noChoice) { //chose the 0 option
			var style=document.getElementById(pct.styleSelect + pct.noChoice);
			DOMhelp.cssjs('remove',style,pct.hideClass);
			
			var swatch=document.getElementById(pct.swatchSelect + pct.noChoice + '-' + pct.noChoice);
			DOMhelp.cssjs('remove',swatch,pct.hideClass);
		} else {
			for(var i=0;i<design.length;i++) {
				var style=document.getElementById(pct.styleSelect + design.options[i].value); //get checkbox
				//style.disabled=false;
				
				if (style.id == (pct.styleSelect + designChoice)) {
					DOMhelp.cssjs('remove',style,pct.hideClass);
					styleChoice = style.value;
				}
				else
					DOMhelp.cssjs('add',style,pct.hideClass);
			}
		
			if (styleChoice == pct.noChoice) { //chose the 0 option
				for(var i=0;i<swatch.length;i++) {
					//swatch[i].disabled=true;
					
					if (swatch[i].id == (pct.swatchSelect + pct.noChoice + '-' + pct.noChoice))
						DOMhelp.cssjs('remove',swatch[i],pct.hideClass);
					else
						DOMhelp.cssjs('add',swatch[i],pct.hideClass);
				}			
			} else {
				for(var i=0;i<swatch.length;i++) {
					//swatch[i].disabled=false;
					
					if (swatch[i].id == (pct.swatchSelect + designChoice + '-' + styleChoice))
						DOMhelp.cssjs('remove',swatch[i],pct.hideClass);
					else
						DOMhelp.cssjs('add',swatch[i],pct.hideClass);
				}
			}			
		}
		
		var addToOrder=document.getElementById(pct.addToOrderSubmit);
		addToOrder.disabled=true;
		addToOrder.style.color = pct.offColor;
	},
	designChange:function(e) {
		var design=DOMhelp.getTarget(e);
		
		while(design.nodeName.toLowerCase()!='select') {
			design=design.parentNode;
		}
		
		designChoice = design.value;

		if (designChoice == pct.noChoice) { //chose the 0 option
			for(var i=0;i<design.length;i++) {
				var style=document.getElementById(pct.styleSelect + design.options[i].value); //get checkbox
				//style.disabled=true;
			}			
		} else {
			for(var i=0;i<design.length;i++) {
				var style=document.getElementById(pct.styleSelect + design.options[i].value); //get checkbox
				//style.disabled=false;
				
				if (style.id == (pct.styleSelect + designChoice)) {
					DOMhelp.cssjs('remove',style,pct.hideClass);
					styleChoice = style.value;
				}
				else
					DOMhelp.cssjs('add',style,pct.hideClass);	
			}
			
			var swatch = new Array();
			var design_array=document.getElementById(pct.designSelect);
			
			for(var i=0;i<design_array.length;i++) {
			 	var style_array=document.getElementById(pct.styleSelect + design_array.options[i].value);
			 	
				for(var j=0;j<style_array.length;j++) {
					tempSwatch=document.getElementById(pct.swatchSelect + design_array[i].value + '-' + style_array[j].value);
					
					if (tempSwatch)
						swatch[swatch.length] = tempSwatch;
				}
			}
		
			if (styleChoice == pct.noChoice) { //chose the 0 option
				for(var i=0;i<swatch.length;i++) {
					//swatch[i].disabled=true;
					
					if (swatch[i].id == (pct.swatchSelect + pct.noChoice + '-' + pct.noChoice))
						DOMhelp.cssjs('remove',swatch[i],pct.hideClass);
					else
						DOMhelp.cssjs('add',swatch[i],pct.hideClass);
				}			
			} else {
				for(var i=0;i<swatch.length;i++) {
					//swatch[i].disabled=false;
					
					if (swatch[i].id == (pct.swatchSelect + designChoice + '-' + styleChoice))
						DOMhelp.cssjs('remove',swatch[i],pct.hideClass);
					else
						DOMhelp.cssjs('add',swatch[i],pct.hideClass);
				}
			}		
		}
	},
	styleChange:function(e) {
		var style=DOMhelp.getTarget(e);
		
		while(style.nodeName.toLowerCase()!='select') {
			style=style.parentNode;
		}
		
		var design=document.getElementById(pct.designSelect); //
		
		designChoice = design.value;
		styleChoice = style.value;
		
		var swatch = new Array();
		var design_array=document.getElementById(pct.designSelect);
		
		for(var i=0;i<design_array.length;i++) {
		 	var style_array=document.getElementById(pct.styleSelect + design_array.options[i].value);
		 	
			for(var j=0;j<style_array.length;j++) {
				tempSwatch=document.getElementById(pct.swatchSelect + design_array[i].value + '-' + style_array[j].value);
				
				if (tempSwatch)
					swatch[swatch.length] = tempSwatch;
			}
		}

		if (styleChoice == pct.noChoice) { //chose the 0 option
			for(var i=0;i<swatch.length;i++) {
				//swatch[i].disabled=true;
			}			
		} else {
			for(var i=0;i<swatch.length;i++) {
				//swatch[i].disabled=false;
				
				if (swatch[i].id == (pct.swatchSelect + designChoice + '-' + styleChoice))
					DOMhelp.cssjs('remove',swatch[i],pct.hideClass);
				else
					DOMhelp.cssjs('add',swatch[i],pct.hideClass);
			}
		}		
	},
	orderQuantityClick:function(e) {
		var quantity=DOMhelp.getTarget(e);
		
		while(quantity.nodeName.toLowerCase()!='input') {
			quantity=quantity.parentNode;
		}

		if (quantity.value == pct.quantityStart) {
			quantity.value = "";
		}	
	},
	orderQuantityChange:function(e) {
		var quantity=DOMhelp.getTarget(e);
		
		while(quantity.nodeName.toLowerCase()!='input') {
			quantity=quantity.parentNode;
		}
			
		if (!IsNumeric(quantity.value)) {
			quantity.value = pct.quantityStart;
		}
	},
	orderQuantityBlur:function(e) {
		var quantity=DOMhelp.getTarget(e);
		
		while(quantity.nodeName.toLowerCase()!='input') {
			quantity=quantity.parentNode;
		}

		if (quantity.value.replace(/^\s+|\s+$/g,"") == "") {
			quantity.value = pct.quantityStart;
		}	
	},
	checkQuantityUpdate:function(e) {
		var quantity=DOMhelp.getTarget(e);
		
		while(quantity.nodeName.toLowerCase()!='input') {
			quantity=quantity.parentNode;
		}
		
		if (!IsNumeric(quantity.value)) {
		 	if (quantity.value.length >= 1)
				quantity.value = quantity.value.substring(0,(quantity.value.length - 1));
		}		
	},
	emptyQuantityUpdate:function(e) {
		var quantity=DOMhelp.getTarget(e);
		
		while(quantity.nodeName.toLowerCase()!='input') {
			quantity=quantity.parentNode;
		}
		
		if (quantity.value.replace(/^\s+|\s+$/g,"").length == 0)
			quantity.value = '0';
	},
	submitStatus:function() {
		var addToOrder=document.getElementById(pct.addToOrderSubmit);
			 
		var design=document.getElementById(pct.designSelect);
		designChoice = design.value;
		
		if (designChoice != pct.noChoice) {
			var style=document.getElementById(pct.styleSelect + designChoice);
			styleChoice = style.value;
			
			if (styleChoice != pct.noChoice) {
			 	var swatch=document.getElementById(pct.swatchSelect + designChoice + '-' + styleChoice);
			 	swatchChoice = swatch.value;
			 	
			 	if (swatchChoice != pct.noChoice) {
			 	 	var size=document.getElementById(pct.sizeSelect);
			 	 	sizeChoice = size.value;
			 	 
			 	 	if (sizeChoice != pct.noChoice) {
			 	 	 	var quantity=document.getElementById(pct.quantityInput);
						
						if (IsNumeric(quantity.value)) {
						 	if (quantity.value > 0) {
								addToOrder.disabled=false;
								addToOrder.style.color = pct.onColor;									
							} else {
								addToOrder.disabled=true;
								addToOrder.style.color = pct.offColor;
							}						
						} else {
							addToOrder.disabled=true;
							addToOrder.style.color = pct.offColor;
						}
					} else {
						addToOrder.disabled=true;
						addToOrder.style.color = pct.offColor;
					}
				} else {
					addToOrder.disabled=true;
					addToOrder.style.color = pct.offColor;
				}
			} else {
				addToOrder.disabled=true;
				addToOrder.style.color = pct.offColor;
			}
		} else {
			addToOrder.disabled=true;
			addToOrder.style.color = pct.offColor;
		}
	}
}
DOMhelp.addEvent(window,'load',pct.init,false); //pt - Product Choice Table