//This JS file has the functions needed for the Search Project Index page.
//Jquery stylish select initialization
$(document).ready(function(){
	$('#selectProvince, #selectSector, #selectStatus, #selectGovtLevel').sSelect();		
});
//This function resets the form
function frm_search_reset()
{
	$('#selectProvince').getSetSSValue('All');
	$('#selectSector').getSetSSValue('All');
	$('#selectStatus').getSetSSValue('All');
	$('#selectGovtLevel').getSetSSValue('All');	
	$('#txtProjectName').val("");
}
//This function is called when the user clicks on the Search button.
function search(baseuri,pageid)
{
	document.getElementById("loadimage").style.display="block";		
	var province = ($('#selectProvince').getSetSSValue() == 'All')?'':$('#selectProvince').getSetSSValue();
	var sector = ($('#selectSector').getSetSSValue() == 'All')?'':$('#selectSector').getSetSSValue();
	var status = ($('#selectStatus').getSetSSValue() == 'All')?'':$('#selectStatus').getSetSSValue();
	var govtLevel = ($('#selectGovtLevel').getSetSSValue() == 'All')?'':$('#selectGovtLevel').getSetSSValue();
	var projectName = document.getElementById('txtProjectName').value;
	
	sector =sector.replace(/-fff-/g,'\'');
	sector =sector.replace(/-ddd-/g,'\"');
	
	var url = baseuri+"/search-project/searchresults"+"?txt_prov="+encodeURIComponent(province)+"&txt_sector="+encodeURIComponent(sector)+"&txt_status="+encodeURIComponent(status)+"&txt_gov_level="+encodeURIComponent(govtLevel)+"&txt_project_name="+encodeURIComponent(projectName)+"&pageid="+pageid;
	
	var qurString = "";
	var method = "POST";	
	sendAjaxRequest(url, '', 'POST', 'callFunction');	
}
//This function shows the reponse of the search action
function callFunction(response)
{
	if(response.substring(0,6) == "<html>"){
		location.reload(true);
		return;	
	}
	document.getElementById("loadimage").style.display="none";
	document.getElementById("container").innerHTML = response;	
 	var table = document.getElementById("sort");
	//sorttable.makeSortable(table);
	$("#sort").tablesorter({headers: {8: {sorter: false}},widgets: ['zebra']});
	if(navigator.appName == "Netscape"){
		if(document.getElementById("scrollDiv")){
			//document.getElementById("scrollDiv").style.overflowX = 'auto';
			//document.getElementById("scrollDiv").style.overflowY = 'hidden';
		}
	}	
	window.scrollTo(0,300);	 
}
//This function generates the Excel Report for the Search Result Page
function generateExcelReport(baseuri,pageid)
{
	var province = ($('#selectProvince').getSetSSValue() == 'All')?'':$('#selectProvince').getSetSSValue();
	var sector = ($('#selectSector').getSetSSValue() == 'All')?'':$('#selectSector').getSetSSValue();
	var status = ($('#selectStatus').getSetSSValue() == 'All')?'':$('#selectStatus').getSetSSValue();
	var govtLevel = ($('#selectGovtLevel').getSetSSValue() == 'All')?'':$('#selectGovtLevel').getSetSSValue();	
	var projectName = $('#txtProjectName').val();	
	sector =sector.replace(/-fff-/g,'\'');
	sector =sector.replace(/-ddd-/g,'\"');
	window.open(baseuri+'/search-project/generate-excel-report'+"?txt_prov="+encodeURIComponent(province)+"&txt_sector="+encodeURIComponent(sector)+"&txt_status="+encodeURIComponent(status)+"&txt_gov_level="+encodeURIComponent(govtLevel)+"&txt_project_name="+encodeURIComponent(projectName)+"&pageid="+pageid,'_self');
}
//These are called for mouseover and mouseout events on each row
var originalClass = "";
function mouseOver(obj){	
	originalClass = $(obj).attr("class");	
	$(obj).removeClass(originalClass);
	$(obj).addClass('hlt');
}
function mouseOut(obj){	
	$(obj).removeClass('hlt');
	$(obj).addClass(originalClass);
}
