document.onmouseover = mouseOver;
document.onmouseout = mouseOut;
document.onmousedown = buttonDown;
function mouseOver(e) {
	tmp = (is.NS5) ? e.target.getAttribute("id") : event.srcElement.id;
	if (tmp == null || tmp == "MyTable" || tmp == "" || tmp == "promoCode" || tmp.substring(0, 5) == "divoC") return;
	if (tmp.substring(0, 1) == "I") tmp = tmp.substring(1, 4);
	tmp = "row" + tmp;
	if (document.getElementById(tmp) == null) return;
	if (document.getElementById(tmp).style.backgroundColor != "#e4e4dc" && document.getElementById(tmp).style.backgroundColor != "rgb(228, 228, 220)") {
		document.getElementById(tmp).style.backgroundColor = "EEEEE0";
		document.getElementById(tmp).style.cursor = "pointer";
	}
}
function mouseOut(e) {
	tmp = (is.NS5) ? e.target.getAttribute("id") : event.srcElement.id;
	if (tmp == null || tmp == "MyTable" || tmp == "" || tmp == "promoCode" || tmp.substring(0, 5) == "divoC") return;
	if (tmp.substring(0, 1) == "I") tmp = tmp.substring(1, 4);
	tmp = "row" + tmp;
	if (document.getElementById(tmp) == null) return;
	if (document.getElementById(tmp).style.backgroundColor != "#e4e4dc" && document.getElementById(tmp).style.backgroundColor != "rgb(228, 228, 220)") {
		document.getElementById(tmp).style.backgroundColor = "FAFAF6";
	}
}
function buttonDown(e) {
	if( ((is.NS5) ? e.which : event.button) != 1) return true;
	tmp = (is.NS5) ? e.target.getAttribute("id") : event.srcElement.id;
	if(!tmp || tmp.substring(tmp.length-2) != "BA") {
		return true;
	}
	if (tmp.substring(0, 1) == "I") tmp = tmp.substring(1, 4);
	getRowValue(tmp);
}
var newWindow = "";
function showColorSchemes() {
  if (!newWindow || newWindow.closed) {
		theFile = "colorSchemes.htm";
		newWindow = window.open(theFile,"colorSchemes",'scrollbars=yes,toolbar=no,width=500,height=720,top='+(screen.height-740)/2+',left='+(screen.width-500)/2);
		if (!newWindow) {
			alert("Please enable popups to view the requested window.");
		} else {
			newWindow.opener = this.window;
			newWindow.focus();
		}
  } else {
		newWindow.focus();
  }
}
function checkField(field, name) {
	if (field.value.length == 0) {
		alert("Please enter your " + name + ".");
		field.focus();
		return false;
	} else if (field.value.indexOf("|") != -1) {
		alert("The | character is invalid. Please enter another " + name + ".");
		field.focus();
		return false;
	}
	return true;
}
function checkWebAdress() {
	if (document.selectForm.urlPrefix.value.length == 0) {
		alert("Please enter a web address.");
		document.selectForm.urlPrefix.focus();
		return;
	} else if (document.selectForm.urlPrefix.value.length < 3) {
		alert("Please enter a web address prefix longer than 3 characters.");
		document.selectForm.urlPrefix.focus();
		return;
	} else if (document.selectForm.urlPrefix.value == "www") {
		alert("www.eFitnessTracker.com is not a valid web address.");
		document.selectForm.urlPrefix.focus();
		return;
	} else if (document.selectForm.urlPrefix.value == "custom") {
		alert("custom.eFitnessTracker.com is not a valid web address. We can setup a unique url you have registered. Please also select a subdomain for your intial setup.");
		document.selectForm.urlPrefix.focus();
		return;
	}
	var checkWindow;
	theFile = "checkURL.asp?urlPrefix="+document.selectForm.urlPrefix.value;
	checkWindow = window.open(theFile,"checkURL",'scrollbars=no,toolbar=no,width=200,height=100,top='+(screen.height-100)/2+',left='+(screen.width-200)/2);
}
function setChecks() {
	if (document.selectForm.chkIncludeeFitnessTracker.checked) { document.selectForm.includeeFitnessTracker.value = "E"; } else { document.selectForm.includeeFitnessTracker.value = "N"; }
	if (document.selectForm.chkCustomWebAddress.checked) { document.selectForm.customWebAddress.value = "W"; } else { document.selectForm.customWebAddress.value = "N"; }
	if (document.selectForm.chkCustomSiteDesign.checked) { document.selectForm.customSiteDesign.value = "S"; } else { document.selectForm.customSiteDesign.value = "N"; }
	if (document.selectForm.chkCustomLogo.checked) { document.selectForm.customLogo.value = "L"; } else { document.selectForm.customLogo.value = "N"; }
	if (document.selectForm.chkFitnessCommunity.checked) { document.selectForm.fitnessCommunity.value = "F"; } else { document.selectForm.fitnessCommunity.value = "N"; }
}
function selectChk(objChk, customMessage) {
	if (objChk.checked) {
		objChk.checked = false;
	} else {
		if (customMessage) {
			if (!document.selectForm.chkCustomWebAddress.checked && !document.selectForm.chkCustomSiteDesign.checked && !document.selectForm.chkCustomLogo.checked) {
				alert("We will contact you after you have subscribed to receive any information necessary to setup your custom website.");
			}
		}
		objChk.checked = true;
	}
}
var newPPWindow = "";
function subscribe() {
	if (document.selectForm.chkCustomWebAddress.checked && document.selectForm.urlPrefix.value.length == 0) {
		document.selectForm.urlPrefix.value = document.selectForm.appName.value.replace(" ", "");
	}
	if (!checkField(document.selectForm.locationName, "Business Name") || !checkField(document.selectForm.appName, "abbreviated Business Name") || !checkField(document.selectForm.urlPrefix, "web subdomain address") || !checkField(document.selectForm.contactEmail, "Contact email")) {
		return;
	} else if (document.selectForm.urlPrefix.value.length < 3) {
		alert("Please enter a web address prefix longer than 3 characters.");
		document.selectForm.urlPrefix.focus();
		return;
	} else if (document.selectForm.urlPrefix.value == "www") {
		alert("www is not a valid web address.");
		document.selectForm.urlPrefix.focus();
		return;
	} else if (document.selectForm.urlPrefix.value == "custom") {
		alert("custom.eFitnessTracker.com is not a valid web address. We can setup a unique url you have registered if you wish.\nPlease also select a subdomain for your intial setup.");
		document.selectForm.urlPrefix.focus();
		return;
	}

	setChecks();
	var selectedSiteLayout = "C";
	if (document.selectForm.siteLayout.value == "1") {
		selectedSiteLayout = "M";
	}
	var item_number = getItemNumber();
	if (document.selectForm.fitnessCommunity.value=="F") {
		item_number = item_number + "F";
	}
	var theFile = "subscribeNow.asp?item_number="+item_number+"&contactEmail="+document.selectForm.contactEmail.value+"&promoCode="+document.selectForm.promoCode.value+"&custom="+encodeURIComponent(document.selectForm.locationName.value)+"|"+encodeURIComponent(document.selectForm.appName.value)+"|"+encodeURIComponent(document.selectForm.urlPrefix.value)+"|"+document.selectForm.colorScheme.value+"|"+document.selectForm.headerGraphic.value+"|"+document.selectForm.includeeFitnessTracker.value+"|"+document.selectForm.logoGraphic.value+"|"+document.selectForm.customWebAddress.value+"|"+document.selectForm.customSiteDesign.value+"|"+document.selectForm.customLogo.value+"|"+locationId+"|"+document.selectForm.fitnessCommunity.value+"|"+selectedSiteLayout;
	if (!newPPWindow || newPPWindow.closed) {
		newPPWindow = window.open(theFile,"PPWindow",'scrollbars=yes,toolbar=no,location=yes,width=1000,height=750,top='+(screen.height-750)/2+',left='+(screen.width-1000)/2);
		if (!newPPWindow) {
			alert("Please enable popups to view the requested window.");
		} else {
			newPPWindow.opener = this.window;
			newPPWindow.focus();
		}
	} else {
		newPPWindow.focus();
	}
}
function getItemNumber() {
	var rowNum = selectedRowCode.substring(0,1);
	return eval("item"+rowNum).value;
}
function changeScheme(option) {
	setChecks();
	this.location.href="?item_number="+getItemNumber()+"&locationName="+document.selectForm.locationName.value+"&appName="+document.selectForm.appName.value+"&urlPrefix="+document.selectForm.urlPrefix.value+"&colorScheme="+document.selectForm.colorScheme.value+"&headerGraphic="+document.selectForm.headerGraphic.value+"&includeeFitnessTracker="+document.selectForm.includeeFitnessTracker.value+"&logoGraphic="+document.selectForm.logoGraphic.value+"&promoCode="+document.selectForm.promoCode.value+"&option="+option+"&customWebAddress="+document.selectForm.customWebAddress.value+"&customSiteDesign="+document.selectForm.customSiteDesign.value+"&customLogo="+document.selectForm.customLogo.value+"siteLayout="+document.selectForm.siteLayout.value+"&fitnessCommunity="+document.selectForm.fitnessCommunity.value+"&contactEmail="+document.selectForm.contactEmail.value+"&selectedRowCode="+selectedRowCode;
}

