var pos = 0;
var offsetv = 170;
var timeout = 5000;

/*****************************
** IMAGE SCROLL UP AND DOWN **
*****************************/
function logout() {
	if (document.getElementById('logoutsession')) {
		document.getElementById('logoutsession').value = "1";
	}
}

function ScrollAuto(direc,name) {

	if(!document.getElementById) return;				
	
	// check to see if there is only one logo
	var moveText = document.getElementById(name);
	
	//	if (name  != 'logos2') {
		if(moveText.offsetHeight == 170) return;
	//	}

	//	if (name=='logos2')	{ alert(pos + '...' + moveText.offsetHeight + '-' + offsetv);	}

	if(direc == "up") {
		if (0-pos == moveText.offsetHeight-offsetv) {
			// Reach bottom, move in reverse
			window.setTimeout("Scroll('down','" + name + "');", timeout);
		} else {
			window.setTimeout("Scroll('up','" + name + "');", timeout);
		}
	}
	if(direc == "down") {
		if (pos == 0) {
			// Reach top, move forward again
			window.setTimeout("Scroll('up','" + name + "');", timeout);
		} else {
			window.setTimeout("Scroll('down','" + name + "');", timeout);
		}
	}
}

function Scroll(direc,name) {
	if(!document.getElementById) return;
	var moveText = document.getElementById(name);

	if (direc == "up") {
		pos -= 2;
		offsetv -= 2;
		moveText.style.top = pos + "px";
		if (offsetv == 0) {
			offsetv = 170;
			moveText.style.top = pos + "px";
			ScrollAuto('up', name);
			return;
		}
		window.setTimeout("Scroll('up','" + name + "');", 10);
	}
	if (direc == "down") {
		pos += 2;
		offsetv -= 2;
		moveText.style.top = pos + "px";
		if (offsetv == 0) {
			offsetv = 170;
			moveText.style.top = pos + "px";
			ScrollAuto('down', name);
			return;
		}
		window.setTimeout("Scroll('down','" + name + "');", 10);
	}
}

function InitsetFocus() { // auto select fields on load
	// home page
	if (eval(document.getElementById("eventcodemain")) && document.getElementById("eventcodemain").type == "text") {
		document.getElementById("eventcodemain").focus();
	}

	// my order
	if (eval(document.getElementById("orderNumber")) && document.getElementById("orderNumber").type == "text") {
			document.getElementById("orderNumber").focus();
	}

	// order sheet
	if (eval(document.getElementById("eCode")) && document.getElementById("eCode").type == "text") {
		document.getElementById("eCode").focus();
	}

	// info sheet
	if (eval(document.getElementById("cName")) && document.getElementById("cName").type == "text") {
		document.getElementById("cName").focus();
	}

	// product sheet
	if (eval(document.getElementById("ref1")) && document.getElementById("ref1").type == "text") {
		document.getElementById("ref1").focus();
	}

	// summary sheet
	if (eval(document.getElementById("CardName")) && document.getElementById("CardName").type == "text") {
		document.getElementById("CardName").focus();
	}

	// admin search
	if (eval(document.getElementById("cCompanyName")) && document.getElementById("cCompanyName").type == "text") {
		document.getElementById("cCompanyName").focus();
	}	
}

/**********************
** ADD PRODUCTS PAGE **
**********************/
function ClearFormClearFormAddProduct() {
	document.getElementById("pName").value = "";
	document.getElementById("pDesc").value = "";
	document.getElementById("extraDesc").value = "";
}

function FillInAddProduct() {
	var temp;
	var selected;

	selected = 0;
	temp = document.getElementsByName("ProdName");
	
	for(i=0; i < document.getElementsByName("ProdName").length; i++) {
		if (temp[i].value == "LeadRetrieval" && temp[i].checked) {
			selected = 1;
			document.getElementsByName("pType")[0].checked = true;
			document.getElementById("pName").value = "Scanner Service (Hand-Held Portable Scanner)";
			document.getElementById("pDesc").value = "<ul><li>Use of hand held barcode scanner for entire event</li><li>Customized lead menu</li><li>Daily print out of prospect data and scanned menu items</li><li>No electrical power required</li><li>Email leads sent out one business day after the show (.csv format)</li></ul>";
			document.getElementById("extraDesc").value = "** no electrical outlet required **";
			if (eval(document.getElementById("pBefore"))) { document.getElementById("pBefore").focus(); }
		} else if (temp[i].value == "SST" && temp[i].checked) {
			selected = 1;
			document.getElementsByName("pType")[1].checked = true;
			document.getElementById("pName").value = "Lead Retrieval with Printer (Hand Held)";
			document.getElementById("pDesc").value = "<ul><li>Use of hand held barcode scanner for entire event</li><li>Customized lead menu (up to 20 qualifiers)</li><li>Daily print out of prospect data and scanned menu items</li><li>No electrical power required</li><li>Instant print out of the leads scanned</li><li>Email leads sent out one business day after the show (.csv format)</li></ul>";
			document.getElementById("extraDesc").value = "** no electrical outlet required **";
			if (eval(document.getElementById("pBefore"))) { document.getElementById("pBefore").focus(); }
		} else if (temp[i].value == "T3" && temp[i].checked) {
			selected = 1;
			document.getElementsByName("pType")[2].checked = true;
			document.getElementById("pName").value = "Trakker (T3)";
			document.getElementById("pDesc").value = "<ul style='font-weight:bold;'><li>Compact, portable battery-powered scanner.</li><li>Rechargable battery, charged from exhibitors computer USB port.</li><li>Multimedia card interface for additional removable storage.</li><li>Comes with USB &amp; RS232 connections.</li><li>Optional printer is available.</li></ul>";
			document.getElementById("extraDesc").value = "";
			if (eval(document.getElementById("pBefore"))) { document.getElementById("pBefore").focus(); }
		} else if (temp[i].value == "T2000" && temp[i].checked) {
			selected = 1;
			document.getElementsByName("pType")[3].checked = true;
			document.getElementById("pName").value = "Trakker (T2000)";
			document.getElementById("pDesc").value = "<ul style='font-weight:bold;'><li>Compact, portable battery-powered scanner.</li><li>Rechargable battery, charged from exhibitors computer USB port.</li><li>Multimedia card interface for additional removable storage.</li><li>Comes with USB &amp; RS232 connections.</li><li>Optional printer is available.</li></ul>";
			document.getElementById("extraDesc").value = "";
			if (eval(document.getElementById("pBefore"))) { document.getElementById("pBefore").focus(); }
		}
	}

	if (!selected) {
		alert('Please select a value to fill in the product form');
	}
}

/********************
** OPEN ALL ORDERS **
********************/
function ChangeSelected(rowNum, which) {
	var table = document.getElementById("OrdersNum");   
	var rows = table.getElementsByTagName("tr");   

	if(which.checked) {
		rows[rowNum].className = "highlighted";
	} else {
		rows[rowNum].className = "nothighlighted";
	} 
}

function SelectAll(status, num, field) {
	var table = document.getElementById("OrdersNum");   
	var rows = table.getElementsByTagName("tr");  

	if(num == "1") {
		if (status == true) {
			val = true;
			document.getElementById('CheckAlltwo').checked = true;
		} else {
			document.getElementById('CheckAlltwo').checked = false;
			val = false;
		}
	} else {
		if (status == true) {
			val = true;
			document.getElementById('CheckAllone').checked = true;
		} else {
			document.getElementById('CheckAllone').checked = false;
			val = false;
		}
	}

	for(i = 0; i < field.length; i++) {
		field[i].checked = val;
		if (val == true) {
			rows[i+2].className = "highlighted";
		} else {
			rows[i+2].className = "nothighlighted";
		}
	}
}

/*******************
** SIGN UP FIELDS **
*******************/
function cleanfield(val) { // clean up fields
	val = val.replace(/</g, "");
	val = val.replace(/>/g, "");
	val = val.replace(/\'/g, "");
	val = val.replace(/\"/g, "");
	val = val.replace(/\)/g, "");
	val = val.replace(/\(/g, "");

	return (val);
}

function SubmitForm(val){ // Submit form
	// set the value of the button clicked
	if (document.getElementById("SubmitButton")) {
		document.getElementById("SubmitButton").value = val;
		document.myForm.submit();
	}
}

function SubmitForm_Prefill(val){ // Submit form
	// set the value of the button clicked
	if (document.getElementById("prefillSubmit")) {
		document.getElementById("prefillSubmit").value = val;
		document.eventSpecial_Prefill.submit();
	}
}

// Signup Summary page
function PolicyChecked() { // only submit the form if the policy has been checked off
	if (document.getElementById('Agreed')) {
		if (document.getElementById('Agreed').checked) {
			return (true);
		} else {
			alert('Please agree with the policy above before continuing');
			return (false);
		}
	}
}

function numbersOnly(val, name) {
	temp = "";
	// creates a new string consiting of numbers only, that way all other characters are removed
	for (i = 0; i < val.length; i++) {
		if (val.charAt(i) >= 0 && val.charAt(i) <= 9) {
			temp += val.charAt(i);
		}
	}

	document.getElementById(name).value = removeAllSpaces(temp);
}

function trim(theForm) {
	return theForm.replace(/^\s+|\s+$/, '');
}

function removeAllSpaces(theForm) {
	return theForm.replace(/\s/gi, '');
}
