﻿var sChannelGuid;
var iPagingIndex;
var arrSearchCriteria;
var BureauAddressClientId;
var CityClientId

function LocateBureaus(sGuid,sBureaAdressId,sCityId)
{
	DisplayWaitMessage();
	sChannelGuid = sGuid;
	window.setTimeout(SearchBureaus,600);
}

function SearchBureaus()
{
	var arrParams = new Array();
	var arrReturnParams = new Array(); 
	var sErrorMessage = ""; 
	
	arrParams[0] = sChannelGuid;
	arrParams[1] = document.getElementById("_ctl0_ddlBureauType").value == 0?"":document.getElementById("_ctl0_ddlBureauType").value ; 
	arrParams[2] = document.getElementById("_ctl0_ddlBureauAddress_ddlAvailableOptions").value == 0?"":document.getElementById("_ctl0_ddlBureauAddress_ddlAvailableOptions").value ;
	arrParams[3] = document.getElementById("_ctl0_ddlCity_ddlAvailableOptions").value == 0?"":document.getElementById("_ctl0_ddlCity_ddlAvailableOptions").value; 
	arrParams[4] = document.getElementById("_ctl0_ddlBureauArea").value == 0?"":document.getElementById("_ctl0_ddlBureauArea").value ;
	arrParams[5] = 1;
	
	//save criteria
	if(arrSearchCriteria == null)
		arrSearchCriteria = new Array();
		
	arrSearchCriteria[0] = arrParams[0];
	arrSearchCriteria[1] = arrParams[1];
	arrSearchCriteria[2] = arrParams[2];
	arrSearchCriteria[3] = arrParams[3];
	arrSearchCriteria[4] = arrParams[4];
	
	sErrorMessage = XMLRPC("CBureauLocateUI","LocateBureau",arrParams,arrReturnParams,"Taldor.Taasuka.UI","Taldor.Taasuka.UI.dll");
	
	HideWaitMessage();
	
	if (sErrorMessage == "") 
	{
		document.getElementById("tdResults").innerHTML = arrReturnParams[0];
	}
	else if (sErrorMessage == "-1")
	{
		document.location.href = ERROR_MESSAGE_PAGE ; 
	}
	else 
	{ 
		OpenMessageWindow(sErrorMessage,BTN_OPTIONS_OK,300,200);	
	}
}

function ShowNextPage(iStartIndex)
{
	iPagingIndex = iStartIndex ; 
	
	DisplayWaitMessage();
	
	window.setTimeout(ShowNextPageProcess,600);
}

function ShowNextPageProcess()
{
	var sErrorMessage = "";
	var arrReturnParams = new Array();
	var arrParams = new Array(); 
	
	if(arrSearchCriteria == null)
		return;
		
	arrParams[0] = arrSearchCriteria[0];
	arrParams[1] = arrSearchCriteria[1]; 
	arrParams[2] = arrSearchCriteria[2];
	arrParams[3] = arrSearchCriteria[3]; 
	arrParams[4] = arrSearchCriteria[4];
	arrParams[5] = iPagingIndex;
	
	sErrorMessage = XMLRPC("CBureauLocateUI","LocateBureau",arrParams,arrReturnParams,"Taldor.Taasuka.UI","Taldor.Taasuka.UI.dll");
	
	HideWaitMessage();

	if (sErrorMessage == "")
	{
		document.getElementById("tdResults").innerHTML = arrReturnParams[0];
		
		//Set paging index
		document.getElementById("htnCurrentIndex").value = iPagingIndex;
	}
	else if(sErrorMessage == "-1")
	{
		document.location.href = ERROR_MESSAGE_PAGE ; 
	}
	else
	{
		OpenMessageWindow(sErrorMessage,BTN_OPTIONS_OK,300,200);
	}
}

function TableClicked(e)
{
	if(IsEnterClicked(e))
	{
		document.getElementById("_ctl0_btnLocate").click();
	}
}

function EnableDisableCities()
{
	if(document.getElementById("_ctl0_rbSearchByBureauCity").checked)
	{
		document.getElementById("_ctl0_ddlBureauAddress_txtAutoComplete").disabled = false;
		
		document.getElementById("_ctl0_ddlCity_txtAutoComplete").disabled = true;
		document.getElementById("_ctl0_ddlCity_txtAutoComplete").value = "";
		document.getElementById("_ctl0_ddlCity_ddlAvailableOptions").value = 0;
	}
	else if(document.getElementById("_ctl0_rbSearchByCity").checked)
	{
		document.getElementById("_ctl0_ddlBureauAddress_txtAutoComplete").disabled = true;
		document.getElementById("_ctl0_ddlBureauAddress_ddlAvailableOptions").value = 0;
		document.getElementById("_ctl0_ddlBureauAddress_txtAutoComplete").value = "";
		document.getElementById("_ctl0_ddlCity_txtAutoComplete").disabled = false;
	}
}
