// JavaScript Document
var xmlHttp;
 
var javscriptDebug= false;
 
$(document).ready(function(){
 
  $("#top").hide('fast',function()
								 {
									$("#main").fadeIn('slow'); 
									}
								 );
  
   Nifty("div#topSearchBar","transparent");
								
});



function GetXmlHttpObject(){
if (window.XMLHttpRequest) {  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject){  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}





function stateChanged() {

if (xmlHttp.readyState==4){
 var counties= '<br /><br />';

	counties +=xmlHttp.responseText;
	 
	document.getElementById("counties").innerHTML = counties;
	xmlHttp=null;
	}

}


function doSearch(){
var query 	= document.getElementById('query').value;


if(query.length< 2){
	alert('Please Enter a Job');
	document.getElementById('query').select();
	document.getElementById('query').focus();
	//document.getElementById('query').style.backgroundColor ='0x330033';
	 
	return;
}

var state 	= document.getElementById('states').options[document.getElementById('states').selectedIndex].value;
var county	=	null;
var zip		= document.getElementById('zip').value;
var city 	= 	document.getElementById('city').value;
var citySelectB = null;

if( document.getElementById('citiesSb') !=null && document.getElementById('citiesSb') && document.getElementById('citiesSb').options[document.getElementById('citiesSb').selectedIndex].value != -1)
	citySelectB = document.getElementById('citiesSb').options[document.getElementById('citiesSb').selectedIndex].value;

 

if(checkZipCode(document.getElementById('zip') )  == false)
	zip = null;
if(city.length <2 )
	city =null;


if(city == null && citySelectB !=null && citySelectB != -1)
	city = citySelectB;



if(state  == -1)
	state = null;

if( document.getElementById('countiesSb') !=null && document.getElementById('countiesSb') &&  document.getElementById('countiesSb').options[document.getElementById('countiesSb').selectedIndex].value != -1)
	county = document.getElementById('countiesSb').options[document.getElementById('countiesSb').selectedIndex].value;

var radius = 10;
var hash=  document.getElementById('hash').value 

var location;
if(zip !=null)
	location = zip;
else if(city != null && state != null)
	location =''+city + '%20'+ state;
else if(city != null && state == null)
	location =''+city;
else if(county != null && state != null)
	location =''+county + '%20'+ state;
else if(state != null)
	location = state;


var queryString = "?q=" + query +'&l='+location + '&state='+state +'&start=0&radius=' + radius + '&co=us&userSearch='+hash;
queryString += "&sId="+   Math.random() 


 
var u =baseUrl + queryString;

window.location.href=u;

//document.getElementById('debug').innerHTML="<a target=='_blank'  href='"+u+"' />"+u +"</a>";
 
}


function loadCounties(){
//alert('a: '  +  document.getElementById("counties"));

 document.getElementById("counties").innerHTML="<br />Loading...<br /><img src='"+ajaxLoadingImgUrl2 +"' hspace='5' vspace='5' /> <br />";
var state = document.getElementById('states').options[document.getElementById('states').selectedIndex].value;


xmlHttp = GetXmlHttpObject();

 var url='';
 url += defaultUrl +"?s="+state;
url += "&sid="+   Math.random() ;
//window.location.href=url;
if(javscriptDebug)
	document.getElementById('debug').innerHTML="<a target=='_blank'  href='"+url+"' />"+url +"</a>";
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}



function checkZipCode(obj){
var asStr = obj.value +"";

if(asStr.length < 3 || asStr.length > 5)
	{
	 return false;
	}
for(i=0;i < asStr.length;i++){
	var char =asStr.charCodeAt(i);
	if(char > 31 && (char <48  || char >57 )  )
			{
			 return false;
			}
	}
return true;
}
