$(window).load(function() {
	//Initialize Search Boxes with Default Text
	
	$('#text-keyword-search').attr( 'title','Search jobs by keyword...' );
	$('#text-location-search').attr( 'title','Search jobs by location...' );
	
	//By default run the onBlur event to add the content
	$('#text-keyword-search').blur();
	$('#text-location-search').blur();
	
});

//Add onFocus event that will set the value to null
$('#text-keyword-search').focus(function(srcc) {
	if ($(this).val() == $(this)[0].title) {
		$(this).removeClass('defaultTextActive');
		$(this).val('');
	}
});
$('#text-location-search').focus(function(srcc) {
	if ($(this).val() == $(this)[0].title) {
		$(this).removeClass('defaultTextActive');
		$(this).val('');
	}
});
//Add onBlur event that will set the value to the title attribute
$('#text-keyword-search').blur(function() {
	if ($(this).val() == '') {
		$(this).addClass('defaultTextActive');
		$(this).val($(this)[0].title);
	}
});
$('#text-location-search').blur(function() {
	if ($(this).val() == '') {
		$(this).addClass('defaultTextActive');
		$(this).val($(this)[0].title);
	}
});

//Add onClick event that will gather user input from both text fields and pass that into a search query
$('#form-search').submit(function() {
	var baseURL = '/search?q=';
	var jobSegment = $('#text-keyword-search').val();
	var locationSegment = '&location='+$('#text-location-search').val();
	
	var searchBox = $('#text-keyword-search');
	var locationBox = $('#text-location-search');
	
	if(searchBox.val()=='Search jobs by keyword...'&&locationBox.val()=='Search jobs by location...'){
		//Set the document's location to our new URL, without a keyword or location
		document.location.href=baseURL;
	}else if(searchBox.val()=='Search jobs by keyword...'){
		//Set the document's location to our new URL, without a keyword
		document.location.href=baseURL+locationSegment;
	}else if(locationBox.val()=='Search jobs by location...'){
		//Set the document's location to our new URL, without a location
		document.location.href=baseURL + jobSegment;
	}else{
		//Set the document's location to our new URL, including the keyword
		document.location.href=baseURL + jobSegment + locationSegment;
	}
	
	//Do not return to the form's default action
	return false;
});
