﻿/*************************************************/
/*Moss Search*/
this.ajaxHandler = new cpaint();
this.ajaxHandler.set_transfer_mode('post');
this.ajaxHandler.set_response_type('text');	


function getPayments(PageNum,PagesGroup,FreeText,Unit)
{
	//alert(MS_Lang);
	//Validation of search values
	if(FreeText == "" && (Unit == "" || Unit == "UnSelected")
		&& MS_Office == "" && MS_Subject == "" && MS_Audience == "" && MS_Situation == "")
	{
		alert('אנא מלא/מלאי ערכי חיפוש');
		return;
	}
	
	var tdResults = document.getElementById('tdPaymentsResults');
	var sCallbackName = "getPaymentsResults";	
	var params ="page="+PageNum+"&group="+PagesGroup+"&mode="+isUnpublishedMode+"&freetext="+encodeURI(FreeText)+"&lang="+MS_Lang;
	if(Unit != "" && Unit != "UnSelected")
	{
		params = params +"&unit="+encodeURI(Unit);		 
	}
	else if(MS_Office != "")
	{
		params = params +"&unit="+encodeURI(MS_Office);		 
	}
	else
	{
		if(MS_Subject != "")
		{
			params = params +"&subject="+encodeURI(MS_Subject);		 
		}	
		if(MS_Audience != "")
		{
			params = params +"&audience="+encodeURI(MS_Audience);		 
		}	
		if(MS_Situation != "")
		{
			params = params +"&situation="+encodeURI(MS_Situation);		 
		}
	}
	
	var url = "/firstGov/Services/searchPaments.aspx?"+params;
	AJAX.asyncWithCallback(url, "", sCallbackName, true, false, tdResults) ;      

}

function getPaymentsResults(response)
{
	var tdResults = document.getElementById('tdPaymentsResults');
	tdResults.innerHTML = response;
}
function changeImageSearch(buttonName,imageName)
{
	document.images[buttonName].src= "/firstGov/Images/he/arrows/"+imageName+".gif";
	return true;
}

function changeImageSearchEng(buttonName,imageName)
{
	document.images[buttonName].src= "/firstGov/Images/en/arrows/"+imageName+".gif";
	return true;
}

//added by linoy for Forms Search
//"getForms(1,1,'" + freeTxt +"','"+ unit +"','"+ subUnit +"','"+ subject +"','"+ lifeStatus +"','"+ client +"','"+ isSearchPrintForm +"','"+ isSearchFillSendForm +"','"+ isSearchFillPrintForm +"');";
function getForms(PageNum,PagesGroup,FreeText,Unit, subUnit, Subject,lifeStatus, Audience, PrintForm, FillSendForm, FillPrintForm , ShowAlert)
{	
	
	//Validation of search values
	
	if(FreeText == "" 
		&& MS_Office == "" && (Unit == "" || Unit == "UnSelected")
		&& MS_Subject == "" && (Subject == "" || Subject == "UnSelected")
		&& MS_Audience == "" && (Audience == "" || Audience == "UnSelected")
		&& MS_Situation == "" && (lifeStatus == "" || lifeStatus == "UnSelected")) 
	{		

		if ( ShowAlert == true )
		{
			alert('אנא מלא/מלאי ערכי חיפוש');
		}
		return;
	}
	
	
	var tdResults = document.getElementById('tdFormsResults');
	var sCallbackName = "getFormsResults";		
	
	//MS_Office, MS_Subject, MS_Audience
	//these parameters come from the page FormSearchResult.aspx
	//used for the case that we get to results not from the Search UC 
	//but from the link  "תשלומים נוספים בנושא" on the categories under
	//the TAB "נושאים" which is placed on the header 
			
	var params ="page="+PageNum+"&group="+PagesGroup+"&mode="+isUnpublishedMode+"&freetext="+encodeURI(FreeText)+"&lang="+MS_Lang+"&feild="+MS_FieldName+"&order="+MS_SortBy;
	//office (unit) - UNIT
	if(Unit != "" && Unit != "UnSelected")
	{
		params = params +"&unit="+encodeURI(Unit);		 
	}
	else if(MS_Office != "")
	{
		params = params +"&unit="+encodeURI(MS_Office);		 
	}	
	//subUnit - SUBUNIT	
	if(subUnit != "" && subUnit != "UnSelected")
	{
		params = params +"&subUnit="+encodeURI(subUnit);		 
	}
	//LifeStatus
	if(lifeStatus != "" && lifeStatus != "UnSelected")
	{
		params = params +"&lifeStatus="+encodeURI(lifeStatus);		 
	}
	else if(MS_Situation != "")
	{
		params = params +"&lifeStatus="+encodeURI(MS_Situation);		 
	}
	
	//files for print  - GOVILFORMPRINTURL
	if(PrintForm != "" && PrintForm != "UnSelected")
	{
		params = params +"&printForm="+encodeURI(PrintForm);		 
	}
	
	//mourner files  - GOVILFORMFILLANDSENDURL
	if(FillSendForm != "" && FillSendForm != "False")
	{
		params = params +"&fillSendForm="+encodeURI(FillSendForm);		 
	}
	//mourner files  - GOVILFORMFILLANDPRINTURL
	if(FillPrintForm != "" && FillPrintForm != "False")
	{
		params = params +"&fillPrintForm="+encodeURI(FillPrintForm);		 
	}
	
	//subject - GOVILSUBJECT
	if(Subject != "" && Subject != "UnSelected")
	{
		params = params +"&subject="+encodeURI(Subject);		 
	}
	else if(MS_Subject != "")
	{
		params = params +"&subject="+encodeURI(MS_Subject);		 
	}	
	
	//client(audience) - GOVILAUDIENCE
	if(Audience != "" && Audience != "UnSelected")
	{
		params = params +"&audience="+encodeURI(Audience);		 
	}
	else if(MS_Audience != "") 
	{
		params = params +"&audience="+encodeURI(MS_Audience);		 
	}			
	
	var url = "/firstGov/Services/searchForms.aspx?"+params;
	AJAX.asyncWithCallback(url, "", sCallbackName, true, false, tdResults) ;     
}

function getAuthoritiessForms(PageNum,PagesGroup,FreeText,City,ShowAlert)
{	
	MS_FieldName = 'Rank';
	MS_SortBy='DESC';
	//debugger;
	//alert('getAuthoritiessForms');
	//Validation of search values
	if(FreeText == "" 
		&& (City == "" || City == "UnSelected")
		&& MS_Subject == "" && MS_Audience == "" && MS_Situation == "") 
	{	
		if(ShowAlert != false)
		{	
			alert('אנא מלא/מלאי ערכי חיפוש');
		}
		return;
	}
	
	
	var tdResults = document.getElementById('tdFormsResults');
	var sCallbackName = "getAuthoritiesResults";		
	
	
			
	var params = [];
	params.push("page="+PageNum+"&group="+PagesGroup+"&freetext="+encodeURI(FreeText)+"&feild="+MS_FieldName+"&order="+MS_SortBy);
	//city (city) - City
	if(City != "" && City != "UnSelected")
	{
		params.push("&city="+encodeURI(City));		 
	}
	
	//Situation
	if(MS_Situation != "")
	{
		params.push("&situation="+encodeURI(MS_Situation));		 
	}
			
	//subject - GOVILSUBJECT
	if(MS_Subject != "")
	{
		params.push("&subject="+encodeURI(MS_Subject));
	}	
	
	//client(audience) - GOVILAUDIENCE
	if(MS_Audience != "") 
	{
		params.push("&audience="+encodeURI(MS_Audience));
	}			
	
	if(District.length > 0)
	{
		District = District.replace("מחוז ","");
		params.push("&district="+encodeURI(District));
	}
	var url = "/firstGov/Services/AuthoritiesSearchForm.aspx?"+params.join("");	
	AJAX.asyncWithCallback(url, "", sCallbackName, true, false, tdResults) ;     
}


function getAuthoritiesResults(response)
{
	
	var tdResults = document.getElementById('tdFormsResults');
	tdResults.innerHTML = response;
}



function getFormsResults(response)
{
	var tdResults = document.getElementById('tdFormsResults');
	tdResults.innerHTML = response;
}

function changeSort(fieldName)
{		
	if(MS_SortBy == "ASC")
	{				
		MS_SortBy = "DESC";
	}
	else
	{		
		MS_SortBy = "ASC";
	}
	MS_FieldName=fieldName;
}


function ToggleSort()
{	
	var sortInput = document.getElementById('SortASC');
	var sortIcon = document.getElementById('SortIconID');
	
	//alert(sortInput.value );
	//alert(sortIcon);
	
	if ( sortInput.value  == "True" )
	{
		sortIcon.src = "/firstgov/Images/en/payments/orange-arrow.gif";
		sortInput.value = "False";
	}
	else
	{
		sortIcon.src = "/firstgov/Images/en/payments/orange-arrow-up.gif";
		sortInput.value = "True";		
	}
	getAllPaymentsEng('1','1')
}

function getAllPaymentsEng(PageNum,PagesGroup)
{		
	
	var tdResults = document.getElementById('tdPaymentResults');
	var sCallbackName = "getPaymentsEngResults";	
	var sortInput = document.getElementById('SortASC');
	var SortVal = "Asc";
	
	if ( sortInput.value  != "True" )
		SortVal = "Desc"
	
	var params ="page="+PageNum+"&group="+PagesGroup + "&Sort=" + SortVal;
	

	var url = "/firstGov/Services/searchPamentsEng.aspx?"+params;
	AJAX.asyncWithCallback(url, "", sCallbackName, true, false, tdResults) ;      

}

function getPaymentsEngResults(response)
{
	var tdResults = document.getElementById('tdPaymentResults');
	tdResults.innerHTML = response;
}
