//::MM Rollovers
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function loadRollovers() {
	MM_preloadImages('images/Nav_Services_R.gif','images/Nav_AnimalInfo_R.gif','images/Nav_Resources_R.gif','images/Nav_Careers_R.gif','images/Nav_Home_R.gif','images/Nav_Home_R.gif','images/Nav_ContactUs_R.gif');
}

//::attach onload event
if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", loadRollovers, false );
else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", loadRollovers );
}
else {
    if ( window.onload != null ) {
        var oldOnload = window.onload;
        window.onload = function ( e ) {
            oldOnload( e );
            loadRollovers;
        };
    }
    else
        window.onload = loadRollovers;
}

//::Attach onLoad Event (Crossbrowser)
//ex.	 onLoadEvent("alert('sample')");
function onLoadEvent(strFunc) {
	if (window.addEventListener)
		window.addEventListener("load", function(){eval(strFunc)}, false);
	else if (window.attachEvent)
		window.attachEvent("onload", function(){eval(strFunc)});
	else if (ie4||dom||document.layers)
		window.onload = function(){eval(strFunc)};
}

//::Toggle Navigation
function ToggleNav(intID) {
	$j('.nav_sm').slideUp('slow');
	if ($j('#sm'+intID).is(':hidden')) {
		$j('#sm'+intID).slideDown('slow');
	}
}

//::Fill Resume Form
function FillResumeForm(strPosition,strEmail) {
	document.frm.position.value = strPosition;
	if (strEmail != "") {
		document.frm.attention.value = strEmail;
		UpdateJobsEmail(strEmail);
	}
	document.location.href = '#apply';
}

//::Update Jobs Email
function UpdateJobsEmail(strEmail) {
	if (strEmail == "") {
		strEmail = "jobs@wildlifesolutions.com";
	}
	document.getElementById("jobsemail").innerHTML = "<a href='mailto:" + strEmail + "'>" + strEmail + "</a>";
}

//::Sub Menu (Display/Hide)
function subMenu(strMenu) {
	if (document.getElementById('sm'+strMenu).style.display == "none"){
		document.getElementById('sm'+strMenu).style.display = "";
	}
	else{
		document.getElementById('sm'+strMenu).style.display = "none";
	}
}

//::Display Career Position Details
function PositionDetails(id) {
	document.getElementById('pm'+id).style.display='none';
	document.getElementById('pd'+id).style.display='';
}

//::Build E-Mail Link
//ex. document.write(BuildEmail('Click Here','email','isp.com','Subject',''))
function BuildEmail(lnkName,lnkEmail,lnkHost,lnkSubject,lnkStyle){
	if(lnkName == ""){
		lnkName = lnkEmail + "&#64;" + lnkHost;
	}
	if(lnkSubject != ""){
		lnkSubject = "?subject=" + lnkSubject;
	}
	return "<a href='" + "mail" + "to:" + lnkEmail + "@" + lnkHost + lnkSubject + "' " + lnkStyle + ">" + lnkName + "</a>";
}

//::Trim String Function
function Trim(str){
	str = str.replace(/\s+/,'');
	str = str.replace(/\s+$/,'');
	return str;
}

//::IsNumeric Function
function IsNumeric(val){
	for (i=0; i<val.length; i++){
		if (isNaN(val.charAt(i))){
			return false;
		}
	}
	return true;
}

//::Valid E-Mail
function ValidEmail(str){
	AccPos = str.indexOf('@');
	AccStr = str.substr(0,AccPos);
	AccLen = AccStr.length;
	DomPos = str.lastIndexOf('.');
	DomStr = str.substr(AccPos+1,(DomPos-AccPos)-1);
	DomLen = DomStr.length;
	ExtPos = DomPos + 1;
	ExtLen = str.length - ExtPos;
	ExtStr = str.substr(ExtPos,ExtLen);
	if(	   (AccPos != -1)
		&& (DomPos != -1)
		&& (AccLen >= 2)
		&& (DomLen >= 2)
		&& (ExtLen >= 2)
		&& (ExtLen <= 3)){
		return true;
	}
	else{return false}
}

//::Valid Phone
function ValidPhone(PhoneArea,PhonePre,PhoneSuf){
	if ((Trim(PhoneArea) == "") ||
		(Trim(PhonePre) == "") ||
		(Trim(PhoneSuf) == "") ||
		(PhoneArea.length != 3) ||
		(PhonePre.length != 3) ||
		(PhoneSuf.length != 4)){
		return false;
	}else{
		if (IsNumeric(PhoneArea) &&
			IsNumeric(PhonePre) &&
			IsNumeric(PhoneSuf) &&
			(PhoneArea.length == 3) &&
			(PhonePre.length == 3) &&
			(PhoneSuf.length == 4)){
			return true;
		}
	}
}

//::Valid Telephone
function ValidTelephone(str){
	str = Trim(str);
	str = str.replace("(","");
	str = str.replace(")","");
	str = str.replace(".","");
	str = str.replace(".","");
	str = str.replace("-","");
	str = str.replace("-","");
	str = str.replace(" ","");
	strLen = str.length;
	if((strLen == 10 || strLen == 7) && IsNumeric(str)){
		return true;
	}
	else{
		return false;
	}
}

//::Validate Contact
function ValidateContact() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.name.value == "") {
	missinginfo += "\n     »  Name";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}
	/*
	if (!ValidPhone(objForm.FIELD.value,objForm.FIELD.value,objForm.FIELD.value)) {
	missinginfo += "\n     »  Phone";
	}
	*/

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Testimonial
function ValidateTestimonial() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.name.value == "") {
	missinginfo += "\n     »  Name";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}
	if (objForm.comments.value == "") {
	missinginfo += "\n     »  Testimonial";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate FedEx
function ValidateFedEx() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.name.value == "") {
	missinginfo += "\n     »  Name";
	}
	if (objForm.address.value == "") {
	missinginfo += "\n     »  Address";
	}
	if (objForm.city.value == "") {
	missinginfo += "\n     »  City";
	}
	if (objForm.state.value == "") {
	missinginfo += "\n     »  State";
	}
	if (objForm.zip.value == "") {
	missinginfo += "\n     »  Zip";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}
	if (objForm.details.value == "") {
	missinginfo += "\n     »  Order Details";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Careers
function ValidateCareers() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.attention.value == "") {
	missinginfo += "\n     »  Positions for [Location]";
	}
	if (objForm.name.value == "") {
	missinginfo += "\n     »  Name";
	}
	if (objForm.address.value == "") {
	missinginfo += "\n     »  Address";
	}
	if (objForm.city.value == "") {
	missinginfo += "\n     »  City";
	}
	if (objForm.state.value == "") {
	missinginfo += "\n     »  State";
	}
	if (objForm.zip.value == "") {
	missinginfo += "\n     »  Zip";
	}
	if (!ValidTelephone(objForm.phone.value)) {
	missinginfo += "\n     »  Phone";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}
	if (objForm.howhear.value != "") {
		if (objForm.howhear.value == "Other:") {
			if (objForm.other.value == "") {
			missinginfo += "\n     »  How did you hear about us? (Please Specify)";
			}
		}
	}
	else {
		missinginfo += "\n     »  How did you hear about us?";
	}
	if (objForm.position.value == "") {
	missinginfo += "\n     »  Position";
	}
	if (objForm.comments.value == "") {
	missinginfo += "\n     »  Resume / More Info";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}