function showpop(page, title) {
	var winName = title
	var args = "height=350,width=420,left=l0,top=10,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1";
	window.open(page, winName, args);
}
function chkform()
{
	if (document.getElementById("qty").value == "")
	{
		alert("Please enter a Quantity");
		document.getElementById("qty").value = "";
		document.getElementById("qty").focus();
		return false;
	}
	if (!IsNumeric(document.getElementById("qty").value))
	{
		alert("Please enter a Quantity");
		document.getElementById("qty").value = "";
		document.getElementById("qty").focus();
		return false;
	}
	if (document.getElementById("hidden_l1type"))
	{
		if (document.getElementById("hidden_l1type").value == "CO")
		{
			if (document.getElementById("l1type").value == "-1")
			{
				alert("Please Select a Color");
				document.getElementById("l1type").focus();
				return false;
			}
		}
	}
	if (document.getElementById("hidden_l2type"))
	{
		if (document.getElementById("hidden_l2type").value == "CO")
		{
			if (document.getElementById("l2type").value == "-1")
			{
				alert("Please Select a Color");
				document.getElementById("l2type").focus();
				return false;
			}
		}
	}
	if (document.getElementById("hidden_l1type"))
	{
		if (document.getElementById("hidden_l1type").value == "SZ")
		{
			if (document.getElementById("l1type").value == "-1" || document.getElementById("l1type").value == "")
			{
				alert("Please Select a Size");
				document.getElementById("l1type").focus();
				return false;
			}
		}
	}
	if (document.getElementById("hidden_l2type"))
	{
		if (document.getElementById("hidden_l2type").value == "SZ")
		{
			if (document.getElementById("l2type").value == "-1")
			{
				alert("Please Select a Size");
				document.getElementById("l2type").focus();
				return false;
			}
		}
	}
	if (document.getElementById("logoname").value !== '')
	{
		if (document.getElementById("logoleftside"))
		{
			if ((document.getElementById("logoleftside").checked == false) && (document.getElementById("logorightside").checked == false) && (document.getElementById("logoleftsleeve").checked == false) && (document.getElementById("logorightsleeve").checked == false))
			{
				alert("Please select a logo side");
				showemb('emb','chkembb');
				return false;
			}
		}
		if (document.getElementById("logocenterside"))
		{
			if (document.getElementById("logoleftside").checked == false)
			{
				alert("Please select a logo side");
				showemb('emb','chkembb');
				return false;
			}
		}
	}
	return true;
}
function showemb(dvName, target) {
	document.getElementById(dvName).style.display = 'block';
	var coords = ajfindPos(document.getElementById(target));
	document.getElementById(dvName).style.left = coords[0] - 370 + 'px';
	document.getElementById(dvName).style.top = coords[1] + 'px';
	document.getElementById('addtocart').disabled = true;
	document.getElementById('addtowishlist').onclick = null;
	if (document.getElementById('embt').innerHTML == "Modify Added Embroidery")
	{
		document.getElementById('noemb').innerHTML = 'Remove';
	} else {
		document.getElementById('noemb').innerHTML = 'Cancel';
	}
}
function ajfindPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
function popupWindow(o,d)
{
	var obj = document.getElementById(o);
	if (d=='s')
	{
		document.getElementById("embt").innerHTML="Modify Added Embroidery";
	} else {
		document.getElementById("lettering").value = 'None';
		document.getElementById('letteringimg').innerHTML = '';
		document.getElementById("threadcolor").value = 'None';
		document.getElementById('threadcolorimg').innerHTML = '';
		document.getElementById("logoname").value = '';
		document.getElementById('logonameimg').innerHTML = '';
		validateEMB();
		document.getElementById("embt").innerHTML="Add Embroidery";
	}
	document.getElementById('addtocart').disabled = false;
	document.getElementById('addtowishlist').onclick = addwishlist;
	obj.style.display = 'none';
}
function setClassName(objId, theclass) {
    	//document.getElementById(objId).className = theclass;
}
function setcolor(opt,c,sku,domain) {
	if (isEmpty(opt))
	{
		opt = "1"
	}
	if (opt == "1")
	{
		if (document.add2cart.option_2)
		{
			document.add2cart.option_2.options[0].selected = true;
			document.getElementById('showemb').style.display = "none";
			popupWindow('emb','c');
		}
		if (document.add2cart.option_3)
		{
			document.add2cart.option_3.options[0].selected = true;
			document.getElementById('showemb').style.display = "none";
			popupWindow('emb','c');
		}
	}
	if (opt == "2")
	{
		if (document.add2cart.option_3)
		{
			document.add2cart.option_3.options[0].selected = true;
			document.getElementById('showemb').style.display = "none";
			popupWindow('emb','c');
		}
	}
	var colorcell = "";
	var mdomain
	var k=0;
	mdomain = domain
	var docform = document.getElementById("add2cart")
	if (document.getElementById("hidden_l1type"))
	{
		var l1type = document.getElementById("hidden_l1type").value;
		if (l1type == "CO")
		{
			elem = document.getElementById("l1type");
		}
	}
	if (document.getElementById("hidden_l2type"))
	{
		var l2type = document.getElementById("hidden_l2type").value;
		if (l2type == "CO")
		{
			elem = document.getElementById("l2type");
		}
	}
	if (document.getElementById("hidden_l3type"))
	{
		var l3type = document.getElementById("hidden_l3type").value;
		if (l3type == "CO")
		{
			elem = document.getElementById("l3type");
		}
	}
	elem.value = c;
	if (c != "-1")
	{
		ajxFrmPopOptions();
	}
	if (l1type == "CO")
	{
		imagecode = document.getElementById("l1type").value;
	}
	if (l2type == "CO")
	{
		imagecode = document.getElementById("l2type").value;
	}
	if (l3type == "CO")
	{
		imagecode = document.getElementById("l3type").value;
	}
	theimage = document.getElementById("sim2");
	xmlhttp = new GetXmlHttpObject();
	xmlhttp.open('get', '/images/' + mdomain + '/products/' + sku + '_' + imagecode + '.jpg', true);
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200){
			if (theimage) theimage.src = "/images/" + mdomain + "/products/" + sku + "_" + imagecode + ".jpg";
		} else if (xmlhttp.status==404){
			if (theimage) theimage.src = "/images/" + mdomain + "/products/noimage.jpg";
		} else alert("Status is "+xmlhttp.status)
	}}
	xmlhttp.send(null);
	if (document.getElementById("zoomimage"))
	{
		document.getElementById("zoomimage").innerHTML = '';
	}
	updatesku(sku,mdomain);
}
function updatesku(sku,domain) {
	var msku;
	var mdomain
	var mopt3 = "";
	var mopt2 = "";
	var mopt1 = "";
	msku = sku;
	mdomain = domain;
	if (document.add2cart){
		if (document.add2cart.option_1){
			opt1name = document.add2cart.option_1.id
			if (document.getElementById("hidden_" + opt1name).value == "CO"){
				mopt1 = document.getElementById(opt1name).value;
			}
			if (document.getElementById("hidden_" + opt1name).value == "SZ"){
				mopt1 = document.getElementById(opt1name).value;
			}
		}
		if (document.add2cart.option_2){
			opt2name = document.add2cart.option_2.id
			if (document.getElementById("hidden_" + opt2name).value == "CO"){
				mopt2 = document.getElementById(opt2name).value;
			}
			if (document.getElementById("hidden_" + opt2name).value == "SZ"){
				mopt2 = document.getElementById(opt2name).value;
			}
		}
		if (document.add2cart.option_3){
			opt3name = document.add2cart.option_3.id
			if (document.getElementById("hidden_" + opt3name).value == "CO"){
				mopt3 = document.getElementById(opt3name).value;
			}
			if (document.getElementById("hidden_" + opt3name).value == "SZ"){
				mopt3 = document.getElementById(opt3name).value;
			}
		}
	}
	if (mopt1 == "-1" && (mopt2 == "-1" || mopt2 == "") && (mopt3 == "-1" || mopt3 == "")){
		sendparam = msku;
		if (document.getElementById('selcolorimg'))
		{
			document.getElementById('selcolorimg').innerHTML = '';
		}
	}else{
		if (mopt1 != "-1" && (mopt2 == "-1" || mopt2 == "") && (mopt3 == "-1" || mopt3 == ""))
		{
			sendparam = msku+' '+mopt1;
			if (document.getElementById('selcolorimg'))
			{
			document.getElementById('selcolorimg').innerHTML = '<img src="/images/' + mdomain + '/products/' + sku + '_' + mopt1 + '_thumb.jpg">';
			}
		}else{
			if (mopt1 != "-1" && mopt2 != "-1"  && (mopt3 == "-1" || mopt3 == ""))
			{
				sendparam = msku+' '+mopt1+' '+mopt2;
				document.getElementById("gensku").value = alltrim(sendparam);
				if (ajxFrmValidSKU() == "Y")
				{
					if (document.getElementById('selcolorimg'))
					{
					document.getElementById('selcolorimg').innerHTML = '<img src="/images/' + mdomain + '/products/' + sku + '_' + mopt1 + '_thumb.jpg">';
					}
				} else {
					sendparam = msku+' '+mopt2+' '+mopt1;
					document.getElementById("gensku").value = alltrim(sendparam);
					if (ajxFrmValidSKU() == "Y")
					{
						if (document.getElementById('selcolorimg'))
						{
						document.getElementById('selcolorimg').innerHTML = '<img src="/images/' + mdomain + '/products/' + sku + '_' + mopt1 + '_thumb.jpg">';
						}
					}
				}
			}else{
				sendparam = msku+' '+mopt1+' '+mopt2+' '+mopt3;
				document.getElementById("gensku").value = alltrim(sendparam);
				if (ajxFrmValidSKU() == "Y")
				{
					if (document.getElementById('selcolorimg'))
					{
					document.getElementById('selcolorimg').innerHTML = '<img src="/images/' + mdomain + '/products/' + sku + '_' + mopt1 + '_thumb.jpg">';
					}
				} else {
					sendparam = msku+' '+mopt2+' '+mopt1+' '+mopt3;
					document.getElementById("gensku").value = alltrim(sendparam);
					if (ajxFrmValidSKU() == "Y")
					{
						if (document.getElementById('selcolorimg'))
						{
						document.getElementById('selcolorimg').innerHTML = '<img src="/images/' + mdomain + '/products/' + sku + '_' + mopt1 + '_thumb.jpg">';
						}
					} else {
						sendparam = msku+' '+mopt2+' '+mopt3+' '+mopt1;
						document.getElementById("gensku").value = alltrim(sendparam);
						if (ajxFrmValidSKU() == "Y")
						{
							if (document.getElementById('selcolorimg'))
							{
							document.getElementById('selcolorimg').innerHTML = '<img src="/images/' + mdomain + '/products/' + sku + '_' + mopt1 + '_thumb.jpg">';
							}
						} else {
							sendparam = msku+' '+mopt3+' '+mopt1+' '+mopt1;
							document.getElementById("gensku").value = alltrim(sendparam);
							if (ajxFrmValidSKU() == "Y")
							{
								if (document.getElementById('selcolorimg'))
								{
								document.getElementById('selcolorimg').innerHTML = '<img src="/images/' + mdomain + '/products/' + sku + '_' + mopt1 + '_thumb.jpg">';
								}
							} else {
								sendparam = msku+' '+mopt1+' '+mopt3+' '+mopt2;
								document.getElementById("gensku").value = alltrim(sendparam);
								if (ajxFrmValidSKU() == "Y")
								{
									if (document.getElementById('selcolorimg'))
									{
									document.getElementById('selcolorimg').innerHTML = '<img src="/images/' + mdomain + '/products/' + sku + '_' + mopt1 + '_thumb.jpg">';
									}
								}
							}
						}
					}
				}
			}
		}
	}
	var nd = document.getElementById("gensku");
	if (nd) nd.value = alltrim(sendparam);
}
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function addwishlist()
{
	var fvalid = false;
	fvalid = chkform();
	if (fvalid !== false)
	{
		document.add2cart.action = "addwishlist.asp";
		document.add2cart.submit();
	}
}
function showthumbImage(field,domain) {
	var origcolor = document.getElementById(field).options[document.getElementById(field).selectedIndex].value;
	var color = origcolor.toLowerCase();
	color = color.replace(' ','_');
	if (color != 'none')
	{
		document.getElementById(field + 'img').innerHTML = '<img src="/images/' + domain + '/' + field + '_' + color + '.gif">';
	} else {
		document.getElementById(field + 'img').innerHTML = '';
	}
}
function showLogo(field) {
	var origsku = document.getElementById(field).options[document.getElementById(field).selectedIndex].value
	var sku = origsku.toLowerCase();
	sku = sku.replace(' ','_');
	if (sku != '')
	{
		document.getElementById(field + 'img').innerHTML = '<img src="/images/logos/' + sku + '.jpg">';
	} else {
		document.getElementById(field + 'img').innerHTML = '';
	}
}


function showMyLogo(field,custid) {
	var origsku = document.getElementById(field).options[document.getElementById(field).selectedIndex].value
	var sku = origsku.toLowerCase();
	sku = sku.replace(' ','_');
	if (sku != '')
	{
		document.getElementById(field + 'img').innerHTML = '<img width="50" height="50" src="/customerlogos/' + custid + sku + '">';
	} else {
		document.getElementById(field + 'img').innerHTML = '';
	}
}



function validateEMB() {
	var coloring = document.getElementById('threadcolor').options[document.getElementById('threadcolor').selectedIndex].value;
	var lettering = document.getElementById('lettering').options[document.getElementById('lettering').selectedIndex].value;
	var logo = document.getElementById('logoname').options[document.getElementById('logoname').selectedIndex].value;
	if (document.getElementById('mylogoname'))
	{
		var logo2 = document.getElementById('mylogoname').options[document.getElementById('mylogoname').selectedIndex].value;
		if (isEmpty(logo) == false && isEmpty(logo2) == true)
		{
			document.getElementById('mylogoname').disabled = true;
			document.getElementById('logoname').disabled = false;
		} else if (isEmpty(logo) == true && isEmpty(logo2) == false) {
			document.getElementById('logoname').disabled = true;
			document.getElementById('mylogoname').disabled = false;
		} else {
			document.getElementById('logoname').disabled = false;
			document.getElementById('mylogoname').disabled = false;
		}
	}
	var embpricing = 0;
	if (coloring != 'None' && lettering != 'None') {
		document.getElementById('line1').disabled = false;
		if (document.getElementById('embroidleftside'))
		{
			document.getElementById('embroidleftside').disabled = false;
		}
		if (document.getElementById('embroidrightside'))
		{
			document.getElementById('embroidrightside').disabled = false;
		}
		if (document.getElementById('embroidleftsleeve'))
		{
			document.getElementById('embroidleftsleeve').disabled = false;
		}
		if (document.getElementById('embroidrightsleeve'))
		{
			document.getElementById('embroidrightsleeve').disabled = false;
		}
		if (document.getElementById('embroidcenterside'))
		{
			document.getElementById('embroidcenterside').disabled = false;
		}
	} else {
		document.getElementById('line1').disabled = true;
		document.getElementById('line1').value = '';
		document.getElementById('line2').disabled = true;
		document.getElementById('line2').value = '';
		document.getElementById('line1price').style.display = 'none';
		document.getElementById('line2price').style.display = 'none';
		if (document.getElementById('embroidleftside'))
		{
			document.getElementById('embroidleftside').disabled = true;
		}
		if (document.getElementById('embroidrightside'))
		{
			document.getElementById('embroidrightside').disabled = true;
		}
		if (document.getElementById('embroidleftsleeve'))
		{
			document.getElementById('embroidleftsleeve').disabled = true;
		}
		if (document.getElementById('embroidrightsleeve'))
		{
			document.getElementById('embroidrightsleeve').disabled = true;
		}
		if (document.getElementById('embroidcenterside'))
		{
			document.getElementById('embroidcenterside').disabled = true;
		}
	}
	var line1 = document.getElementById('line1').value;
	var line2 = document.getElementById('line2').value;
	if (isEmpty(line1) == false) {
		document.getElementById('line2').disabled = false;
		document.getElementById('line1price').style.display = 'inline';
		embpricing = parseFloat(embpricing) + parseFloat(document.getElementById('line1value').value);
	} else {
		document.getElementById('line1price').style.display = 'none';
	}
	if (isEmpty(line2) == false) {
		document.getElementById('line2price').style.display = 'inline';
		embpricing = parseFloat(embpricing) + parseFloat(document.getElementById('line2value').value);
	} else {
		document.getElementById('line2price').style.display = 'none';
	}
	if (isEmpty(logo) == false || isEmpty(logo2) == false) {
		document.getElementById('logocolor').disabled = false;
		if (document.getElementById('logoleftside'))
		{
			document.getElementById('logoleftside').disabled = false;
		}
		if (document.getElementById('logorightside'))
		{
			document.getElementById('logorightside').disabled = false;
		}
		if (document.getElementById('logoleftsleeve'))
		{
			document.getElementById('logoleftsleeve').disabled = false;
		}
		if (document.getElementById('logorightsleeve'))
		{
			document.getElementById('logorightsleeve').disabled = false;
		}
		if (document.getElementById('logocenterside'))
		{
			document.getElementById('logocenterside').disabled = false;
		}
		embpricing = parseFloat(embpricing) + parseFloat(document.getElementById('logovalue').value);
	} else {
		document.getElementById('logocolor').disabled = true;
		if (document.getElementById('logoleftside'))
		{
			document.getElementById('logoleftside').disabled = true;
		}
		if (document.getElementById('logorightside'))
		{
			document.getElementById('logorightside').disabled = true;
		}
		if (document.getElementById('logoleftsleeve'))
		{
			document.getElementById('logoleftsleeve').disabled = true;
		}
		if (document.getElementById('logorightsleeve'))
		{
			document.getElementById('logorightsleeve').disabled = true;
		}
		if (document.getElementById('logocenterside'))
		{
			document.getElementById('logocenterside').disabled = true;
		}
	}
}
function logoPrice(price) {
	document.getElementById('logovalue').value = price;
	alert(document.getElementById('logovalue').value);
	validateEMB();
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
	    {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
		catch (e)
	    {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	}
	return xmlHttp;
}
function ajxFrmValidSKU()
{
	var sku = alltrim(document.getElementById("gensku").value);
	var url = "/ajaxed/product-validsku.asp?sku="+sku;
	xmlhttp3 = new GetXmlHttpObject();
	xmlhttp3.open('GET',url,false);
	xmlhttp3.send(null);
	var validSKU = xmlhttp3.responseText;
	return validSKU;
}
function ajxFrmProdPrice()
{
	var sku = alltrim(document.getElementById("gensku").value);
	var qty = document.getElementById("qty").value;
	var showmode = document.getElementById("showmode").value;
	var opt1 = document.add2cart.option_1.value;
	var opt2 = "";
	if (document.add2cart.option_2)
	{
		opt2 = document.add2cart.option_2.value;
	}
	var opt3 = "";
	if (document.add2cart.option_3)
	{
		opt3 = document.add2cart.option_3.value;
	}
	var url = "/ajaxed/product-showprice.asp?sku="+sku+"&qty="+qty+"&showmode="+showmode;
	if (opt1 != "-1" && opt2 != "-1" && opt3 != "-1")
	{
		xmlhttp = new GetXmlHttpObject();
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange=function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				optionArray = eval(xmlhttp.responseText);
				document.getElementById('PriceDisplay').innerHTML = optionArray[0];
				var emboption = alltrim(optionArray[1]);
				if (Mid(emboption,1,1) != "X")
				{
					document.getElementById('showemb').style.display = "block";
				} else {
					document.getElementById('showemb').style.display = "none";
					popupWindow('emb','c');
				}
			}
		}
		xmlhttp.send(null);
	} else {
		document.getElementById('PriceDisplay').innerHTML = '';
	}
}
function ajxFrmPopOptions()
{
	var sku = alltrim(document.add2cart.itemno.value);
	var opt1 = document.add2cart.option_1.value;
	var opt2 = "";
	var type2 = "";
	var opt3 = "";
	var type3 = "";
	var defoption = "";
	var defoption2 = "";
	if (document.add2cart.option_2)
	{
		opt2 = document.add2cart.option_2.value;
		defoption = document.add2cart.option_2.options[0].text
		var type2 = document.add2cart.option_2.id;
	}
	if (document.add2cart.option_3)
	{
		opt3 = document.add2cart.option_3.value;
		defoption2 = document.add2cart.option_3.options[0].text
		var type3 = document.add2cart.option_3.id;
	}
	var showmode = document.getElementById("showmode").value;
	var url = "/ajaxed/product-showoptions.asp?sku="+sku+"&opt1="+opt1+"&opt2="+opt2+"&showmode="+showmode+"&type2="+type2+"&type3="+type3;
	var optionArray = "";
	if (opt1 != "-1" && (document.add2cart.option_2))
	{
		xmlhttp2 = new GetXmlHttpObject();
		xmlhttp2.open('GET',url,true);
		xmlhttp2.onreadystatechange=function() {
			if(xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
				if (document.add2cart.option_2.length == 1 || opt2 == "-1")
				{
					ClearOptions(document.add2cart.option_2);
					var ID = document.add2cart.option_2.id;
					optionArray = eval(xmlhttp2.responseText);
					if (optionArray.length > 0)
					{
						AddToOptionList(document.add2cart.option_2, "-1", defoption);
						for (var i=0; i<optionArray.length; i++) {
							AddToOptionList(document.add2cart.option_2, optionArray[i][0], optionArray[i][1]);
						}
					}
					document.add2cart.option_2.options[0].selected = true;
				}
				if (document.add2cart.option_3)
				{
					if (document.add2cart.option_2.length > 1 && document.add2cart.option_2.value != "-1" && document.add2cart.option_3.length == 1)
					{
						ClearOptions(document.add2cart.option_3);
						var ID = document.add2cart.option_3.id
						optionArray = eval(xmlhttp2.responseText);
						if (optionArray.length > 0)
						{
							AddToOptionList(document.add2cart.option_3, "-1", defoption2);
							for (var i=0; i<optionArray.length; i++) {
								AddToOptionList(document.add2cart.option_3, optionArray[i][0], optionArray[i][1]);
							}
						}
						document.add2cart.option_3.options[0].selected = true;
					}
				}
			}
		}
		xmlhttp2.send(null);
	}
}
function AddToOptionList(OptionList, OptionValue, OptionText) {
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}
function ClearOptions(OptionList) {
   for (x = OptionList.length; x >= 0; x = x - 1) {
      OptionList[x] = null;
   }
}
function Mid(str, start, len)
{
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}
