//GLOBAL VARIABLES
var menuTimer;
var map = null;
var geocoder = null;
var urlAddress = "";
var xmlHttp;
var cssResponseID;
var displayType = "block";
var ss;
var arrPOBoxRE = new Array();
	arrPOBoxRE[0] = /<%=Application("POBoxExpressions")(0)%>/i;
	arrPOBoxRE[1] = /<%=Application("POBoxExpressions")(1)%>/i;
	arrPOBoxRE[2] = /<%=Application("POBoxExpressions")(2)%>/i;
	arrPOBoxRE[3] = /<%=Application("POBoxExpressions")(3)%>/i;
	arrPOBoxRE[4] = /<%=Application("POBoxExpressions")(4)%>/i;
	arrPOBoxRE[5] = /<%=Application("POBoxExpressions")(5)%>/i;
	arrPOBoxRE[6] = /<%=Application("POBoxExpressions")(6)%>/i;
	arrPOBoxRE[7] = /<%=Application("POBoxExpressions")(7)%>/i;
var arrProduct = new Array();
//JSCRIPT CLASS (sort of - no methods)
function theProduct(prodName, prodDesc, imgURL) {
	arrProduct[0] = prodName;
	arrProduct[1] = prodDesc;
	arrProduct[2] = imgURL;
	}
//Add Any site wide onload events to this function:
var arrHideSelects = new Array();
var slideTimer;
var tapeTimer;
var tapeReset;
var strOldHTML = ""; //this is a holder for menus that change after the item is clicked.
				//It keeps the old HTML so that when the menu
				//when the menu is destroyed, it can successfuly be reopened again
function loader() {
	if ($("smallMap")) {
		initialize();
		showAddress(urlAddress);
		}
	if (document.location.protocol == "https:") {
		$$("a").each(function(el) {
			el.href = el.href.replace("https:", "http:");
			});
		}
	window.addEvent("load", function () {
		$$("#co-brand div img").each(function(el){
			scaleImage(el, 258, 50);
			});
		});
	}

function couponMenu(parentID, strVisibility, e) {
	var cpnmen = $("cpnMenu");
	var curVis = cpnmen.style.visibility;
	if (curVis != strVisibility) cpnmen.style.visibility = strVisibility;
	else e = new Event(e).stopPropagation();
	}

function subCatMenu(parentID, strVisibility) {
	var submen = $(parentID).childNodes[2];
	if (submen) {
		var curVis = submen.style.visibility;
		if (curVis != strVisibility) {
			submen.lastChild.style.borderBottom = "none";
			submen.style.visibility = strVisibility;
			}
		else e = new Event(window.event).stopPropagation();
		}
	}

function fixBrokenImage(objImage, strType, maxWidth, maxHeight) {
	objImage.src = "/images/spacer.gif";
	objImage.style.height = maxHeight + "px";
	objImage.style.width = maxWidth + "px";
	if (strType == "member") objImage.style.background = "url('/images/_memberimages/nomemberimage.jpg') no-repeat center center";
	else objImage.style.background = "url('/images/product_noimage.png') no-repeat center center";
	}

function scaleImage(objImage, maxWidth, maxHeight) {
	if (objImage) {
		if (objImage.naturalWidth) {
			var imgWidth = objImage.naturalWidth;
			var imgHeight = objImage.naturalHeight;
			}
		else {
			var imgWidth = objImage.offsetWidth;
			var imgHeight = objImage.offsetHeight;
			}
		if (imgWidth > maxWidth || imgHeight > maxHeight) {
			objImage.width = maxWidth;
			objImage.height = Math.round(imgHeight * (maxWidth / imgWidth));
			if (maxHeight - objImage.height < 0) {
				objImage.height = maxHeight
				objImage.width = Math.round(imgWidth * (maxHeight / imgHeight));
				}
			if (maxHeight - objImage.height > 2) objImage.vspace = objImage.vspace + Math.round((maxHeight - objImage.height) / 2);
			if (maxWidth - objImage.width > 2) objImage.hspace = objImage.hspace + Math.round((maxWidth - objImage.width) / 2);
			}
		}
	}

function fixRedX() {
	var arrImgs = $$("img");
	for (i = 0; i < arrImgs.length; i++) {
		if (arrImgs[i].parentNode.parentNode.className != "gmnoprint") {
			if (arrImgs[i].complete == false) {
				if (arrImgs[i].width != "" && arrImgs[i].height != "") {
					arrImgs[i].style.width = arrImgs[i].width + "px";
					arrImgs[i].style.height = arrImgs[i].height + "px";
					arrImgs[i].style.background = "url('/images/product_noimage.png') center center no-repeat";
					arrImgs[i].src = "/images/spacer.gif";
					}
				else arrImgs[i].src = "/images/product_noimage.png";
				}
			else {
				if (arrImgs[i].offsetWidth > 100 && arrImgs[i].className == "prodImage") { arrImgs[i].style.width = 100; }
				}
			}
		}
	}
function moveLeft() {
	currLeft = parseInt($("tape").style.left, 10);
	if (currLeft < tapeReset) currLeft = 240;
	$("tape").style.left = (currLeft - 3) + "px";
	}
function fixShadow(imgID, parentID) {
	parentHeight = $(parentID).offsetHeight;
	imageHeight = $(imgID).offsetHeight;
	$(imgID).style.top = (parentHeight - imageHeight) + "px";
	}
function formatNumber(num, dec, thou, pnt, curr1, curr2, n1, n2) {
	var x = Math.round(num * Math.pow(10, dec));
	if (x >= 0) n1 = n2 = "";
	var y = ("" + Math.abs(x)).split("");
	var z = y.length - dec;
	if (z < 0) z--;
	for (var i = z; i < 0; i++) y.unshift("0");
	y.splice(z, 0, pnt);
	if (y[0] == pnt) y.unshift("0");
	while (z > 3) {
		z -= 3;
		y.splice(z, 0, thou);
		}
	var r = curr1 + n1 + y.join('') + n2 + curr2;
	return r;
	}
function stateChanged() { 
	if (xmlHttp.readyState) {
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
			$(cssResponseID).innerHTML = xmlHttp.responseText;
			$(cssResponseID).style.display = displayType;
			xmlHttp = null;
			}
		}
	}
function getXmlHttpObject(handler) { 
	var objXMLHttp = null;
	try { objXMLHttp = new XMLHttpRequest() }
	catch(e) { objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP") }
	return objXMLHttp;
	}
function recordTraffic(lngVendorID, lngLocalLocationID, lngPromotionID, lngSiteLocation, lngTrafficType) {
	qstring = "site=" + window.location.hostname;
	qstring += "&pg=" + window.location.pathname + window.location.search;
	qstring += "&vid=" + lngVendorID;
	qstring += "&pid=" + lngPromotionID;
	qstring += "&siteloc=" + lngSiteLocation;
	qstring += "&traffic=" + lngTrafficType;
	var xmlHttp = getXmlHttpObject();
	xmlHttp.open("GET", "/_scripts/insertTraffic.asp?" + qstring, true);
	xmlHttp.send(null);
	xmlHttp = null;
	}
function initialize() {
	if (GBrowserIsCompatible() && $("smallMap")) {
		map = new GMap2($("smallMap"));
		map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		geocoder = new GClientGeocoder();
		}
	}
function showAddress(address) {
	if (geocoder) {
		geocoder.getLatLng(address, function(point) {
			if (!point) alert(address + " not found");
			else {
				map.setCenter(point, 13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(address);
				}
			});
		}
	}
function GetCookie(name){return Cookie.read(name);}
function SetCookie(name, value, noexpire) {
	if (name == "ak" || name == "as11" || name == "as12" || name == "as13" || name == "as21" || name == "as22" || name == "as23" || name == "as24" || name == "as25" || name == "as26" || name == "31" || name == "s4z" || name == "sbar" || name == "sponsor") noexpire = 1;
	if (noexpire == 1) intDuration = 770;
	else if (noexpire != null) {
		nowDate = new Date();
		expDate = new Date(noexpire);
		intDuration = Math.abs(Math.round((expDate - nowDate) / 86400000));
		}
	else intDuration = 0;
	if (window.location.protocol = "https:") blnSecure = true;
	else blnSecure = false;
	Cookie.write(name, value, {
		domain: window.location.hostname,
		path: "/",
		duration: intDuration,
		secure: blnSecure
		});
	}
function DeleteCookie(name){Cookie.remove(name);}
function cleanString(strIn) {
	if (strIn == null) outString = "";
	else {
		outString = strIn.clean();
		outString = outString.replace("@@", "@");
		outString = outString.replace("&&", "&");
		outString = outString.replace("--", "-");
		outString = outString.replace("..", ".");
		outString = outString.replace(/cast\(/i, "");
		outString = outString.replace(/ declare /i, "");
		outString = outString.replace(/ exec /i, "");
		outString = outString.replace(/xp_/i, "");
		outString = outString.replace(/WAITFOR/i, "");
		outString = outString.replace(/SP_PASSWORD/i, "");
		outString = outString.replace("=", "");
		outString = outString.replace("[", "");
		outString = outString.replace("]", "");
		outString = outString.replace("{", "");
		outString = outString.replace("}", "");
		outString = outString.replace("|", "");
		outString = outString.replace("(", "");
		outString = outString.replace(")", "");
		outString = outString.replace("%", "");
		outString = outString.replace("$", "");
		outString = outString.replace("~", "");
		outString = outString.replace("+", "");
		outString = outString.replace("\"", "");
		outString = outString.replace("/", "");
		outString = outString.replace("?", "");
		outString = outString.replace("<", "");
		outString = outString.replace(">", "");
		outString = outString.replace("*", "");
		outString = outString.replace("#", "");
		outString = outString.replace("^", "");
		}
	return outString;
	}
function centerElement(elemID) {
	h = window.getSize().y;
	y = window.getScroll().y;
	var elem = $(elemID).getSize();
	$(elemID).setStyles({'top' : (h / 2) + y - (elem.y / 2), 'left' : (950 - elem.x) / 2});
	}
function restoreElement(boxID, elemID) {
	var elem = $(elemID);
	if (strOldHTML != "") {
		elem.innerHTML = strOldHTML;
		strOldHTML = "";
		}
	else {
		var box = $(boxID);
		elem.innerHTML = box.innerHTML;
		}
	if (arrHideSelects.length > 0 && navigator.appVersion.indexOf("MSIE 6") > -1) { for (sel = 0; sel < arrHideSelects.length; sel++) { arrHideSelects[sel].style.visibility = 'visible'; } }
	}
function destroyElement(elemID) {
	if ($(elemID)) {
		var elem = $(elemID);
		var par = elem.parentNode;
		par.removeChild(elem);
		}
	if (arrHideSelects.length > 0 && navigator.appVersion.indexOf("MSIE 6") > -1) { for (sel = 0; sel < arrHideSelects.length; sel++) { arrHideSelects[sel].style.visibility = 'visible'; } }
	}
function fitDisplayBox() {
	objDisplayBox = $("newBox");
	if (objDisplayBox.offsetWidth > parseInt(objDisplayBox.style.width)) objDisplayBox.style.width = objDisplayBox.offsetWidth + "px";
	if (objDisplayBox.offsetHeight > parseInt(objDisplayBox.style.height)) objDisplayBox.style.height = objDisplayBox.offsetHeight + "px";
	centerElement("newBox");
	}
function displayBox(strPage, intWidth, intHeight, bClose) {
	var strResponse = "";
	if ($("newBox")) {
		var nb = $("newBox");
		if (typeof(strPage) != "object") restoreElement("newBox", nb.className);
		if ($("closeButton")) destroyElement("closeButton");
		destroyElement("newBox");
		}
	if (typeof(strPage) == "object") {
		elemID = strPage.name;
		strResponse = strPage.HTML;
		bExternal = true;
		}
	else if (strPage.charAt(0) == "#") {
		//pull content from specified page element
		elemID = strPage.replace("#", "");
		sourceElement = $(elemID);
		strResponse = sourceElement.innerHTML.trim();
		sourceElement.innerHTML = "";
		bExternal = false;
		}
	else {
		//grab content from specified page
		elemID = "";
		if (window.location.protocol == "https:") strPage = "https://" + window.location.hostname + strPage;
		var xmlHttp = getXmlHttpObject();
		xmlHttp.open("GET", strPage, false);
		xmlHttp.send(null);
		strResponse = xmlHttp.responseText;
		bExternal = true;
		}
	var box = new Element("div", {"id":"newBox","class":elemID,"styles":{"width":intWidth,"height":intHeight}});
	box.set('html', strResponse);
	$$("body").adopt(box);
	var blnCenter = false;
	if (bClose == null) {
		box.addEvent("mouseleave", function() {
			if (bExternal) menuTimer = setTimeout("destroyElement('" + box.id + "')", 50);
			else menuTimer = setTimeout("restoreElement('" + box.id + "', '" + box.className + "'); destroyElement('" + box.id + "')", 50);
			});
		}
	else {
		blnCenter = true;
		var cls = new Element("img", {"id":"clsButton", "name":elemID, "src":"/images/spacer.gif", "styles":{"position":"absolute", "z-index":101}})
		if (bClose == true) { cls.addClass("icon_close").setStyles({width:20,height:20}); }
		else { cls.addClass("icon_restore").setStyles({width:21,height:21}); }
		if (bExternal) cls.setStyles({top:21,right:21});
		else cls.setStyles({top:5,right:5});
		if (bExternal) {
			if (cls.outerHTML) box.set('html', cls.outerHTML + box.innerHTML);
			else cls.inject(box, 'bottom');
			var cls = $("clsButton");
			cls.addEvent("click", function(){
				this.dispose();
				$("newBox").dispose();
				});
			}
		else {
			cls.addEvent("click", function(){
				this.dispose();
				restoreElement("newBox", this.name);
				$("newBox").dispose();
				});
			cls.inject(box, 'bottom');
			}
		}
	if (blnCenter) centerElement("newBox");
//	if (sIFR) {
//		switch (ft) {
//			case "GillSans":sIFR.replace(GillSans,{selector:'#newBox h3',wmode:'transparent',css:['.sIFR-root{display:inline}']});break;
//			case "Square":sIFR.replace(Square,{selector:'#newBox h3',wmode:'transparent',css:['.sIFR-root{display:inline}']});break;
//			case "Futura":sIFR.replace(Futura,{selector:'#newBox h3',wmode:'transparent',css:['.sIFR-root{display:inline}']});break;
//			case "BankGothic":sIFR.replace(BankGothic,{selector:'#newBox h3',wmode:'transparent',css:['.sIFR-root{display:inline}']});break;
//			}				
//		}
	}
function popup(file, w, h) {
	if (!file) return;
	if (!w) w = 480;
	if (!h) h = 440;
	var t = (screen.height - h) / 2;
	var l = (screen.width - w) / 2;
	var options = "width=" + w + ",height=" + h + ",location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,hotkeys=0,screenx=" + l + ",screeny=" + t + ",left=" + l + ",top=" + t;
	var qm = file.indexOf("?");
	(qm == -1) ? qm = "?" : qm = "&";
	file = file + qm + "popup=true&pop=1";
	window.open(file, "greenbackstreet", options);
	}
function sendToMenu(strType, clickedOn) {
	var clickSource = $(clickedOn).getCoordinates();
	var intLeft = clickSource.left;
	var intTop = clickSource.top;
	var intHeight = clickSource.height;
	switch (strType) {
		case "store":
			storeID = clickedOn.replace("sendStoreTo", "");
			displayBox("#storeSendMenu", 270, 180, true);
			var newBox = $("newBox");
			break;
		case "broken":
			storeID = clickedOn.replace("sendStoreBroken", "");
			displayBox("#storeSendBrokenLinkMenu", 350, 180, true);
			var newBox = $("newBox");
			break;
		case "product":
			displayBox("#prodSendMenu", 270, 180, true);
			var newBox = $("newBox");
			strOldHTML = newBox.innerHTML;
			break;
		}
	newBox.style.height = newBox.scrollHeight + "px";
	centerElement("newBox");
	}
function addToMenu(strType, clickedOn) {
	var clickSource = $(clickedOn).getCoordinates();
	var intLeft = clickSource.left;
	var intTop = clickSource.top;
	var intHeight = clickSource.height;
	switch (strType) {
		case "fav":
			arrData = clickedOn.split("|");
			if (arrData[1] == "") {
				displayBox("#storeAddFavMenu", 150, 85, true);
				centerElement("newBox");
				}
			else {
				displayBox("#divAddFavConfirmation", 300, 100, null);
				centerElement("newBox");
				addFavorites(arrData[0]);
				}
			break;
		case "wm":
			storeID = clickedOn.replace("addStoreTo", "");
			displayBox("#storeAddWMMenu", 165, 110, null);
			var newBox = $("newBox");
			newBox.style.top = (intTop + intHeight) + "px";
			newBox.style.left = (intLeft + 25) + "px";
			$$("#newBox span.existingWM").each(function(sp){;
				sp.addEvent("click", function() {
					strOldHTML = this.parentNode.innerHTML;
					addToWikiMall(this.id, "store", storeID);
					});
				});
			var addToNew = $("storeAddToNewWikiMall2");
			if (addToNew != null) addToNew.href += "?store=" + storeID;
			break;
		case "store":
			storeID = clickedOn.replace("addStoreTo", "");
			displayBox("#storeAddMenu", 165, 110, null);
			var newBox = $("newBox");
			newBox.setStyles({'top':intTop + intHeight,'left':intLeft + 25});
			newBox.getFirst().addEvent("click", function() { strOldHTML = this.parentNode.innerHTML;addFavorites(storeID);});
			$$("#newBox span.existingWM").each(function(sp){;
				sp.addEvent("click", function() {
					strOldHTML = this.parentNode.innerHTML;
					addToWikiMall(this.id, "store", storeID);
					});
				});
			var addToNew = $("storeAddToNewWikiMall");
			if (addToNew != null) addToNew.href += "?store=" + storeID;
			break;
		case "product":
			//update product add to menu in case they just made one on this same page
			xmlHttp = getXmlHttpObject();
			xmlHttp.open("GET", strBase + "_scripts/buildAddToMenu.asp", false);
			xmlHttp.send(null);
			$("prodAddMenu").innerHTML = xmlHttp.responseText;
			displayBox("#prodAddMenu", 180, 150, null);
			var newBox = $("newBox");
			strOldHTML = newBox.innerHTML;
			newBox.style.top = (intTop + intHeight) + "px";
			newBox.style.left = (intLeft + 25) + "px";
			break;
		}
	if (newBox) newBox.setStyles({'height':newBox.getScrollSize().y,'width':newBox.getScrollSize().x});
	}
function addToWishList(wlid) {
	xmlHttp = getXmlHttpObject();
	displayType = "inline";
	cssResponseID = "newBox";
	xmlHttp.onreadystatechange = stateChanged;
	if (wlid == "new") {
		xmlHttp.open("POST", "/_scripts/addWL.asp", true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send("action=add&wlname=" + escape($("wlName").value) + "&prod=" + escape(arrProduct.join('|')));
		}
	else {
		xmlHttp.open("POST", "/_scripts/addWLitem.asp", true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send("action=add&wlid=" + wlid + "&prod=" + escape(arrProduct.join('|')));
		}
	}
function addToWikiMall(wmid, strType, obj) {
	xmlHttp = getXmlHttpObject();
	var d = new Date();
	displayType = "inline";
	cssResponseID = "newBox";
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
			if (!isNaN(xmlHttp.responseText)) $("newBox").innerHTML = "Added to wikiMALL&trade;.";
			else $("newBox").innerHTML = "Error adding to wikiMALL&trade;." + "<br>" + xmlHttp.responseText;
			}
		}
	if (strType == "store") {
		xmlHttp.open("POST", strBase + "_scripts/addWMstore.asp", true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send("action=add&wmid=" + wmid.replace("wmid", "") + "&store=" + obj + "&" + d.getTime());
		}
	else {
		xmlHttp.open("POST", strBase + "_scripts/addWMitem.asp", true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send("action=add&wmid=" + wmid + "&prod=" + escape(obj.join('|')) + "&" + d.getTime());
		}
	}
function addFavorites(id) {
	xmlHttp = getXmlHttpObject();
	displayType = "inline";
	cssResponseID = "newBox";
	if (lngLocationID == null) lngLocationID = 0;
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("POST", strBase + "_scripts/myfavorites.asp", true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("action=add&vid=" + id + "&loc=" + lngLocationID + "&" + Math.random());
	}
function focusParentWindow() {var parentWindow = window.opener;parentWindow.focus();}
function checkZip(strField, strZip) {if (strZip != stripper(strZip)) $(strField).value = stripper(strZip);}
function checkPhone(strField, strPhone) {if (strPhone != formatPhone(strPhone)) $(strField).value = formatPhone(strPhone);}
function checkSSN(strField, strSSN) {if (strSSN != formatSSN(strSSN)) $(strField).value = formatSSN(strSSN);}
function checkEIN(strField, strEIN) {if (strEIN != formatEIN(strEIN)) $(strField).value = formatEIN(strEIN);}
function formatPhone(strNum) {
	strNum = stripper(strNum);
	arrNums = strNum.split("");
	strResult = "";
	for (i = 0; i < arrNums.length; i++) {
		if (i == 0) strResult += "(";
		if (i == 3) strResult += ") ";
		if (i == 6) strResult += "-";
		strResult += arrNums[i];
		}
	return strResult.toString().substr(0, 14);
	}
function formatSSN(strSSN) {
	ssnStr = stripper(strSSN);
	arrNums = ssnStr.split("");
	ssnResult = "";
	for (i = 0; i < arrNums.length; i++) {
		if (i == 3 || i == 5) ssnResult += "-";
		ssnResult += arrNums[i];
		}
	return ssnResult.toString();
	}
function formatEIN(strEIN) {
	var retVal = "";
	strEIN = stripper(strEIN);
	switch (strEIN.length) {
		case 2:
			retVal = strEIN + "-";
			break;
		case 9:
			retVal = strEIN.substr(0, 2) + "-" + strEIN.substr(2);
			break;
		default:
			retVal = strEIN;
			break;
		}
	return retVal;
	}
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,"");
	if (isNaN(num)) num = "0";
	cents = Math.floor((num * 100 + 0.5) % 100);
	num = Math.floor((num * 100 + 0.5) / 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 ("$" + num + "." + cents);
	}
function stripper(num) {
	str = num.toString();
	str = str.split("");
	res = "";
	for (i = 0; i < str.length; i++) {
		str[i] = parseInt(str[i]);
		if (isNaN(str[i])) str[i] = "";
		res = res + "" + str[i];
		}
	return res;
	}
function domainStripper(charString) {
	var validString = "_-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var charArray = charString.split("");
	var strResult = "";
	for (i = 0; i < charArray.length; i++) if (validString.indexOf(charArray[i]) > -1) strResult += charArray[i];
	strResult = strResult.replace("--", "-");
	return strResult;
	}