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 apply_validate()
{ document.form1.process.value = ""
	if (!app_validate()) return false
	document.form1.process.value = "submit"
	return true
}
function do_list() { do_process("list") }
function do_clear() { do_process("clear") }
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 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
}
