/*************************************************/
/*Moss Search*/
this.ajaxHandler = new cpaint();
this.ajaxHandler.set_transfer_mode('post');
this.ajaxHandler.set_response_type('text');	


function getPayments(PageNum,PagesGroup,FreeText,Unit)
{
//debugger;
	//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)
{	
	//alert('getForms');
	//Validation of search values
	//debugger;
	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;
		}
		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 


	
	// Split FreeText into array by space.
	// Loop throw the array.
	// If ( (array length > 1) And (Word Contains double/single quotes) ) -->  
	// Do Not Collect this word into Serach_FreeText.
	// Else 
	// If (array length == 1) -->
	// Remove all double/single quotes from the word and collect it.
	var txt_FreeText = FreeText.split(' ');
	var Serach_FreeText="";
	for(i=0;i<txt_FreeText.length;i++)
	{
		if (txt_FreeText[i].match(/["']{1}/g)==null && i<txt_FreeText.length)
		{
			Serach_FreeText = Serach_FreeText + txt_FreeText[i];
			if (i<txt_FreeText.length && txt_FreeText.length>1)
			{
				Serach_FreeText = Serach_FreeText + ' ' ;
			}		
		}
		else
		{
			if (txt_FreeText.length==1)
			{
				var wor = txt_FreeText[i];
				for(j=0;j<wor.length;j++)
				{
					if (wor.substring(j,j+1).match(/["']{1}/g)==null && j+1<=wor.length)
					{
						Serach_FreeText = Serach_FreeText + wor.substring(j,j+1);
					}	
				}
			}
			else
			{//last change
				var wor = txt_FreeText[i];
				for(j=0;j<wor.length;j++)
				{
					
					if (wor.substring(j,j+1).match(/["']{1}/g)==null && j+1<=wor.length)
					{
						Serach_FreeText = Serach_FreeText + wor.substring(j,j+1);
					}
					else
					{
						Serach_FreeText = Serach_FreeText + "&quot;";
						j = wor.length;
					}
				}
				Serach_FreeText = Serach_FreeText + ' ';
			}	
		}
	}
	if (Serach_FreeText.charAt(Serach_FreeText.length-1)==' ')
	{
		Serach_FreeText = Serach_FreeText.substring(0,Serach_FreeText.length-1);
 	}
 	Serach_FreeText = FreeText;
	
	
	var params ="page="+PageNum+"&group="+PagesGroup+"&mode="+isUnpublishedMode+"&freetext="+encodeURI(Serach_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;//alert(params);
	AJAX.asyncWithCallback(url, "", sCallbackName, true, false, tdResults) ;     
}

function getAuthoritiessForms(PageNum,PagesGroup,FreeText,City,ShowAlert)
{	//debugger;
	MS_FieldName = 'Rank';
	MS_SortBy='DESC';
	//debugger; 
	//alert('getAuthoritiessForms');
	//Validation of search values
	
	//Old Condion Before Change
	/*if(FreeText == "" 
		&& (City == "" || City == "UnSelected")
		&& MS_Subject == "" && MS_Audience == "" && MS_Situation == "") 
	{	
		if(ShowAlert != false)
		{	
			alert('אנא מלא/מלאי ערכי חיפוש');
		}
		return;
	}*/
	
	
	//
	var txt_FreeText="";
	try{
		if (document.getElementById('AuthoritiessFormsSearch1_txtFreeText') != null)
		{
			txt_FreeText = document.getElementById('AuthoritiessFormsSearch1_txtFreeText').value;
		}
		if (document.getElementById('onLineServices1_AuthoritiessFormsSearch1_txtFreeText') != null)
		{
			txt_FreeText = document.getElementById('onLineServices1_AuthoritiessFormsSearch1_txtFreeText').value;
		}
	}
	catch(err)
	{
	}
	//var txt_FreeText = document.getElementById('AuthoritiessFormsSearch1_txtFreeText').value;
	if(FreeText == "" && (txt_FreeText=="" || txt_FreeText=="טקסט חופשי") && (City == "" || City == "UnSelected")) 
	{
		if ( ShowAlert != false )
		{
			alert('אנא מלא/מלאי ערכי חיפוש');
			//return;
		}
		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;
}

