function CheckIfEmpty(id,text,id_autocomplete)
{
	id = document.getElementById(id);
	autocomplete = document.getElementById(id_autocomplete);
	
	if (id.value == '')
	{
		id.value = text;
		autocomplete.style.display = 'none';
		
	}
}

function open_div(id)
{
	var div2 = document.getElementById(id);
	
	if (div2.style.display == 'none')
		div2.style.display = 'block';
	else
		div2.style.display = 'none';	
}

function change_ads(type)
{

	if (type == 0)
		var city = document.getElementById("cityS");
	else
		var city = document.getElementById("cityD");

	if (city.value == '' || city.value != 'עיר')
	{
		var path="";
		var myAjax = new Ajax.Request(
			path+'ajax/getAreaIdByCity.php?city='+city.value,
			{
				method: 'get', 
				onComplete: function(response) {
					dcReloadMapot(response.responseText);
				}
			}                    
		);
	}
}

function get_text(type){

	if (type == 0)
	{
		var city = document.getElementById("cityS").value;
		var address = document.getElementById("streetS").value;
		var homenum = document.getElementById("houseNumberS").value;
	}
	else
	{
		var city = document.getElementById("cityD").value;
		var address = document.getElementById("streetD").value;
		var homenum = document.getElementById("houseNumberD").value;
	}
		
	if (city == "עיר")
		city = 'ישראל';
	if (address == "רחוב")
		address = '';
	
	if( !city || city=="ישראל" )
	{	
		document.getElementById("h1_city").innerHTML = "מפת " + city
		document.getElementById("city_text").innerHTML = ".הגעת למפה של  "+city+". כאן ניתן למצוא מסלולי נסיעה ב"+city+", ולבצע חיפוש על מנת למצוא את נקודת היעד שלך או לצפות במסלול הנסיעה שלך";	
	}
	else if (city && address)
	{
		document.getElementById("h1_city").innerHTML = "מפת " + city;
		document.getElementById("city_text").innerHTML = "למטה מצורפת מפת הרחובות הסמוכים לכתובת "+address+" "+homenum+"  ב"+city+". באפשרותך לבצע חיפוש לנקודת יעד בעיר ולצפות במסלול הנסיעה הקצר ביותר ליעדך";
	}
	else
	{	//if ( city ){
		document.getElementById("h1_city").innerHTML = "מפת " + city;
		document.getElementById("city_text").innerHTML = ".למטה מצורפת מפת הרחובות ב"+city+". באפשרותך לבצע חיפוש לנקודת יעד בעיר ולצפות במסלול הנסיעה הקצר ביותר ליעדך";
	}
	
	if (city == "ישראל" || city == "עיר")
		city = '';
	
	document.getElementById("yad1_ads").src="http://maps.yad2.co.il/innerYad1.php?City="+city;
	var city_txt = '';
	url="http://www.yad2.co.il/Nadlan/rent.php";
	
	if( city ){
		url=url+"?City="+city;
		 city_txt = " ב" + city;
	}
		if(url) {
			document.getElementById("yad2_rent").href=url;
			if(document.all)
				document.getElementById("yad2_rent").innerText="דירות להשכרה"+city_txt;
			else
				document.getElementById("yad2_rent").textContent="דירות להשכרה"+city_txt;
			
			document.getElementById('yad2_city').innerHTML = city_txt;
		}
 
		url="http://www.yad2.co.il/Nadlan/sales.php";
		if( city ){
			url=url+"?City="+city;
			city_txt =" ב"+city;
		}
		if(url) {
				document.getElementById("yad2_sales").href=url;
			if(document.all)
				document.getElementById("yad2_sales").innerText="דירות למכירה"+city_txt;
			else
				document.getElementById("yad2_sales").textContent="דירות למכירה"+city_txt;
			
			document.getElementById('yad2_city').innerHTML = city_txt;
		}

		address = document.getElementById("streetS").value;
		city_link = city.replace(/ /g, "+");
		address_link = address.replace(/ /g, "+");
		
		if (address == "")
			document.getElementById("breadcrumbs").innerHTML = '> <a id="bread_path" class="location" href="http://maps.yad2.co.il/מפת+'+city_link+'" style="color:#FF6600;">מפת '+city+'</a>';
		else
		{
			document.getElementById("breadcrumbs").innerHTML = '> <a id="bread_path" class="location" href="http://maps.yad2.co.il/מפת+'+city_link+'" style="color:#FF6600;">מפת '+city+'</a>';
			document.getElementById("breadcrumbs").innerHTML = document.getElementById("breadcrumbs").innerHTML + ' > <a id="bread_path" class="location" href="http://maps.yad2.co.il/מפת+'+city_link+'+רחוב:+'+address_link+'" style="color:#FF6600;">רחוב '+address+'</a>'
		}
}

function openWindow(URL, winName, width, height){

		if(height=='' || !height)
		height=screen.height/2
		height_factor = ((screen.height/100)*85)
		if(height>=height_factor)
			height=height_factor;

 
		if(width=='' || !width)
			width=screen.width/2
		width_factor = ((screen.width/100)*95)
		if(width>=width_factor)
			width=width_factor;

		var top=((screen.height-height)/2)-(screen.height/20)
		var left=(screen.width - width) / 2 ;

			win=window.open(URL, winName, 'toolbar=no,location=no,directories=no,status=0,menubar=no,scrollbars=yes,resizable=1,copyhistory=no,width='+width+',height='+height+',top='+top+',left='+left+'');
			win.focus();
	}
	
	function changeButtonBG(id,img)
	{
		newImage = "url(http://maps.yad2.co.il/images/" + img + ")";
		document.getElementById(id).style.backgroundImage = newImage;
	}
	
	Image1= new Image(132,64)
	Image1.src = "http://maps.yad2.co.il/images/show_address_b.png";

	Image2= new Image(132,64)
	Image2.src = "http://maps.yad2.co.il/images/show_destination_b.png";
	
	Image3= new Image(132,64)
	Image3.src = "http://maps.yad2.co.il/images/show_address.png";

	Image4= new Image(132,64)
	Image4.src = "http://maps.yad2.co.il/images/show_destination.png";
	
	
	function getMonthStr(month)
	{
	
		var d=new Date()
		var month=new Array(12);
		
		month[0]="January";
		month[1]="February";
		month[2]="March";
		month[3]="April";
		month[4]="May";
		month[5]="June";
		month[6]="July";
		month[7]="August";
		month[8]="September";
		month[9]="October";
		month[10]="November";
		month[11]="December";
	
		return month[d.getUTCMonth()]; 
	}
	
	function LoadLeftBanner()
	{		
		var clientWidth = document.body.clientWidth;
		
		if (clientWidth >= 1230)
		{
			document.getElementById("GamboBanner").style.top = "0px";  
			document.getElementById("GamboBanner").style.left = "0px";
			document.getElementById("GamboBanner").style.display = "inline";
		}
		else
		{   
			document.getElementById("GamboBanner").style.display = "none"; 
		}
		
		setCookie();
	}
	
	function setCookie()
	{
	
		var the_cookie1 = "CLIENT_WIDTH_DIR=" + escape(document.body.clientWidth);
		var the_cookie2 = "MAIN_WIDTH_DIR=" + escape(document.body.clientWidth);
		var d = new Date();
		var the_date = new Date(getMonthStr(d.getUTCMonth())+", 2099");
		var Expiration_Date = "expires=" + the_date.toGMTString();
		var the_path="../../";
		var the_domain = ".yad2.co.il";
	
		document.cookie = the_cookie1 + ";" + the_path + ";" + the_domain + ";" + the_path + ";" + Expiration_Date;
		document.cookie = the_cookie2 + ";" + the_path + ";" + the_domain + ";" + the_path + ";" + Expiration_Date;
	
	}
