// Thomas Higginbotham
// Name: disableImageClick()
// Date: 7.17.5
// Desc: Displays an alert box when visitor right-clicks an image. Add exceptions to this
//       in the aAllow array.
function disableImageClick(e) {
	var sMsg, dDate, nYear;
	var oSource;
	var aAllow = new Array("favorite_links.asp");

	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 + " twiceasniceconsignmentboutique.com";
	
	if (document.all)
		oSource = event.srcElement;
	else
		oSource = e.target;
	
	if (oSource.nodeName == "IMG") {
		alert(sMsg);
		return false;
	}
	return true;
}
// Thomas Higginbotham
// Name: popUp()
// Date: 7.17.5
// Args: sURL - URL of image file to load
// Desc: Opens a full-size image into a popup window. Also disables image
//       right-click and IE image toolbar.
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='scripts.js'></script>";
	sHTML += "</head><body>";
	sHTML += "<img src='" + sURL + "' alt='Product Image'>";
	sHTML += "</body></html>";

	oWin = window.open("", "", sFeatures);
	oWin.document.write(sHTML);
}
function viewImage(sURL) {
	var oWin, sFeatures, sHTML;
	sFeatures = "width=640, height=480, scrollbars=yes, resizable=yes";
	
	sHTML = "<html><head><title>Gallery Viewer</title>";
	sHTML += "<meta http-equiv='imagetoolbar' content='no'>";
	sHTML += "<script type='text/javascript' src='scripts.js'></script>";
	sHTML += "</head><body>";
	sHTML += "<img src='" + sURL + "' alt='Gallery Image'>";
	sHTML += "</body></html>";

	oWin = window.open("", "", sFeatures);
	oWin.document.write(sHTML);
}
// Thomas Higginbotham
// Date: 7.20.5
// Name: validateProduct()
// Desc: Returns true if form contains no errors. Otherwise, an alert box notifies the 
//       visitor of the error
function validateProduct() {
	var oPLU = document.getElementById("pPLU");
	var oName = document.getElementById("pName");
	var oDesc = document.getElementById("pDesc");
	var oPrice = document.getElementById("pPrice");
	var oWholesale = document.getElementById("pWholesalePrice");
	var oStock = document.getElementById("pNumInStock");
	var oPercent = document.getElementById("pPercentOff");
	
	if (!oPLU.value) {
		alert("Please type a value for this item's PLU");
		oPLU.focus();
		return false;
	}
	if (!oName.value) {
		alert("Please type a name for this item");
		oName.focus();
		return false;
	}
	if (!oDesc.value) {
		alert("Please type a description for this item");
		oDesc.focus();
		return false;
	}
	if (!oPrice.value || isNaN(oPrice.value)) {
		alert("Please type a numeric value for this item's price");
		oPrice.select();
		return false;
	}
	if (!oWholesale.value || isNaN(oWholesale.value)) {
		alert("Please type a numeric value for the wholesale price");
		oWholesale.select();
		return false;
	}
	if (!oStock.value || isNaN(oStock.value)) {
		alert("Please type a numeric value for the inventory of this product");
		oStock.select();
		return false;
	}
	if (!oPercent.value || isNaN(oPercent.value)) {
		alert("Please type a numeric value for % Off Discount");
		oPercent.select();
		return false;
	}
	return true;
}
// Thomas Higginbotham
// Date: 8.2.5
// Name: validateMailForm()
// Desc: Returns true if form contains no errors. Otherwise, an alert box notifies the 
//       visitor of the error
function validateMailForm() {
	var oFirstName = document.getElementById("txtFirstName");
	var oLastName = document.getElementById("txtLastName");
	var oEmail = document.getElementById("txtEmail");
	
	if (!oFirstName.value) {
		alert("Let us know your name");
		oFirstName.focus();
		return false;
	}
	if (!oLastName.value) {
		alert("Let us know your name");
		oLastName.focus();
		return false;
	}
	if (oEmail.value.indexOf("@") < 0 || oEmail.value.indexOf(".") < 0) {
		alert("Please type a valid E-mail address");
		oEmail.select();
		return false;
	}
	return true;
}

document.oncontextmenu = disableImageClick;