var searchresults

window.onload = init;

function init()
{
	//Set up the smartSearch
	var searchinput = document.getElementById('sitesearch');
	searchresults = document.getElementById('ssresults');
	
	searchinput.onkeyup = searchinput.onfocus = function()
	{
		sendsmartSearch(searchinput.value);
	}
	
	searchresults.onblur = searchinput.onblur = function()
	{
		hideThatMenu = setTimeout("hideMenu()",500)
	}
	
	//Find any pdfs or emails on the page to place the correct icon. 
	/*var a = document.getElementsByTagName("A")
		for( i=0;i<a.length;i++ )
		{
			//alert("yes")
			if( a[i].href.indexOf('.pdf') != -1 || a[i].href.indexOf('.PDF') != -1 )
			{
				//alert("yes")
				a[i].style.paddingLeft = '18px'
				a[i].style.background = 'url(/images/ico_pdf.gif) top left no-repeat'
				//a[i].style.height = '16px'
			}
			
			if( a[i].href.indexOf('mailto:') != -1 || a[i].href.indexOf('MAILTO:') != -1 )
			{
				a[i].style.paddingRight = '18px'
				a[i].style.background = 'url(/images/ico_mail.gif) top right no-repeat'
			}
			
		}*/
}

function pullsmartSearch()
{
	if( xmlHttp.readyState == 4 )
	{
		searchresults = document.getElementById('ssresults');
		var seeall = document.getElementById('sitesearch')
		var results = ''
		var matches = ''
		var sMatch = ''
		 matches = xmlHttp.responseText.split('*|*');
		 
		for( i=0;i<(matches.length-1);i++ )
			{	
				sMatch = matches[i].split("||");
				results += '<a href="/?id='+sMatch[0]+'">'+sMatch[1]+'</a>'
			}
		results += '<a class="all" href="/Scripts/smartSearch.asp?ssphrase='+seeall.value+'">See all</a>'
		searchresults.innerHTML = results
		
		if( results.value != '' )
		{
			delaymenu = setTimeout("showMenu()",5000);
		}
		//else
//		{
//			searchresults.style.display = 'none'
//		}
	}
}

function sendsmartSearch(searchphrase)
{
	checkAJAX();
	//alert(searchphrase)
	var url = "/Scripts/ajax/smartsearch.ajax.asp";
	url += "?smart="+searchphrase;
	xmlHttp.onreadystatechange = pullsmartSearch;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function showMenu()
{
	searchresults = document.getElementById('ssresults');
	searchresults.style.display = 'block'
}

function hideMenu()
{
	var hide = document.getElementById('sitesearch')
	searchresults = document.getElementById('ssresults');
	
	searchresults.style.display = 'none'
	hide.value = ''
			
}



// browser detection
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) 
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


function validate(form,findclass)
{
	//alert("yes")
	var tag=document.body.getElementsByTagName('*');
	var errormsg = document.getElementById('errormsg')
	var txt = ''
	for(var i=0; i<tag.length; i++) 
	{
		if(tag[i].className == findclass)
			{
				//tag[i].style.className = 'ERROR'
					//confirm(tag[i].name)
				if(tag[i].value == '')
				{
					errormsg.style.display = "block"
					tag[i].style.border = '#C00 solid 3px'
					tag[i].focus();
					return false;
				}
			}
	}
	//sendForm()
}



function addEmployer(num){
	//checkAJAX();
//	
//	var url = "/Scripts/ajax/addEmployer.asp";
//	xmlHttp.onreadystatechange = employerStateChange;
//	xmlHttp.open("GET",url,true);
//	xmlHttp.send(null);
	var employer = document.getElementById('employer' + (num+1));
	
	if(employer){
		employer.style.display = 'block';
	}


	
	
}

function employerStateChange(){
	if( xmlHttp.readyState == 4 ){
		var employers = document.getElementById("employers");
		employers.innerHTML += xmlHttp.responseText;
	}
	
}


function validateApplication(oForm){
	

	if(validateInput(oForm.fName,"First Name is a required field.")==false||
	validateInput(oForm.mName,"Middle Name is a required field.")==false||
	validateInput(oForm.lName,"Last Name is a required field.")==false||
	validateSocial(oForm.ssn,"Please enter a valid social security number.\ni.e. xxx-xx-xxxx")==false||
	validateInput(oForm.address,"Address is a required field.")==false||
	validatePhone(oForm.homePhone,"Please enter a valid Home Phone.\ni.e. xxx-xxx-xxxx")==false||
	validateCheckGroup(oForm.under18,"Please indicate whether or not you are over the age of 18.")==false||
	validateInput(oForm.position,"Position is a required field.")==false){
		return false;
	}
	
	//This field is not required, but if they enter something make sure it is in the correct format.
	if(oForm.dateAvailable.value.length > 0){
		if(validateDate(oForm.dateAvailable,"Please enter a valid Available Date.\ni.e. xx/xx/xxxx")==false){
			return false;
		}
	}
	
	if(validateCheckGroup(oForm.employmentPreference,"Employment preference is a required field")==false||
	validateCheckGroup(oForm.criminal,"Please indicate whether or not you have ever been convicted of a felony of misdemeanor.")==false||
	validateCheckGroup(oForm.fine,"Please indicate whether or not you have ever paid a civil forfeiture.")==false||
	validateInput(oForm.highSchoolName,"High School Name is a required field.")==false||
	validateCheckGroup(oForm.highSchoolYear,"Please indicate the last year of high school completed.")==false||
	validateCheckGroup(oForm.highSchoolGrad,"Please indicate whethor or not you graduated high school.")==false||
	validateCheckDependent(oForm.noEmployment,oForm.companyPosition1,"Position is a required field.",false)==false||
	validateCheckDependent(oForm.noEmployment,oForm.companyName1,"Company Name is a required field.",false)==false||
	validateCheckDependent(oForm.noEmployment,oForm.companyAddress1,"Company Address is a required field.",false)==false||
	validateCheckDependent(oForm.noEmployment,oForm.companyCity1,"Company City is a required field.",false)==false||
	validateCheckDependent(oForm.noEmployment,oForm.companyState1,"Company State is a required field.",false)==false){
		return false;
	}
	
	if(oForm.noEmployment.checked==false){
		if(validatePhone(oForm.companyPhone1,"Please enter a valid Company Phone Number \ni.e. xxx-xxx-xxxx")==false||
		validateDate(oForm.companyStart1,"Please enter a valid Start Date.\ni.e. xx/xx/xxxx")==false||
		validateCheckGroup(oForm.companyContact1,"Please indicate whether or not we may contact the employer.")==false){
			return false;
		}
			
	}
	
	//This field is not required, but if they enter something make sure it is in the correct format.
	if(oForm.companyEnd1.value.length > 0){
		if(validateDate(oForm.companyEnd1,"Please enter a valid End Date.\ni.e. xx/xx/xxxx")==false){
			return false;
		}
	}
	
	if(validateCheckDependent(oForm.noEmployment,oForm.companySupervisor1,"Company Supervisor is a required field.",false)==false||
	validateCheckDependent(oForm.noEmployment,oForm.companyEmail1,"Email is a required field",false)==false||
	validateCheckDependent(oForm.noEmployment,oForm.companyReason1,"Reason for leaving is a required field.",false)==false||
	validateCheckDependent(oForm.noEmployment,oForm.companyDuties1,"Company Duties is a required field.",false)==false||
	validateCheck(oForm.privacy,"You must agree to the employee application authoriztion before you can submit your application.")==false){
			return false;
	}
	
}