// JavaScript Document

	// State() if user select other state than 'indiana' then display hire cities fields
	function State(value)
	{
		var stateName = value;
		if (stateName != "Indiana")
			window.document.all["Tabstate"].style.display = "";
		else {window.document.all["Tabstate"].style.display = "none";}
		return;
	}
	
	//electricity() if vcr or dvd is yes, change elec to yes
	function electricity(p_select)
	{	
		var the_select = p_select;
		var the_index = the_select.selectedIndex;
		var the_selected = the_select.options[the_index].text;
		if (the_selected == "1")
			window.document.eventinfo.electric.selectedIndex = 1;
		else if (the_selected == "2")
			window.document.eventinfo.electric.selectedIndex = 1;
		return;
	}
		
	//Interview() disable or not the other checkboxes
	function Interview()
	{	
		if (document.eventinfo.day1.checked)
			document.eventinfo.day1.checked = false;
		if (document.eventinfo.day2.checked)
			document.eventinfo.day2.checked = false;
		if (document.eventinfo.none.checked)
		{
			window.document.eventinfo.day1.disabled = true;
			window.document.eventinfo.day2.disabled = true;
		}
		else
		{
			window.document.eventinfo.day1.disabled = false;
			window.document.eventinfo.day2.disabled = false;
		}
		
		return;
	}
	//Selects the correct state for a returning user on reg_event.asp
	function setState(p_state){
		var v_state = p_state;
		var v_length = window.document.company.state.length;
		var i = 0;
		for(var i=0; i < v_length; i++){
			var v_current = window.document.company.state.options[i].text;
			if(v_state == v_current)
				window.document.company.state.selectedIndex = i;
		}
		return;
	}

//to retrieve lost passwords
function getEmail(){
	var v_email = window.document.frmLog.txtLog.value;
	window.location.href = ("LostPassw.asp?email=" + v_email);
	return;
}

//The easiest way I could think of automatically filling in all of the fields on company.asp
function getCompany(){
	var v_company = document.company.coList.options[document.company.coList.selectedIndex].text; 
    v_company = v_company.replace(/\+/g,"%2B");
    v_company = v_company.replace(/&/g,"%26");
    window.location.href = ("company.asp?selectedCo=" + v_company);
	return;
}

function getCompany2(){
	var v_company = document.company.coList.options[document.company.coList.selectedIndex].value;
	window.location.href = ("company_data.asp?selectedCo=" + v_company);
	return;
}

function getUser(p_usr, p_year){
	v_url = "/asp/htjf/data_entry.asp?admin=true&writeto=userinfo&usr=" + p_usr + "&yr=" + p_year;
	window.open(v_url,'userinfo','width=1024,height=600,resizable=yes,scrollbars=yes,menubar=yes,left=0,top=0,toolbar=yes,directories=yes');
	//window.open('/asp/htjf/data_entry.asp','userinfo','width=1024,height=600,resizable=yes,scrollbars=yes,menubar=yes,left=0,top=0,toolbar=yes,directories=yes');
	return;
}

function yearToFrom(){
	var v_yearFrom = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_yearTo = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var v_statID = document.functions.stat.options[document.functions.stat.selectedIndex].value;
	
	window.location.href = ("admin.asp?yearFrom=" + v_yearFrom + "&yearTo=" + v_yearTo + "&statID=" + v_statID);
	return;
}
function yearToFrom2(){
	var v_yearFrom = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_yearTo = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var v_emailID = document.functions.emSelected.value;
	
	window.location.href = ("email_hub.asp?yearFrom=" + v_yearFrom + "&yearTo=" + v_yearTo + "&emailID=" + v_emailID);
	return;
}
function standardEm(){
	var v_yearFrom = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_yearTo = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var v_emailID = document.functions.standard_email.options[document.functions.standard_email.selectedIndex].value;
	
	window.location.href = ("email_hub.asp?yearFrom=" + v_yearFrom + "&yearTo=" + v_yearTo + "&emailID=" + v_emailID);
	return;
}
function customEm(){
	var v_yearFrom = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_yearTo = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var v_emailID = document.functions.custom_email.options[document.functions.custom_email.selectedIndex].value;
	
	window.location.href = ("email_hub.asp?yearFrom=" + v_yearFrom + "&yearTo=" + v_yearTo + "&emailID=" + v_emailID);
	return;
}
function activateEm(){
	var v_yearFrom = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_yearTo = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var v_emailID = document.functions.deacted_email.options[document.functions.deacted_email.selectedIndex].value;
	
	window.location.href = ("email_hub.asp?yearFrom=" + v_yearFrom + "&yearTo=" + v_yearTo + "&emailID=" + v_emailID + "&status=act");
	return;
}
function deactivateCustEm(){
	var v_yearFrom = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_yearTo = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var v_emailID = document.functions.custom_email.options[document.functions.custom_email.selectedIndex].value;
	
	window.location.href = ("email_hub.asp?yearFrom=" + v_yearFrom + "&yearTo=" + v_yearTo + "&emailID=" + v_emailID + "&status=deact");
	return;
}
function deactivateStandEm(){
	var v_yearFrom = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_yearTo = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var v_emailID = document.functions.standard_email.options[document.functions.standard_email.selectedIndex].value;
	
	window.location.href = ("email_hub.asp?yearFrom=" + v_yearFrom + "&yearTo=" + v_yearTo + "&emailID=" + v_emailID + "&status=deact");
	return;
}
function deleteEm(){
	var v_yearFrom = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_yearTo = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var v_emailID = document.functions.deacted_email.options[document.functions.deacted_email.selectedIndex].value;
	
	window.location.href = ("email_hub.asp?yearFrom=" + v_yearFrom + "&yearTo=" + v_yearTo + "&emailID=" + v_emailID + "&status=delete");
	return;
}

function getFunc2(){
	var v_func = document.functions.selectFunc.options[document.functions.selectFunc.selectedIndex].value;
	var v_name = document.functions.selectFunc.options[document.functions.selectFunc.selectedIndex].text;
	var v_y1 = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_y2 = document.functions.yearStop.options[document.functions.yearStop.selectedIndex].text;
	var len = document.functions.coSelected.length;
	var v_coID = new Array(len)
	for(var i = 0; i < len; i++){
			v_coID[i] = document.functions.coSelected.options[i].value;
	}
	v_url = v_func + "?y1=" + v_y1 + "&y2=" + v_y2;
	for(var i_co = 0; i_co < v_coID.length; i_co++){
		v_url = v_url + "&co" + i_co + "=" + v_coID[i_co];
	}
	
	window.open(v_url,'function','width=900,height=520,resizable=yes,scrollbars=yes,menubar=yes,left=0,top=0,status=yes');
	document.functions.selectFunc.selectedIndex = 0;
	document.functions.selectFunc.blur();
	return;
}

function openList(){
	window.open('term_list.asp','term_list','width=800,height=520,resizable=yes,scrollbars=yes,menubar=yes,left=0,top=0');
	return;
}

function deleteCo(){
	var coID = document.functions.coSelected.options[0].value;
	var vyear = document.functions.yearStart.options[document.functions.yearStart.selectedIndex].text;
	var v_url = "delete.asp?coid=" + coID + "&vyear=" + vyear;
	window.open(v_url,'deleteco','width=500,height=200,resizable=yes,scrollbars=yes,menubar=yes,left=0,top=0');
}

function getReport(){
	var rptID = document.reports.saved.options[document.reports.saved.selectedIndex].value;
	var v_url = "custom.asp?fromSaved=true&id=" + rptID;
	window.open(v_url,'savedreport','width=1024,height=700,resizable=yes,scrollbars=yes,menubar=yes,left=0,top=0,toolbar=yes,directories=yes');
	document.reports.saved.selectedIndex = 0;
	document.reports.saved.blur();
	return;
}

//The following three functions are for the auto tab feature used in the phone and fax fields
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

function f_allRight(){
	var len = document.functions.coList.options.length;
	var rLen = document.functions.coSelected.options.length;
	for(var i = 0; i < len; i++){
		document.functions.coSelected.options[rLen] = new Option(document.functions.coList.options[i].text, document.functions.coList.options[i].value);
		document.functions.coSelected.options[rLen].selected = true;
		rLen = rLen + 1
	}
	len = len - 1
	while(len >= 0){
		document.functions.coList.options[len] = null;
		len = len - 1;
	}
	var listLen = document.functions.coList.options.length;
	var selectLen = document.functions.coSelected.options.length;
	window.document.functions.lDisp.value = listLen;
	window.document.functions.sDisp.value = selectLen;
	return;
}

function f_allLeft(){
	var len = document.functions.coSelected.options.length;
	var lLen = document.functions.coList.options.length;
	for(var i = 0; i < len; i++){
		document.functions.coList.options[lLen] = new Option(document.functions.coSelected.options[i].text, document.functions.coSelected.options[i].value);
		lLen = lLen + 1
	}
	var len = len - 1
	while(len >= 0){
		document.functions.coSelected.options[len] = null;
		len = len - 1;
	}
	var listLen = document.functions.coList.options.length;
	var selectLen = document.functions.coSelected.options.length;
	window.document.functions.lDisp.value = listLen;
	window.document.functions.sDisp.value = selectLen;
	return;
}

function f_oneRight(){
	var len = document.functions.coList.options.length;
	var x = document.functions.coSelected.options.length;
	for(var i = 0; i < len; i++){
		if(document.functions.coList.options[i].selected == true){
			document.functions.coSelected.options[x] = new Option(document.functions.coList.options[i].text, document.functions.coList.options[i].value);
			document.functions.coSelected.options[x].selected = true;
			document.functions.coList.options[i].text = "REMOVE"
			x = x + 1
		}
	}
	var rLen = document.functions.coSelected.options.length;
	var v_holdText = new Array(len)
	var v_holdValue = new Array(len)
	var b = 0
		for(var z = 0; z < len; z++){
			if(document.functions.coList.options[z].text != "REMOVE"){
				v_holdText[b] = document.functions.coList.options[z].text;
				v_holdValue[b] = document.functions.coList.options[z].value;
				b = b + 1
			}
		}
	var dlen = len
	while(dlen >= 0){
		document.functions.coList.options[dlen] = null;
		dlen = dlen - 1;
	}
	for(var a = 0; a < b; a++){
		document.functions.coList.options[a] = new Option(v_holdText[a], v_holdValue[a]);
	}
	var listLen = document.functions.coList.options.length;
	var selectLen = document.functions.coSelected.options.length;
	window.document.functions.lDisp.value = listLen;
	window.document.functions.sDisp.value = selectLen;
	return;
}

function f_oneLeft(){
	var len = document.functions.coSelected.options.length;
	var x = document.functions.coList.options.length;
	for(var i = 0; i < len; i++){
		if(document.functions.coSelected.options[i].selected == true){
			document.functions.coList.options[x] = new Option(document.functions.coSelected.options[i].text, document.functions.coSelected.options[i].value);
			document.functions.coSelected.options[i].text = "REMOVE"
			x = x + 1
		}
	}
	var rLen = document.functions.coList.options.length;
	var v_holdText = new Array(len)
	var v_holdValue = new Array(len)
	var b = 0
		for(var z = 0; z < len; z++){
			if(document.functions.coSelected.options[z].text != "REMOVE"){
				v_holdText[b] = document.functions.coSelected.options[z].text;
				v_holdValue[b] = document.functions.coSelected.options[z].value;
				b = b + 1
			}
		}
	var dlen = len
	while(dlen >= 0){
		document.functions.coSelected.options[dlen] = null;
		dlen = dlen - 1;
	}
	for(var a = 0; a < b; a++){
		document.functions.coSelected.options[a] = new Option(v_holdText[a], v_holdValue[a]);
	}
	var listLen = document.functions.coList.options.length;
	var selectLen = document.functions.coSelected.options.length;
	window.document.functions.lDisp.value = listLen;
	window.document.functions.sDisp.value = selectLen;
	return;
}