

function doSearch() { // Fires the search using values from sliders etc

			$('#searchResults').html('<h1>Search results</h1><img src=\'images/ajax-loader.gif\' alt=\'Loading\' class=\'loader\' />'); // Show the loading animation
			$('#searchResults').load('ajax/ajaxJobSearch.asp', {   // Make the ajax call
					'jobType': $('#jobType').val(), 	
					'keywords': $('#keywords').val(), 	
					'salaryFrom': $('#salaryFrom').val(), 	
					'salaryTo': $('#salaryTo').val(),	
					'counties': $('#counties').val() 	
			});	
			
			setCookie('jobType', $('#jobType').val() );
			setCookie('keywords', $('#keywords').val() );
			setCookie('salaryFrom', $('#salaryFrom').val() );
			setCookie('salaryTo', $('#salaryTo').val() );
			setCookie('counties', $('#counties').val() );
}

function showJobDetails(jobID) { // Fires the search using values from sliders etc
			
			location.href='jobDetail.asp?from=search&jobID='+jobID;

}


function extractUrl(input)
{
 // remove quotes and wrapping url() 
 var str;
 str = input.replace(/"/g,"").replace(/url\(|\)$/ig, "");
 str = str.substring(str.length,str.length-7);
 return str;
}

function switchBG(inputID)
{ 
 var str;
 str = $(inputID).css('background-image').replace(/"/g,"").replace(/url\(|\)$/ig, "");
 str = str.substring(str.length,str.length-7);
 if (str=='Off.gif'){
	 $(inputID).css('background-image', 'url(images/btnCountyOn.gif)'); 
 }
 else {
	 $(inputID).css('background-image', 'url(images/btnCountyOff.gif)'); 
 };
 
}

function switchCountyText(txt)
{
	var countyVal;
	countyVal = $('#counties').val();

	// Check if we need to remove or add to hidden counties field
	if(countyVal.indexOf(', '+txt) !== -1){//remove
		$('#counties').val(countyVal.replace((', '+txt), ''));
	}
	else  {// add countiesAllHolder
		$('#counties').val(countyVal+', '+txt);
	}
}

function countyClick(txt, inputID)
{
	switch(txt)
				{
				case 'None':
					$('#countyAll').show();
					$('#countyNone').hide();
					$('#counties').val('zzz');
					$('#countiesSelect ul li').css('background-image', 'url(images/btnCountyOff.gif)');	
					doSearch();
				  break;
				case 'All':
					$('#countyAll').hide();
					$('#countyNone').show();
					$('#counties').val($('#countiesAllHolder').val());
					$('#countiesSelect ul li').css('background-image', 'url(images/btnCountyOn.gif)');		 
					doSearch();
				  break;
				default:
					switchBG(inputID);
					switchCountyText(txt);
					doSearch();
				}
}


function addBasket(jobID)
{
	$('#addJobBtn').html('Added to list');	
	$('#jobsPanel').load('ajax/ajaxJobAdd.asp', { 
		'jobID': jobID				
			});
	location.reload();
}

function removeBasket(jobID)
{
	$('#addJobBtn').html('Removed from list');	
	$('#jobsPanel').load('ajax/ajaxJobRemove.asp', { 
		'jobID': jobID				
			});
	location.reload();
}

function refreshBasket()
{
	$('#jobsPanel').html('<p>Loading...</p>');
	$('#jobsPanel').load('ajax/ajaxJobBasket.asp', { 
						
			});
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   doSearch();
   return false;
   }
else
   return true;
}

$(document).ready(function() {	 
						   
			// retrieve any previously searched values
			var sMin, sMax, sKeywords, sType, sCounties;
			
			sKeywords = getCookie('keywords');
			$('#keywords').val(sKeywords);
			
			sMin = getCookie('salaryFrom');	if (sMin=='') {sMin = '10000'};
			$('#salaryFrom').val(sMin);
			sMax = getCookie('salaryTo');	if (sMax=='') {sMax = '100000'};
			$('#salaryTo').val(sMax);
			
			sType = getCookie('jobType');	if (sType=='') {sType = 'PT'};
			$('#jobType').val(sType);
			
			switch(sType)
				{
				case 'P':
					$('#typePermOn').show();
					$('#typePermOff').hide();
					$('#typeTempOn').hide();
					$('#typeTempOff').show();
				  break;
				case 'T':
					$('#typePermOn').hide();
					$('#typePermOff').show();
					$('#typeTempOn').show();
					$('#typeTempOff').hide();
				  break;
				case 'PT':
					$('#typePermOn').show();
					$('#typePermOff').hide();
					$('#typeTempOn').show();
					$('#typeTempOff').hide();
				  break;
				default:
					$('#typePermOn').show();
					$('#typePermOff').hide();
					$('#typeTempOn').show();
					$('#typeTempOff').hide();
				}
							
			
			// Set up salary range slider
			$('#salarySlider').slider({
				range: true,
				values: [sMin,sMax],
				min: 10000,
				max: 100000,
				step: 10000,
				slide: function(event, ui) {
					$('#salaryFrom').val($('#salarySlider').slider('values', 0));
					$('#salaryTo').val($('#salarySlider').slider('values', 1));
				},
				change: function(event, ui) {
					doSearch();
				}			
			});	
			
			// Event handlers
			$('#searchBtn').click(function() {
						doSearch();
						});
			
			$('#keywords').keyup(function() {
							if($('#keywords').val().length>4){
								doSearch();
							}
						});
			
			$('#typePermOn').click(function() {
					$('#typePermOn').hide();
					$('#typePermOff').show();
					$('#jobType').val($('#jobType').val().replace('P', ''));
					doSearch();
			});
			
			$('#typePermOff').click(function() {
					$('#typePermOff').hide();
					$('#typePermOn').show();
					$('#jobType').val('P' + $('#jobType').val());
					doSearch();
			});
			
			$('#typeTempOn').click(function() {
					$('#typeTempOn').hide();
					$('#typeTempOff').show();
					$('#jobType').val($('#jobType').val().replace('T', ''));
					doSearch();
			});
			
			$('#typeTempOff').click(function() {
					$('#typeTempOff').hide();
					$('#typeTempOn').show();
					$('#jobType').val($('#jobType').val() + 'T');
					doSearch();
			});
			
			$('#countyButton').click(function() {
					$('#countiesSelect').slideToggle('fast');
			});
			
			// Jobs basket
			refreshBasket();
			
});



 








