/*
Name				:executeSearch
Notes				:makes a call to the server side search functionality using the AJAX object to search					
Parameters	:searchSql - string: contains the SQL to execute against the database
*/
function executeSearch(searchSql){		
	xajax_executeSql(searchSql);	
}

/*
Name				:executeSavedSearch
Notes				:makes a call to the server side search functionality using the AJAX object to execute
						:the last search for the current session
Parameters	:none
*/
function executeSavedSearch(){	
	xajax_executeSavedSearch();		
}

/*
Name				:saveSearch
Notes				:makes a call to the server side search functionality using the AJAX object to save
						:the last executed search for the session, or the passed in sql string
Parameters	:searchSql - string (optional): contains the SQL to save
*/
function saveSearch(searchSql){
	if(searchSql == ""){
		searchSql = msSearchSql;
	}
	xajax_saveSearch("", "", searchSql);
}

/*
Name				:deleteTableRows
Notes				:removes all TR elements from the specified table
Parameters	:tableName - string: table containing the rows to delete
*/
function deleteTableRows(tableName) {
	var elem = document.getElementById(tableName);
	
  for (var i = elem.rows.length-1; i >= 0 ; i--) {
  	elem.removeChild(elem.rows[i]);
  }
}

/*
Name				:outputSearchResultsRow(table
Notes				:outputs the individual TR element for search data
Parameters	:table - object: table object where the row is to be created
						:resultArray - array: recordset data
						:classTitle - string: class name for output of specific style for row
						:noRecordsFound - boolean: indicates if no record message HTML is to be displayed in place of row data
*/
function outputSearchResultsRow(resultArray, tableName, classTitle, noRecordsFound){		
	var table = document.getElementById(tableName);	
	var sJobHtml = "";	
	var tr = document.createElement('TR');
	table.appendChild(tr);		
	var td = document.createElement('TD');
	tr.appendChild(td);
	
	if(noRecordsFound == "false"){
		var sDescription = resultArray[5];
		sJobHtml = "<div class='jobSummary " + classTitle + "'>";
		sJobHtml +=  	"<div><a style='font-weight:bold;' href='../job-detail/" + resultArray[4] + "'>" + resultArray[0] + ": £" + resultArray[2] + "K - £" + resultArray[3] + "K</a></div>";
		sJobHtml += 	"<div>" + sDescription.substr(0, 100 + sDescription.indexOf(" ", 100)) + "...&nbsp<a href='../job-detail/" + resultArray[4] + "'>view</a></div>";
		sJobHtml += 	"<div><div style='width:150px;float:left;'>Location: " + resultArray[1] + "</div>";
		sJobHtml += 	"<div style='float:right;width:100px;display:inline;'><a href=\"javascript:addToNet('"+resultArray[4]+"')\">Add To Job Net</a></div></div>";
		sJobHtml += "</div>";
		var oRefineSearchImg = document.getElementById("refineSearchBottom");
		if(oRefineSearchImg){
			oRefineSearchImg.style.display = "inline";
		}
	}else{
		//no jobs found copy
		var sNoJobsCopy = "<p>Sorry, on this occasion no vacancies that matched your requirements were found.</p>";
		sNoJobsCopy += "<p>However, our job pages are updated daily so don’t forget to check the site on a regular basis to find other opportunities that you’d be interested in.</p>";
		sNoJobsCopy += "<p>To receive the latest jobs by email, why not subscribe to our free monthly jobs bulletin. For the price of a few details we’ll bring you the latest jobs, news and relevant information from the advertising, marketing, PR, creative, digital and sales industries.</p>";
		sNoJobsCopy += "<p>To receive your copy, please fill in the form below and the next issue will be sent straight to your inbox.</p>";
		sNoJobsCopy += '<form action="http://bigfishrecruitment.cmail1.com/s/88622/" method="post" style="margin-left:22px;"><table><tr><td>Name:</td><td><input type="text" name="name" id="name" style="width:200px;" /></td></tr><tr><td>Email:</td><td><input type="text" name="cm-88622-88622" id="l88622-88622" style="width:200px;" /></td></tr><tr><td><input type="image" src="images/site/subscribe.gif" style="border:0;cursor:hand;"/></td></tr></table></form>'
		sJobHtml = "<div class='jobSummary " + classTitle + " noJobs'>";
		sJobHtml += sNoJobsCopy;		
		sJobHtml += "</div>";
		//remove the second refine search image
		var oRefineSearchImg = document.getElementById("refineSearchBottom");
		if(oRefineSearchImg){
			oRefineSearchImg.style.display = "none";
		}
	}
	td.innerHTML = sJobHtml;			
}

/*
Name				:addToNet
Notes				:makes call to AJAX  function to add a job record to the job net
Parameters	:jobId - string: Id of job record
*/
function addToNet(jobId) {
	xajax_addToNet(jobId);
}

/*
Name				:deleteFromNet
Notes				:makes call to AJAX  function to delete a job record from the jobnet table
Parameters	:jobId - string: Id of job record
*/
function deleteFromNet(jobId){
	xajax_deleteFromNet(jobId);
	xajax_jobNetStatus();
}


/*
Name				:jobNetStatus
Notes				:makes a call to AJAX function to update the job net record count
Parameters	:none
*/
function jobNetStatus() {
	xajax_jobNetStatus();
}

/*
Name				:jobNetStatusDisplay
Notes				:makes a call to AJAX function to update the job net record count
Parameters	:none
*/
function jobNetStatusDisplay(count) {
	document.getElementById("divJobNet").innerHTML = "<a href='index.php?main=page&mode=jobnet' title='Your Job Net'>Jobs in your net: " + count + "</a>";
}

function showAlert(message){
	alert(message);
}