function init (e) {
	adjustSearchBox ();
}

function adjustSearchBox () {
	var oSearchBox = document.getElementById("_ctl3_keywords");

	if (window.addEventListener) {
		oSearchBox.addEventListener("focus", clearInput, false);
		oSearchBox.addEventListener("blur", setInput, false);
	} else {
		oSearchBox.attachEvent("onfocus", clearInput);
		oSearchBox.attachEvent("onblur", setInput);
	}
}

function clearInput (e) {
	var oTarget = (e.target) ? e.target : event.srcElement;
	
	if (oTarget.value == "Search") oTarget.value = "";
}

function setInput (e) {
	var oTarget = (e.target) ? e.target : event.srcElement;
	
	if (oTarget.value == "") oTarget.value = "Search";
}

function checkTax(sState, nAmount, nTotal) {
	var oDdl = document.getElementById("ddlState");
	var oLabel = document.getElementById("taxLabel");
	var nTaxAmount = nAmount * nTotal;
	
	if (oDdl.options[oDdl.selectedIndex].value == sState) {
		oLabel.innerHTML = "$" + nTaxAmount.toFixed(2) + " sales tax will be added.";
	} else {
		oLabel.innerHTML = "";	
	}
}

function disableImageClick(e) {
	var sMsg, dDate, nYear;
	var oSource;
	var aAllow = new Array("links.aspx");

	for (var n = 0; n < aAllow.length; n++) {
		if (window.location.href.indexOf(aAllow[n]) > -1) return true;
	}

	dDate = new Date();
	nYear = dDate.getFullYear();
	sMsg = "This image is copyright " + nYear;
	
	if (document.all)
		oSource = event.srcElement;
	else
		oSource = e.target;
	
	if (oSource.nodeName == "IMG") {
		alert(sMsg);
		return false;
	}
	return true;
}

function popUp(sURL) {
	var oWin, sFeatures, sHTML;
	sFeatures = "width=640, height=480, scrollbars=yes";
	
	sHTML = "<html><head><title>Product Viewer</title>";
	sHTML += "<meta http-equiv='imagetoolbar' content='no'>";
	sHTML += "<script type='text/javascript' src='include/scripts.js'></script>";
	sHTML += "</head><body style='margin:0;padding:0'>";
	sHTML += "<img src='" + sURL + "' alt='Product Image'>";
	sHTML += "</body></html>";

	oWin = window.open("", "", sFeatures);
	oWin.document.write(sHTML);
}

function openWindow(sUrl, nWidth, nHeight) {
	sFeatures = "width=" + nWidth + ", height=" + nHeight + ", scrollbars=yes";
	
	window.open(sUrl, "", sFeatures);
}

if (window.addEventListener) {
	window.addEventListener("load", init, false);
	document.addEventListener("contextmenu", disableImageClick, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", init);
	document.attachEvent("oncontextmenu", disableImageClick);
}
