var pagenum;
function get_listings(jobqry,loc,pageset,pagenum) {

	temp = "<tr><td colspan=\"4\" align=\"center\">Please wait for your results</td></tr>";

	$("#indeed_job_listings").html(temp);

	$("#indeed_job_listings").fadeTo("normal", 0.50);
temp2 =  "<tr class=\"dark\"><td colspan=4 align=\"center\">";
$("#indeed_page_nav").html(temp2);  

	url = "http://www.wahm.com/indeedsvc.php?" ;


	if (jobqry.length>0)
	   url = url + "&qry=" + jobqry ;
	if (loc.length>0)
	   url = url + "&loc=" + loc ;
	if (pageset.length>0)
	   url = url + "&pagenav=" + pageset ;
	if (pagenum>0)
	   url = url + "&start=" + pagenum*10 ;

	temp ="";
		  
	$.getJSON(url, function(data){

		pagenum = data.page;
		totalresults = data.totalresults;
		if (totalresults==0){
			temp = "<tr><td colspan=4 align=\"center\">No Results Found</td></tr>";
			temp2 = "<tr><td colspan=4 align=\"center\"></td></tr>";
			$("#indeed_job_listings").fadeTo("slow", 1);
			$("#indeed_job_listings").html(temp);
			$("#indeed_page_nav").hide();  
		}
		else {
			$.each(data.results,function (i,item){

				cssclass = '';
				if (i%2==0)
				   cssclass = "class=\"dark\"";
				else
				   cssclass = "";
				temp = temp +"<tr " + cssclass + "><td class=\"date\">"+item.date+"</td><td>"+item.company+"</td><td class=\"position\"><a href=\""+item.url+"\" target=\"_blank\" rel=\"nofollow\">"+item.jobtitle+"</a></td><td class=\"state\">"+item.state+"</td></tr>";


				if (i==9 || i==totalresults) 
				{
					$.fn.wait = function(time, type) {
							time = time || 1000;
							type = type || "fx";
							return this.queue(type, function() {
								var self = this;
								setTimeout(function() {
									$(self).dequeue();
								}, time);
							});
						};


					$("#indeed_job_listings").fadeTo("slow", 1);
					$("#indeed_job_listings").wait().html(temp);
					return false;
				}
				else {
				
					if (data.results.length<=9 && data.results.length>0 ) {



					$("#indeed_job_listings").fadeTo("slow", 1);
					$("#indeed_job_listings").html(temp);
						
						
					}
				}

			});

			if (totalresults>9)
			{
//alert (pagenum+" beep "+totalresults);
				temp2 =  "<tr class=\"dark\"><td colspan=4 align=\"center\">";
				 if (pagenum!=0)
					temp2 = temp2 + "<a  href=\"javascript:get_listings('','','prev',0);\" id=\"prev\">Prev</a>  &nbsp;";
				 else
					temp2 = temp2 + "Prev  &nbsp;";
				pages = 20;
				if (totalresults < 200 ){
					pages = Math.round(( totalresults % 200 )/10);
				}
				 for (i=0;i<pages;i++) {
					if (i!=pagenum)
					   temp2 = temp2 + "<a href=\"javascript:get_listings('','','',"+i+");\" >" +(i+1) + "</a> &nbsp;";
					else
					   temp2 = temp2 + (i+1) + " &nbsp;";
				 }
				if (pagenum<pages-1)
					temp2 = temp2 + "&nbsp; <a  href=\"javascript:get_listings('','','next',0);\" id=\"next\">Next<a/></td></tr>";
				else
					temp2 = temp2 + "&nbsp; Next</td></tr>";     
					
				$("#indeed_page_nav").html(temp2);  
return false;
			}
		}
	});

}
function customSearch(){
 
 var   qry = $("#srchqry").val();
var	loc = $("#loc").val();
 


get_listings(qry,loc,"",0);
return false;
}
  $(document).ready(function(){
    pagenum = 0;
get_listings("","","",0);
});