function change(id){
	ID = document.getElementById(id);
	if(ID.style.display == "")
		ID.style.display = "none";
	else
		ID.style.display = "";
}

function toggleVis(toggle) {
	if (document.getElementById(toggle).style.display=='none') {
		document.getElementById(toggle).style.display='block';
	} else {
		document.getElementById(toggle).style.display='none';
	}
}

function toggleVis2(toggle) {
	if (document.getElementById(toggle).style.display=='none') {
		document.getElementById(toggle).style.display='inline';
	} else {
		document.getElementById(toggle).style.display='none';
	}
}

function PopUp(page) { 
	OpenWin = window.open(page, "PhotoWindow", "width=585,height=485,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no"); 
}

function CVV(page) {
	OpenWin = window.open(page, "CVVWindow", "width=340,height=550,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no");
}

function GiftOptions(page) {
	OpenWin = window.open(page, "GiftWindow", "width=400,height=550,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no");
}

function Remember(page) {
	OpenWin = window.open(page, "RememberWindow", "width=340,height=350,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no");
}

function ShipInfo(page) {
	OpenWin = window.open(page, "ShipInfoWindow", "width=340,height=350,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no");
}

function SmallWindow(page) {
	OpenWin = window.open(page, "SmallWindow", "width=500,height=400,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes");
}

function setCount(target){
	try {
		document.getElementById('passSize').value = document.getElementById('size').options[document.getElementById('size').selectedIndex].value.split('~')[0];
	} catch(err) {}
	try {
		document.getElementById('passLength').value = document.getElementById('length').options[document.getElementById('length').selectedIndex].value;
	} catch(err) {}
	try {
		document.getElementById('passWidth').value = document.getElementById('width').options[document.getElementById('width').selectedIndex].value;
	} catch(err) {}
	try {
		document.getElementById('passColor').value = document.getElementById('color').options[document.getElementById('color').selectedIndex].value;
	} catch(err) {}
	if(target == 0) document.Product.action="store/addtocart.cfm";
	if(target == 1) document.Product.action="store/addtowishlist.cfm";
}

function showLoading() {
	document.getElementById('loadID').style.display = 'block';
	document.getElementById('submitID').style.display = 'none';
	setTimeout('hideLoading()', 2000); 
}
function hideLoading() {
	document.getElementById('loadID').style.display = 'none';
	document.getElementById('submitID').style.display = 'block';
}

function refreshLocator (url, async, output) {
	showLoading();
	if (document.getElementById('boxAutoSub').value == 'yes' && document.getElementById('refCheck').value != 'yes' && document.getElementById('nocache').value != 'reset') {
		document.getElementById('locBoxForm').submit();
	} else {
		var request = new XMLHttpRequest();
		var async = async ? async : false;
		request.open("GET", url, async);
		if (async) {
			request.onreadystatechange = function () {
				if (request.readyState === 4 && request.status === 200)
				{
					output(request.responseText);
				}
			};
			request.send(null);
		} else {
			request.send(null);
			document.getElementById('locBox').innerHTML = request.responseText;
		}
	}
}

function optionMenu (url, async, output) {
	var request = new XMLHttpRequest();
	var async = async ? async : false;
	request.open("GET", url, async);
	if (async) {
		request.onreadystatechange = function () {
			if (request.readyState === 4 && request.status === 200)
			{
				output(request.responseText);
			}
		};
		request.send(null);
	} else {
		request.send(null);
		document.getElementById('prodOptions').innerHTML = request.responseText;
	}
}

function genURL() {
	if (document.getElementById('boxAutoSub').value == 'yes') {
		ajaxURL = 'locator-new.cfm?LocatorForm=y&autosub=yes&';
	} else {
		ajaxURL = 'locator-new.cfm?';
	}
	if (document.getElementById('boxCategory').value == 'Socks') {
		ajaxURL = ajaxURL+'Category=Socks&Gender='+document.getElementById('boxGender').options[document.getElementById('boxGender').selectedIndex].value;
		ajaxURL = ajaxURL+'&Length='+document.getElementById('boxLength').options[document.getElementById('boxLength').selectedIndex].value;
		ajaxURL = ajaxURL+'&Style='+document.getElementById('boxStyle').options[document.getElementById('boxStyle').selectedIndex].value;
		ajaxURL = ajaxURL+'&ActCon='+document.getElementById('boxActCon').options[document.getElementById('boxActCon').selectedIndex].value;
		ajaxURL = ajaxURL+'&Color='+document.getElementById('boxColor').options[document.getElementById('boxColor').selectedIndex].value;
		ajaxURL = ajaxURL+'&Pattern='+document.getElementById('boxPattern').options[document.getElementById('boxPattern').selectedIndex].value;
		ajaxURL = ajaxURL+'&Mfg='+document.getElementById('boxMfg').options[document.getElementById('boxMfg').selectedIndex].value;
	} else if (document.getElementById('boxCategory').value == 'Therapy') {
		ajaxURL = ajaxURL+'Category=Therapy&Gender='+document.getElementById('boxGender').options[document.getElementById('boxGender').selectedIndex].value;
		ajaxURL = ajaxURL+'&Length='+document.getElementById('boxLength').options[document.getElementById('boxLength').selectedIndex].value;
		ajaxURL = ajaxURL+'&Color='+document.getElementById('boxColor').options[document.getElementById('boxColor').selectedIndex].value;
		ajaxURL = ajaxURL+'&SupportLev='+document.getElementById('boxSupportLev').options[document.getElementById('boxSupportLev').selectedIndex].value;
		ajaxURL = ajaxURL+'&Condition='+document.getElementById('boxCondition').options[document.getElementById('boxCondition').selectedIndex].value;
		ajaxURL = ajaxURL+'&ToeType='+document.getElementById('boxToeType').options[document.getElementById('boxToeType').selectedIndex].value;
		ajaxURL = ajaxURL+'&Mfg='+document.getElementById('boxMfg').options[document.getElementById('boxMfg').selectedIndex].value;
	} else if (document.getElementById('boxCategory').value == 'Shoes') {
		ajaxURL = ajaxURL+'Category=Shoes&Gender='+document.getElementById('boxGender').options[document.getElementById('boxGender').selectedIndex].value;
		ajaxURL = ajaxURL+'&Style='+document.getElementById('boxStyle').options[document.getElementById('boxStyle').selectedIndex].value;
		ajaxURL = ajaxURL+'&Closure='+document.getElementById('boxClosure').options[document.getElementById('boxClosure').selectedIndex].value;
		ajaxURL = ajaxURL+'&Size='+document.getElementById('boxSize').options[document.getElementById('boxSize').selectedIndex].value;
		ajaxURL = ajaxURL+'&Width='+document.getElementById('boxWidth').options[document.getElementById('boxWidth').selectedIndex].value;
		ajaxURL = ajaxURL+'&Color='+document.getElementById('boxColor').options[document.getElementById('boxColor').selectedIndex].value;
		ajaxURL = ajaxURL+'&Mfg='+document.getElementById('boxMfg').options[document.getElementById('boxMfg').selectedIndex].value;
	}
	return ajaxURL;
}

function genURL2(pid) {
	ajaxURL = 'inc_prodoptions.cfm?pid='+pid+'&curGender='+document.getElementById('curGender').value;
	if (document.getElementById('size').type == 'select-one') {
		ajaxURL = ajaxURL+'&curSize='+encodeURIComponent(document.getElementById('size').options[document.getElementById('size').selectedIndex].value);
	}
	if (document.getElementById('length').type == 'select-one') {
		ajaxURL = ajaxURL+'&curLength='+encodeURIComponent(document.getElementById('length').options[document.getElementById('length').selectedIndex].value);
	}
	if (document.getElementById('width').type == 'select-one') {
		ajaxURL = ajaxURL+'&curWidth='+encodeURIComponent(document.getElementById('width').options[document.getElementById('width').selectedIndex].value);
	}
	if (document.getElementById('color').type == 'select-one') {
		ajaxURL = ajaxURL+'&curColor='+encodeURIComponent(document.getElementById('color').options[document.getElementById('color').selectedIndex].value);
	}
	return ajaxURL;
}

function priceAdj() {
	var basePrice = document.getElementById('startPrice').value;
	var baseList = document.getElementById('startList').value;
	
	try {
		if (document.getElementById('size').type == 'select-one' && parseFloat(document.getElementById('size').options[document.getElementById('size').selectedIndex].text.split('$')[1].split(')')[0]) != undefined) {
			basePrice = parseFloat(basePrice)+parseFloat(document.getElementById('size').options[document.getElementById('size').selectedIndex].text.split('$')[1].split(')')[0]);
			baseList = parseFloat(baseList)+parseFloat(document.getElementById('size').options[document.getElementById('size').selectedIndex].text.split('$')[1].split(')')[0]);
		}
	} catch (err) {}
	
	try {
		if (document.getElementById('length').type == 'select-one' && parseFloat(document.getElementById('length').options[document.getElementById('length').selectedIndex].text.split('$')[1].split(')')[0]) != undefined) {
			basePrice = parseFloat(basePrice)+parseFloat(document.getElementById('length').options[document.getElementById('length').selectedIndex].text.split('$')[1].split(')')[0]);
			baseList = parseFloat(baseList)+parseFloat(document.getElementById('length').options[document.getElementById('length').selectedIndex].text.split('$')[1].split(')')[0]);
		}
	} catch (err) {}
	
	try {
		if (document.getElementById('width').type == 'select-one' && parseFloat(document.getElementById('width').options[document.getElementById('width').selectedIndex].text.split('$')[1].split(')')[0]) != undefined) {
			basePrice = parseFloat(basePrice)+parseFloat(document.getElementById('width').options[document.getElementById('width').selectedIndex].text.split('$')[1].split(')')[0]);
			baseList = parseFloat(baseList)+parseFloat(document.getElementById('width').options[document.getElementById('width').selectedIndex].text.split('$')[1].split(')')[0]);
		}
	} catch (err) {}
	
	try {
		if (document.getElementById('color').type == 'select-one' && parseFloat(document.getElementById('color').options[document.getElementById('color').selectedIndex].text.split('$')[1].split(')')[0]) != undefined) {
			basePrice = parseFloat(basePrice)+parseFloat(document.getElementById('color').options[document.getElementById('color').selectedIndex].text.split('$')[1].split(')')[0]);
			baseList = parseFloat(baseList)+parseFloat(document.getElementById('color').options[document.getElementById('color').selectedIndex].text.split('$')[1].split(')')[0]);
		}
	} catch (err) {}
	
	for (i = 1; i <= document.getElementById('totalOpts').value; i++) {
		if (document.getElementById('curOpt'+i).checked == true) {
			try {
				basePrice = parseFloat(basePrice)+parseFloat(document.getElementById('curOptP'+i).innerHTML.split('$')[1]);
				baseList = parseFloat(baseList)+parseFloat(document.getElementById('curOptP'+i).innerHTML.split('$')[1]);
			} catch (err) {}
		}
	}
	
	if (document.getElementById('listPrice') != null) {
		document.getElementById('listPrice').innerHTML = '$'+parseFloat(baseList).toFixed(2);
	}
	if (document.getElementById('basePrice') != null) {
		document.getElementById('basePrice').innerHTML = '$'+parseFloat(basePrice).toFixed(2);
	}
}

function lightBox(photoSrc,photoColor,sortOrder) {
	var photoColor = photoColor.replace(' ', '');

	if (window.innerWidth != undefined) {
		if (window.innerWidth < 1000) {
			document.getElementById('light').style.width=window.innerWidth-75+'px';
			document.getElementById('light').style.left='0px';
		} else {
			document.getElementById('light').style.left=((window.innerWidth-1000)/2)-10+'px';
		}
		if (window.innerHeight < 650) {
			document.getElementById('light').style.height=window.innerHeight-150+'px';
		}
	} else {
		if (document.body.clientWidth < 1000) {
			document.getElementById('light').style.width=document.body.clientWidth-75+'px';
			document.getElementById('light').style.left='0px';
		} else {
			document.getElementById('light').style.left=((document.body.clientWidth-1000)/2)-10+'px';
		}
		if (document.body.clientHeight < 650) {
			document.getElementById('light').style.height=document.body.clientHeight-150+'px';
		}
	}
	
	if (photoSrc != '' && photoSrc != 'nochange') {
		document.getElementById('largePhoto').src=photoSrc;
		document.getElementById('largePhoto').alt=sortOrder;
	} else if (sortOrder != '' && photoColor != 'All') {
		try {
			document.getElementById('largePhoto').src=document.getElementById('photoSort-'+photoColor+'-'+sortOrder).innerHTML;
			document.getElementById('largePhoto').alt=sortOrder;
		} catch (err) {}
	}
	document.getElementById('photoMenu').innerHTML=document.getElementById('photoMenu'+photoColor).innerHTML;
	
	document.getElementById('light').style.display='block';
	document.getElementById('fade2').style.display='block';
}

function lightBoxClose() {
	document.getElementById('light').style.display='none';
	document.getElementById('fade2').style.display='none';
}

function getColorPhotos(photoDiv) {
	if (photoDiv != '' && photoDiv != 'undefined' && document.getElementById('colorPhotos') != 'undefined' && document.getElementById('colorPhotos') != null) {
		document.getElementById('colorPhotos').innerHTML=document.getElementById('colorPhotos'+photoDiv).innerHTML;
	} else if (document.getElementById('colorPhotos') != 'undefined'  && document.getElementById('colorPhotos') != null) {
		document.getElementById('colorPhotos').innerHTML='';
	}
}

function lockBorder(divID,thumbID) {
	if (document.getElementById(divID) != null) {
		var theListLen = document.getElementById(divID).getElementsByTagName('img');
		for (i = 0; i < theListLen.length; i++) {
			if (theListLen[i].id == thumbID) {
				theListLen[i].style.border = '1px solid #0000FF';
			} else {
				theListLen[i].style.border = '1px solid #CCC';
			}
		}
		if (divID != 'photoMenuAll' && document.getElementById('photoMenuAll') != null) {
			var theListLen = document.getElementById('photoMenuAll').getElementsByTagName('img');
			for (i = 0; i < theListLen.length; i++) {
				if (theListLen[i].id == thumbID) {
					theListLen[i].style.border = '1px solid #0000FF';
				} else {
					theListLen[i].style.border = '1px solid #CCC';
				}
			}
		}
	}
}

function selectColor(colorName) {
	for (i=0; i <= document.getElementById('color').options.length; i++) {
		if (document.getElementById('color').options[i].text == colorName) {document.getElementById('color').options[i].selected=true;break;}
	}
}

function setCFSBox() {
	var obj=document.getElementById('txtHint').style;
	obj.top="24px";
	obj.left="12px"; 
}

function cMenuChange(curID) {
	optionMenu(genURL2(curID));
	priceAdj();
	if (document.getElementById('color').options[document.getElementById('color').selectedIndex].value != '') {
		if (document.getElementById('photoSort2-'+document.getElementById('color').options[document.getElementById('color').selectedIndex].value.replace(' ', '')+'-'+document.getElementById('curMainSort').innerHTML) != null) {
			document.getElementById('PhotoView').src = document.getElementById('photoSort2-'+document.getElementById('color').options[document.getElementById('color').selectedIndex].value.replace(' ', '')+'-'+document.getElementById('curMainSort').innerHTML).innerHTML;
			document.getElementById('PhotoView').alt = document.getElementById('color').options[document.getElementById('color').selectedIndex].value;
			document.getElementById('notAvail').style.display = 'none';
		} else {
			document.getElementById('notAvail').style.display = 'block';
		};
	} else {
		document.getElementById('notAvail').style.display = 'none';
	};
	if (document.getElementById('colorPhotos'+document.getElementById('color').options[document.getElementById('color').selectedIndex].value.replace(' ', '')).getElementsByTagName('img').length > 1) {
		getColorPhotos(document.getElementById('color').options[document.getElementById('color').selectedIndex].value.replace(' ', ''))
	} else {
		void(0)
	};
}

function gFormVali(fList) {
	intReg = new RegExp('^(([1-9][0-9]*)|0)?$');
	decReg = new RegExp('[-]?([1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|\.[0-9]{1,2})$');
	emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	formResp = 'Please correct the following problems:\n';
	
	for (i = 0; i < fList.split(',').length; i++) {
		curField = document.getElementById(fList.split(',')[i].split('~')[0]).value;
		// required
		if (fList.split(',')[i].split('~')[1] == 'r' && curField == '') {
			formResp = formResp+'\n'+fList.split(',')[i].split('~')[2]+' is required.';
		}
		// integer
		if (fList.split(',')[i].split('~')[1] == 'i' && curField != '' && intReg.test(curField) == false) {
			formResp = formResp+'\n'+fList.split(',')[i].split('~')[2]+' must be an integer.';
		}
		// integer required
		if (fList.split(',')[i].split('~')[1] == 'ir' && (intReg.test(curField) == false || curField == '')) {
			formResp = formResp+'\n'+fList.split(',')[i].split('~')[2]+' must be an integer and is required.';
		}
		// decimal
		if (fList.split(',')[i].split('~')[1] == 'd' && curField != '' && decReg.test(curField) == false) {
			formResp = formResp+'\n'+fList.split(',')[i].split('~')[2]+' may only contain numbers and decimals.';
		}
		// decimal required
		if (fList.split(',')[i].split('~')[1] == 'dr' && (decReg.test(curField) == false || curField == '')) {
			formResp = formResp+'\n'+fList.split(',')[i].split('~')[2]+' may only contain numbers and decimals and is required.';
		}
		// email validate
		if (fList.split(',')[i].split('~')[1] == 'e' && curField != '' && emailReg.test(curField) == false) {
			formResp = formResp+'\n'+fList.split(',')[i].split('~')[2]+' must be a valid email address.';
		}
		// email validate required
		if (fList.split(',')[i].split('~')[1] == 'er' && (emailReg.test(curField) == false || curField == '')) {
			formResp = formResp+'\n'+fList.split(',')[i].split('~')[2]+' must be a valid email address and is required.';
		}
	}
	
	if (formResp == 'Please correct the following problems:\n') {
		return true;
	} else {
		alert(formResp);
		return false;
	}
}
