function SetTabIndex()
{	
    try
    {
		setTabs(document.getElementById('HeaderTD'));
		setTabs(document.getElementById('FirstGovBreadcrumbControlTD'));
		setTabs(document.getElementById('RightBarTable'));
		document.getElementById('searchByAddress').tabIndex = tabCounter;
		tabCounter ++;
		document.getElementById('searchByHalka').tabIndex = tabCounter;
		tabCounter ++;
		setTabs(document.getElementById('findAddress'));
		setTabs(document.getElementById('findParcel'));
		setTabs(document.getElementById('ResultTD'));
		setTabs(document.getElementById('TextTD'));
		setTabs(document.getElementById('LeftDT'));
		setTabs(document.getElementById('footerTD'));
     }
     
     
    catch(e)
    {
		
    }

}

function setTabs(node)
{ 
	if(node != null)
	{
	
	
    var objChildNodes= node.childNodes;
    for (var j=0;j<objChildNodes.length;j++)
    {
        if(objChildNodes.length > 0)
        {
            setTabs(node.childNodes[j])
           
        }
    }
    if(node.nodeName == 'INPUT' || node.nodeName == 'SELECT' || node.nodeName == 'A' || node.nodeName == 'OBJECT' || node.nodeName == 'AREA')
    {
        if(node.getAttribute('tabindex') != -1)
        {
            var oCurrentObject = node;
            var oAttributes = oCurrentObject.attributes;
            var namedItem = document.createAttribute("tabindex");
            namedItem.value = tabCounter;
            oAttributes.setNamedItem(namedItem);
            tabCounter++;
        }   
     }
     }
}

function displayNotify()
{
	document.getElementById('waitNotify').style.display="inline";
}
function closeNotify()
{
	document.getElementById('waitNotify').style.display="none";
}
function closeMapiResult(divId)
{
	document.getElementById(divId).style.display="none";
	if(document.getElementById('input_citySelectBox') != null)
	{
		document.getElementById('input_citySelectBox').focus();
	}
}
function checkValid()
{	
	//set current search to search by address
	document.getElementById('hiddenState').value = 0;
var browser=navigator.appName;

	if(browser == 'Netscape')
	{
		if (document.getElementById('ddlCity').selectedIndex == 0)
		{
			alert("אנא בחר/י שם ישוב מהרשימה");
			return false;			
		}
		if (document.getElementById('ddlStreet').selectedIndex == 0)
		{
			alert(" אנא בחר/י שם רחוב מהרשימה");
			return false;
		}
	}	
	else
	{
		if (document.getElementById('hiddenInputCityVal').value=='#' || document.getElementById('hiddenInputCityVal').value=='' || document.getElementById('input_citySelectBox').value=='#' || document.getElementById('input_citySelectBox').value=='' )
		{
			alert("אנא בחר/י שם ישוב מהרשימה");
			//var tempDdlStreets = document.getElementById('ddlStreets');
			//tempDdlStreets.reset();
			//tempDdlStreets.value = "";
			CleanControls();
			return false;			
		}
		if (document.getElementById('hiddenInputStreetVal').value=='#' ||document.getElementById('hiddenInputStreetVal').value=='' || document.getElementById('input_ddlStreets').value=='#' || document.getElementById('input_ddlStreets').value=='')
		{
			alert(" אנא בחר/י שם רחוב מהרשימה");
			document.getElementById('txtHouseNumber').value ="";
			document.getElementById('hiddenInputStreetVal').value = "";
			return false;
		}	
	}

	var txtHouseNumBox = document.getElementById("txtHouseNumber");	
	var houseNumberVal = txtHouseNumBox.value;
	
	if(houseNumberVal == "") 
	{
		//txtHouseNumBox.className="invalid_field";
		alert("עליך להזין מספר בית");
		//txtHouseNumBox.focus();
		txtHouseNumBox.value ="";
		return false;
	}
	if((houseNumberVal.indexOf('.')) > 0 ) 
	{
		//txtHouseNumBox.className="invalid_field";
		alert("מספר בית אינו חוקי");
		//txtHouseNumBox.focus();
		txtHouseNumBox.value ="";
		return false;
	}
	else
	{
		// also - dont see the previous results divResult
		var resultDiv = document.getElementById('result');
		if(resultDiv != null)
		{
			resultDiv.style.display="none";		
		}		
		
		// also - dont see the noResultsMessage Row result
		var noResultTr = document.getElementById('tr_noResults');
		
		
		if(noResultTr != null)
		{
			noResultTr.style.display="none";		
		}			
		//clean last search at gush/halka search
		CleanControls2();
		
		displayNotify();
	
		
		var theCity =  document.getElementById('hiddenInputCityTxt').value;
		var theStreet =  document.getElementById('hiddenInputStreetTxt').value;
		
		 document.getElementById('hiddeCityName').value = theCity;
		 document.getElementById('hiddeStreetName').value = theStreet;
		 document.getElementById('HouseNumber').value = houseNumberVal;
		__doPostBack('lnkBtnSearch','');
		
	}	
}
function changeImage(buttonName,imageName)
{
	document.images[buttonName].src= "/firstgov/Images/he/search/"+imageName+".gif";
	return true;
}
function CleanControls()
{
					
	var browser=navigator.appName;
	if(browser == 'Netscape')
	{

					
		document.getElementById('ddlCity').selectedIndex  = 0;
		document.getElementById('ddlStreet').selectedIndex = 0;
		}
	else
	{
		document.getElementById('citySelectBox').reset();
		document.getElementById('ddlStreets').reset();
		FiilCitiesXML();
		document.getElementById('citySelectBox').DataArr = myDataArr;
		citySelectBox.DataBind();
	}
	
	document.getElementById('txtHouseNumber').value ="";
	document.getElementById('hiddenInputCityVal').value=""
	document.getElementById('hiddenInputStreetVal').value = "";
		
}
function CleanControls2()
{
	document.getElementById('txtParcel').value ="";
	document.getElementById('txtGushNumber').value ="";	
}
function checkValidParcelGush()
{
	var parcel = document.getElementById('txtParcel');
	var gush = document.getElementById('txtGushNumber');
	
	
	
	if(isNaN(gush.value) && isNaN(parcel.value))
	{	
		alert("אנא הקלד מספרים בלבד בשדות מספר גוש ומספר חלקה");
		return false;
	}
	
	if (!/\d+/gi.test(gush.value)&& gush.value=="" && !/\d+/gi.test(parcel.value) && parcel.value=="" )
	{
		alert("עליך להזין מספר גוש ומספר חלקה");
		//gush.className="invalid_field";
		return false;
	}
	
	if (!/\d+/gi.test(gush.value)&& gush.value=="" && isNaN(parcel.value) )
	{
		alert("עליך להזין מספר גוש ואנא הקלד מספרים בלבד בשדה מספר חלקה");
		//gush.className="invalid_field";
		return false;
	}
	
	if (!/\d+/gi.test(parcel.value) && parcel.value=="" && isNaN(gush.value) )
	{
		alert("עליך להזין מספר חלקה ואנא הקלד מספרים בלבד בשדה מספר גוש");
		//gush.className="invalid_field";
		return false;
	}
	
	
	if(isNaN(gush.value))
	{	
		alert("אנא הקלד מספרים בלבד בשדה מספר גוש");
		return false;
	}
	if(isNaN(parcel.value))
	{	
		alert("אנא הקלד מספרים בלבד בשדה מספר חלקה");
		return false;
	}

	if (!/\d+/gi.test(gush.value) && gush.value=="" )
	{
		//alert("עליך להזין מספר גוש");
		//gush.className="invalid_field";
		return false;
	}
	
	if (!/\d+/gi.test(parcel.value) && parcel.value=="" )
	{
		alert("עליך להזין מספר חלקה");
		return false;
	}
	
	

		// also - dont see the previous results div result
		var resultDiv = document.getElementById('result');
		if(resultDiv != null)
		{
			resultDiv.style.display="none";		
		}			
		// also - dont see the noResultsMessage Row result
		var noResultTr = document.getElementById('tr_noResults');
		if(noResultTr != null)
		{
			noResultTr.style.display="none";		
		}					
		displayNotify();
		//set current search to search by GUSH/HALKA
		document.getElementById('hiddenState').value = 1;	
		
		
		__doPostBack('lnkSerchAddress','');
}

function checkValidGush()
{
	var gush = document.getElementById('txtGushNumber');
	
	if(isNaN(gush.value))
	{	
		alert("אנא הקלד מספרים בלבד בשדה מספר גוש");
		return false;
	}
	
	if (!/\d+/gi.test(gush.value)&& gush.value=="" )
	{
		alert("עליך להזין מספר גוש");
		//gush.className="invalid_field";
		return false;
	}
}
function checkValidParcel()
{
	var parcel = document.getElementById('txtParcel');
	
	if(isNaN(parcel.value))
	{	
		alert("אנא הקלד מספרים בלבד בשדה מספר חלקה");
		return false;
	}
	
	if (!/\d+/gi.test(parcel.value) && parcel.value =="")
	{
		alert("עליך להזין מספר חלקה");
		return false;
	}
}

function setaction()
{
	document.forms[0].action="/firstGov/Templates/MapiNewAddressSearch.aspx";
//	alert(document.forms[0].action);	
}

function setCurrentSearch()
{
	// set tabs + searchImg + table...

	var status =  document.getElementById('hiddenState').value;		
	if(status == 0)
	{	
		//search by address
		document.getElementById('hiddenState').value = 1;
		document.getElementById('findAddress').style.display ="none";
		document.getElementById('findParcel').style.display ="inline";
		//change table
		var table_Add = document.getElementById('spanTableSearchByAddress');
		if(table_Add != null)
		{
			table_Add.style.display = 'block';				
		}
		var table_Halka = document.getElementById('spanTableSearchByHalka');
		if(table_Halka != null)
		{
			table_Halka.style.display = 'none'; 	
		}		
		//change titles
		var title = document.getElementById('searchByAddress');
		if(title != null)
		{
			title.className = 'tabAddress_on';
		}
		title = document.getElementById('searchByHalka');
		if(title != null)
		{
			title.className = 'tabHalka_off';
		}
		/*var item = document.getElementById('searchImg');	
		if (item != null)
		{
			item.className = 'searchImgByAddress';
		}*/
	}
	else
	{
		//search by gush/halke
		document.getElementById('findAddress').style.display ="inline";
		document.getElementById('findParcel').style.display="none";
		document.getElementById('hiddenState').value = 0;	
		//change tables		
		var table_Add = document.getElementById('spanTableSearchByAddress');		
		if(table_Add != null)
		{
			table_Add.style.display = 'none';				
		}
		var table_Halka = document.getElementById('spanTableSearchByHalka');
		if(table_Halka != null)
		{
			table_Halka.style.display = 'block'; 
		}
		//change titles
		title =	document.getElementById('searchByAddress');
		if(title)
		{
			title.className = 'tabAddress_off';
		}
		title = document.getElementById('searchByHalka');
		if(title)
		{
			title.className = 'tabHalka_on';
		}
		/*item = document.getElementById('searchImg');	
		if(item != null)
		{
			item.className = 'searchImgByGush';
		}*/
	}
}
//take search fields (search by gush/halka) - and open in new window the buy link


function buyMap()
{
	var city_name = document.getElementById('hiddeCityName').value;
	var street_name = document.getElementById('hiddeStreetName').value;
	var house_number = document.getElementById('HouseNumber').value;
	
	//get form : buy_map
	
	var buy_map_address = document.forms[2]; //document.getElementById('buy_map_address');
	
	//Search 
	
	buy_map_address.city.value = city_name;
	buy_map_address.street.value = street_name;
	buy_map_address.houseNumber.value = house_number;
	
	buy_map_address.submit();
}

//change tables when user click
function ChangeType(element)
{

	if(element.id == 'searchByAddress')
	{
		//change titles
		element.className = 'tabAddress_on';
		var type = document.getElementById('searchByHalka');
		type.className = 'tabHalka_off';
		item1 = document.getElementById('searchImg');	
		/*item1.className = 'searchImgByAddress';*/
		
		//change tables
		
		var table_Add = document.getElementById('spanTableSearchByAddress');
		table_Add.style.display = 'block';				
		var table_Halka = document.getElementById('spanTableSearchByHalka');
		table_Halka.style.display = 'none'; 
		
		document.getElementById('findAddress').style.display ="none";
		document.getElementById('findParcel').style.display="inline";
		document.getElementById('hiddenState').value = 1;	
		
		//make textBox focus
		//if(document.getElementById('input_citySelectBox') != null)
		//{
		//	document.getElementById('input_citySelectBox').focus();
		//}
		
	}
	else 
	{	
		
		//change titles
	
		element.className = 'tabHalka_on';		
		var item1 = document.getElementById('searchByAddress');	
		item1.className = 'tabAddress_off';		
		item1 = document.getElementById('searchImg');	
		/*item1.className = 'searchImgByGush';*/
		
		
		//change tables		
		var table_Add = document.getElementById('spanTableSearchByAddress');		
		table_Add.style.display = 'none';				
		var table_Halka = document.getElementById('spanTableSearchByHalka');
		table_Halka.style.display = 'block'; 
		
		document.getElementById('findAddress').style.display ="inline";
		document.getElementById('findParcel').style.display="none";
		document.getElementById('hiddenState').value = 0;	
		
		//make textBox focus
		//if(document.getElementById('txtGushNumber') != null)
		//{
		//	document.getElementById('txtGushNumber').focus();
		//}		
	}	
}

// when radio btn is chosen 
//	- update hiddeCityName, hiddeStreetName,HouseNumber
//	- change button (btnBuy) to able from disable (and deals with 'onmouseover' and 'onmouseover')
//  - give uniqe cssClass to selected row (dont forget the others row to move to default cssClass - var lastRowIdSelected )
// when onclick button (btnBuy)
//	- send city_name,street_name,house_number to btn
function switchBuyButton(city_name,street_name,house_number,trId)
{
//alert("switchBuyButton");
	var td_btn_buy = document.getElementById('btnBuy');
	td_btn_buy.className = 'btn_off';
	td_btn_buy.onclick = function()
		{
			buyMap();
		}
	td_btn_buy.onmouseover = function()
		{		
				td_btn_buy.className = 'btn_on';	
		}
	td_btn_buy.onmouseout = function()
	{		
		td_btn_buy.className = 'btn_off';	
	}
		
	// give selected row - a uniqe cssClass
	var trSelected = document.getElementById(trId);
	trSelected.className = 'trTableResultRowSelectd';	
	
	
	//last row that was chosen - return its cssClass to default;
	var trLastSelected = document.getElementById(lastRowIdSelected);
	
	if(trLastSelected != null && lastRowIdSelected != trId )
	{
		trLastSelected.className = 'trTableResultRowNotSelectd';
	}	
	
	lastRowIdSelected = trId;
	
	
	// update hide textBox
	document.getElementById('hiddeCityName').value = city_name;
	document.getElementById('hiddeStreetName').value = street_name;
	document.getElementById('HouseNumber').value = house_number;
}
	
	// mozilla postback bug fix [guy, 21/2/06]
	window.onload = function() {
		__CMS_PostbackForm = document.getElementsByTagName("FORM")[0];
		__CMS_PostbackForm.action = __CMS_CurrentUrl;	
	}
   
// -->
function TabooWatch()
{
 var taboo_url="<%=TabooUrl%>";
 var gushNum = document.getElementById('lblGush').innerHTML;
 var helkaNum = document.getElementById('lblParcel').innerHTML;
 taboo_url=taboo_url+'&gushNum='+gushNum+'&helkaNum='+helkaNum;
 window.open(taboo_url,'Yulia','menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes,resizable=yes');
}


function openExMap() 
{
	var imagePath = "/FirstGov/Images/he/mapi/mapa_normal.gif";
	var winTitle = "מפה לדוגמה"; // popup title 
	var width = "620"; // popup width 
	var height = "520"; // popup height 
	var	windowProperties = 'height='+height+',width='+width+',scrollbars=no';
	
	newWin = window.open('/FirstGov/Images/he/mapi/mapa_normal.gif', 'myWin', 'toolbar=no, directories=no, location=no,  status=yes, menubar=no, resizable=no, scrollbars=no,  width=650, height=550'); 
	newWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>מפה לדוגמה</title></head><body><Map Name=MyMap><area alt="סגור" coords="13,470,58,489" href="#" onclick="window.close()"></Map><img src="'+"/FirstGov/Images/he/mapi/mapa1.jpg"+ '" USEMAP="#MyMap" width="618" height="500" border=0><div style="position: absolute;left:345;top:27;width:320;height:245"><div></body></html>');
}

		
		/* this function restore the selected items */
		function readFromTextBox(tb, contID)
		{
			//alert(tb.id);
			var indexSelected=tb.value;
			var tbID=tb.id;
			temp=contID.id+"_AuthoringModeControlsContainer_tBox";
			tbID=tbID.substring(temp.length+3,temp.length);//holds only the textBox Id number 
			
			//get the hidden textBox			
			var hiddenTB=document.getElementById(contID.id+'_AuthoringModeControlsContainer_txtHiddenXmlString');
			hiddenTBSplit=new Array();
			hiddenTBSplit=hiddenTB.value.split('#');
			//insert the number into the array in the tbId place
			hiddenTBSplit[tbID]=indexSelected; 
			//insert the selected number back to the hidden textBox and return the '#'
			var str="";
			for (i=0; i<hiddenTBSplit.length; i++)
			{
				str+=hiddenTBSplit[i]+"#";
			}
			//alert(str);
			
			str=str.substring(0,str.length-1); //remove the last "#"
			document.getElementById(contID.id+'_AuthoringModeControlsContainer_txtHiddenXmlString').value = str;
						
		}
		
		


