var mouseX, mouseY;

function getMousePos(e) {
if (!e) {
var e = window.event||window.Event;
}
if('undefined'!=typeof e.pageX) {
	mouseX = e.pageX;
	mouseY = e.pageY;
}else{
	mouseX = e.clientX + document.body.scrollLeft;
	mouseY = e.clientY + document.body.scrollTop;
}
	var NAMEDIV = document.getElementById("TownName");
	NAMEDIV.style.top = mouseY;
	NAMEDIV.style.left = mouseX + 10;
}

if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE);

	document.onmousemove = getMousePos;
	
function ClearME() {
	var EMAIL = document.form1.Email.value;
	if (EMAIL == "Enter Email Here") {
		document.form1.Email.value = "";
	}
}
function NAVON(ME) {
	ME.style.cursor = 'pointer';
	ME.className = 'NAVTextON';
}
function NAVOFF(ME) {
	ME.className = 'NAVTextOFF';
}
/*function MoveDiv() {
	//alert("HELLO" + ME_X);
	ME_X = event.clientX + 10;
	ME_Y = event.clientY;
	var NAMEDIV = document.getElementById("TownName");
	NAMEDIV.style.top = ME_Y;
	NAMEDIV.style.left = ME_X;
}*/
function ShowTown(ME) {
	MEALT = ME.alt;
	//alert(MEALT + " " + ME_X + " " + ME_Y);
	var NAMEDIV = document.getElementById("TownName");
	NAMEDIV.innerHTML = MEALT;
	NAMEDIV.style.visibility = "visible";
	NAMEDIV.style.paddingLeft = "4";
	NAMEDIV.style.paddingRight = "4";
}
function HideTown(ME) {
	var NAMEDIV = document.getElementById("TownName");
	NAMEDIV.innerHTML = "";
	NAMEDIV.style.visibility = "hidden";
	NAMEDIV.style.paddingLeft = "";
	NAMEDIV.style.paddingRight = "";
}
function ValidateEmail(FORM) {
	ME = document[FORM].Email.value;
	Length = ME.length;
	AtPOS = ME.indexOf("@");
	DotPOS = ME.lastIndexOf(".");
	DotPOSP = DotPOS + 1; 
	CHARAD = Length - DotPOSP;
	if (CHARAD == 2 || CHARAD == 3) {
		CHARAD_TF = true;
	}else{
		CHARAD_TF = false;
	}
	//alert(Length + " " + DotPOS + " " + AtPOS + " " + CHARAD_TF);
	if (AtPOS == -1 || DotPOS == -1 || CHARAD_TF == false) {
		alert("Please Enter A Valid Email.");
		return false;
	}
}
function ValidateEmailSEC(FORM) {
	ME = document[FORM].Email.value;
	Length = ME.length;
	AtPOS = ME.indexOf("@");
	DotPOS = ME.lastIndexOf(".");
	DotPOSP = DotPOS + 1; 
	CHARAD = Length - DotPOSP;
	if (CHARAD == 2 || CHARAD == 3) {
		CHARAD_TF = true;
	}else{
		CHARAD_TF = false;
	}
	//alert(Length + " " + DotPOS + " " + AtPOS + " " + CHARAD_TF);
	if (AtPOS == -1 || DotPOS == -1 || CHARAD_TF == false) {
		//alert("Please Enter A Valid Email.");
		return false;
	}
}
function ValidateForm(FORM) {
	Validated = true;
	Email = ValidateEmailSEC(FORM);
	FIRST = document.getElementById('First');
	LAST = document.getElementById('Last');
	EMAIL = document.getElementById('Email');
	if (document[FORM].FirstName.value == "") {
		FIRST.className = "ShowRequired";
		Validated = false;
	}else{
		FIRST.className = "";
	}
	if (document[FORM].LastName.value == "") {
		LAST.className = "ShowRequired";
		Validated = false;
	}else{
		LAST.className = "";
	}
	if (document[FORM].LastName.value == "") {
		EMAIL.className = "ShowRequired";
		Validated = false;
	}else{
		EMAIL.className = "";
	}
	if (Validated == false) {
		alert("Please Fill out Required Fields.");
		return false;
	}else if (Email == false) {
		alert("Please Enter A Valid Email.");
		return false;
	}
}
function SendME(ME) {
	window.location.href = ME;
}
function DeleteME(URL) {
	if (confirm("Are you sure you want to delete?")) {
		window.location.href = URL;
	}		
}
function CandidateON(ME)  {
	ME.style.cursor = "pointer";
	ME.className = "CandidateBOXON";
}
function CandidateOFF(ME) {
	ME.style.cursor = "pointer";
	ME.className = "CandidateBOXOFF";
}
function SendSelect(ME) {
	//alert(ME);
	LINK = document.formC[ME].value;
	window.location.href = LINK;
	
}
function SendSelf() {
	MYURL = document.URL;
	LASTSL = MYURL.lastIndexOf("/") + 1;
	NEWURL = MYURL.slice(LASTSL);
	//alert(NEWURL);
	document.form1.action = NEWURL;
	document.form1.submit();
}
function TabON(ME) {
	ME.className = "AdminButtonON";
	ME.style.cursor = "pointer";
}
function TabOFF(ME) {
	ME.className = "AdminButtonOFF";
}

var Expanded = false;

function CheckTownNUM () {
	TownNUM = document.form1.TownNUM.value;
	if (TownNUM >= 1 && TownNUM <= 15) {
		//Valid Number
	}else{
		document.form1.TownNUM.focus();
		alert("Please enter a number 1 - 15.");
	}

}

function Expand(ME) {
	TownNUM = parseInt(document.form1.TownNUM.value);
	//alert(TownNUM);
	if (TownNUM == 1) {
		HEIGHT = "";
	}else{
		HEIGHT = TownNUM * 30;
	}
	//alert(HEIGHT);
	if (Expanded == false) {
		ME.style.height = HEIGHT;
		ME.innerHTML = "Hide Extra Towns";
		for(i=2;i<=TownNUM;i++) {
			T = document.getElementById("TownID" + i);
			T.style.visibility = "visible";
		}
		Expanded = true;
	}else{
		ME.style.height = "";
		ME.innerHTML = "Show Extra Towns";
		for(i=2;i<=TownNUM;i++) {
			T = document.getElementById("TownID" + i);
			T.style.visibility = "hidden";
		}
		Expanded = false;
	}
}
function ExpandNON(TH) {
	ME = document.getElementById(TH);
	TownNUM = parseInt(document.form1.TownNUM.value);
	//alert(TownNUM);
	if (TownNUM >= 1 && TownNUM <= 15) {
		if (TownNUM == 1) {
			HEIGHT = "";
		}else{
			HEIGHT = TownNUM * 30;
		}
		//alert(HEIGHT);
		if (Expanded == true) {
			ME.style.height = HEIGHT;
			ME.innerHTML = "Hide Extra Towns";
			for(i=2;i<=15;i++) {
				T = document.getElementById("TownID" + i);
				if (i <= TownNUM) {
					T.style.visibility = "visible";
				}else{
					T.style.visibility = "hidden";
					document.form1["TownID" + i].selectedIndex = 0;
					document.form1["OrderID" + i].value = "";
				}
			}
		}
	}
}
function TownDUP(ME) {
	//Check for town duplicates
	SEL = document.form1[ME].value;
	Matched = false;
	Matched_Town = "";
	if (ME != "TownID") {
		if (document.form1.TownID.value == SEL && SEL != "0") {
			Matched = true;
			Matched_Town = "TownID";
		}
	}
	for(i=2;i<=15;i++) {
		Town = "TownID" + i;
		T = document.form1[Town].value;
		if (SEL == T && Town != ME && SEL != "0") {
			Matched = true;
			Matched_Town = Town;
		}
	}
	//alert(Matched);
	if (Matched == true) {
		alert("That town has already been selected");
		document.form1[ME].selectedIndex = 0;
	}		
}
function CheckEnabled(ME) {
	if (document.form1[ME].value == "0") {
		alert("Please Select a town.");
		document.form1[ME].focus();
	}
}