var divFlag = "#ffffcc"
var sep = String.fromCharCode(10)
function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,"") }
function do_apply(id)
{ document.form1.requisition_id.value = id
	do_process("apply")
}
function do_state()
{ document.form1.filter_city.value = ""
	do_list()
}
function do_city()
{ document.form1.filter_state.value = ""
	do_list()
}
function do_posting(id)
{ document.form1.requisition_id.value = id
	do_process("posting")
}
function pop_posting(id,w)
{ var page = window.location + '?id=' + id
	var opts = 'width=' + w + ',height=670,resizable=yes,scrollbars=yes,toobar=no,location=no,directories=no,status=no,menubar=no'
	document.form1.requisition_id.value = id
	document.form1.process.value = "list"
	var awin = window.open(page,'Apply',opts)
	awin.focus()
}
function do_submit()
{ document.form1.process.value = "submit"
	return true
}
function do_login_tab(tab)
{ document.form1.process.value = "login"
	tabs_select(tab)
}
function pw_validate()
{ document.form1.process.value = "password"
	var msg = check_required()

	if (document.form1.password && document.form1.pw_confirm)
	{ if (document.form1.password.value != document.form1.pw_confirm.value)
		{ if (msg == "") document.form1.password.focus()
			msg += sep + sep + "Password not equal to Confirm Password"
		}
	}
	if (msg != "")
	{ alert("** Input Required **" + sep + msg)
		return false
	}
	document.form1.submit()
	return true
}
function login_validate()
{ document.form1.process.value = "login"
	var msg = check_required()
	var exp = /^[^@]+@[^@]+.[a-z]{2,}$/i
	var email = document.form1.email.value

	if (email.search(exp) == -1)
	{ if (msg == "") document.form1.email.focus()
		msg += sep + sep + "A valid email address is required." + sep + "Please verify you have entered your email address correctly."
	}
	if (document.form1.password && document.form1.pw_confirm)
	{ if (document.form1.password.value != document.form1.pw_confirm.value)
		{ if (msg == "") document.form1.password.focus()
			msg += sep + sep + "Password not equal to Confirm Password"
		}
	}
	if (msg != "")
	{ alert("** Input Required **" + sep + msg)
		return false
	}
	document.form1.submit()
	return true
}
function apply_validate()
{ document.form1.process.value = ""
	if (!app_validate()) return false
	document.form1.process.value = "submit"
	return true
}
function cancel_login() { do_cancel() }
function do_cancel() { do_list() }
function do_list() { do_process("list") }
function do_clear() { do_process("clear") }
function do_login() { do_process("login") }
function do_logout() { do_process("logout") }
function do_password() { do_process("password") }
function do_process(proc)
{ document.form1.process.value = proc
	document.form1.submit()
}
function radio_value(obj)
{ var len = obj.length
	if (len == undefined)
	{ if (obj.checked) return obj.value
		return ""
	}
	for (var i = 0; i < len; i++)
	{ if (obj[i].checked) return obj[i].value
	}
	return ""
}
function hilite(obj)
{ if (obj.value == "" && obj.title != "") flag(obj)
	else unflag(obj)
}
function unflag(obj)
{ obj.style.background = "#ffffff"
}
function unflagId(id)
{ if (document.getElementById) document.getElementById(id).style.background = ""
}
function flag(obj)
{ obj.style.background = "#ffffcc"
}
function flagId(id)
{ if (document.getElementById) document.getElementById(id).style.background = divFlag
}
function hilite_source()
{ unflag(document.form1.detail_advertisement)
	unflag(document.form1.detail_job_posting)
	unflag(document.form1.detail_emp_referral)
	unflag(document.form1.detail_referral)
	unflag(document.form1.detail_other)
	src = radio_value(document.form1.source)
	if (src == "Advertisement" && document.form1.detail_advertisement.value == "") flag(document.form1.detail_advertisement)
	else if (src == "Job Posting" && document.form1.detail_job_posting.value == "") flag(document.form1.detail_job_posting)
	else if (src == "Employee Referral" && document.form1.detail_emp_referral.value == "") flag(document.form1.detail_emp_referral)
	else if (src == "Referral" && document.form1.detail_referral.value == "") flag(document.form1.detail_referral)
	else if (src == "Other" && document.form1.detail_other.value == "") flag(document.form1.detail_other)
	if (src == "") flagId("id_source")
	else unflagId("id_source")
}
function check_required()
{ var msg = ""
	for (i=0; i < document.form1.length; i++)
	{ inp = document.form1.elements[i]
		T = new String(inp.title)
		if (T != '') // if has title then input is required
		{ if (inp.type == "select-one")
			{ if (inp.selectedIndex < 1)
				{ flag(inp)
					if (msg == "") inp.focus()
					msg += sep + T
				}
			}
			else if (inp.type == "radio")
			{	if (radio_value(document.form1.elements[inp.name]) == "")
					msg += sep + T
			}
			else if (trim(inp.value) == "")
			{ flag(inp)
				if (msg == "") inp.focus()
				msg += sep + T
			}
		}
	}
	return msg
}
function hilite_contact()
{ if (document.form1.home_phone.value == "" && document.form1.work_phone.value == "" && document.form1.cell_phone.value == "" && document.form1.email.value == "")
		flagId("id_contact")
	else
		unflagId("id_contact")
}
function do_apply_tab(tab)
{ if (!app_validate()) return
	document.form1.process.value = "apply"
	tabs_select(tab)
}
function app_validate()
{ var msg = check_required()
	if (document.form1.email)
	{ if (document.form1.email.value == "" && document.form1.home_phone.value == "" && document.form1.work_phone.value == "" && document.form1.cell_phone.value == "")
		{ if (msg == "") document.form1.home_phone.focus()
			msg += sep + "Please enter a phone number or an email address";
		}
		hilite_contact()
	}
	if (document.form1.detail_advertisement)
	{ src = radio_value(document.form1.source)
		if (src == "Advertisement" && document.form1.detail_advertisement.value == "")
		{ if (msg == "") document.form1.detail_advertisement.focus()
			msg += sep + "Please tell us where you saw advertisement"
		}
		if (src == "Job Posting" && document.form1.detail_job_posting.value == "")
		{ if (msg == "") document.form1.detail_job_posting.focus()
			msg += sep + "Please tell us where you saw job posting"
		}
		if (src == "Employee Referral" && document.form1.detail_emp_referral.value == "")
		{ if (msg == "") document.form1.detail_emp_referral.focus()
			msg += sep + "Please tell us which of our employees referred you"
		}
		if (src == "Referral" && document.form1.detail_referral.value == "")
		{ if (msg == "") document.form1.detail_referral.focus()
			msg += sep + "Please tell us who referred you"
		}
		if (src == "Other" && document.form1.detail_other.value == "")
		{ if (msg == "") document.form1.detail_other.focus()
			msg += sep + "Please tell us briefly how you heard about us"
		}
		hilite_source()
	}
	if (msg != "")
	{ alert("** Input Required **" + sep + msg)
		return false
	}
	return true
}
function popup_pull()
{ if (window.opener)
	{ document.form1.candidate_id.value = window.opener.document.form1.candidate_id.value
		document.form1.reqs.value = window.opener.document.form1.reqs.value
	}
}
function popup_push()
{ if (window.opener)
	{ window.opener.document.form1.candidate_id.value = document.form1.candidate_id.value
		window.opener.document.form1.reqs.value = document.form1.reqs.value
		window.opener.document.form1.submit()
	}
}
