
var IGAZIROOT='http://pentimo.com/'
if (window.location.hostname=='ubuntu') 
  var IGAZIROOT='http://ubuntu/pentimo2/'

// Cross-browser event listener
function listenForEventIn(obj,type,func,bubble) {
	if (obj.addEventListener) {
	obj.addEventListener(type,func,bubble); // For Presto and Gecko
	}
	else if ( obj.attachEvent ) {
	obj.attachEvent("on" + type, func); // For Trident
	}
}
// Window.onload
function csakszam(e)  {
   var k;
   if (e.charCode)	{
	 k = e.charCode; 
	 }
   else if (e.keyCode)	{
	 k = e.keyCode; // For Presto
	 }
   if (k != 37 && k != 38 && k != 39 && k != 40 && k != 35 && k != 46 && k != 8 && k != 36 && k != 9 && k != 13 && k != 45 )  {
	 if ( k < 47 || k > 57 ) {
	   if ( e.preventDefault )  {
		 e.preventDefault(); // For Presto and Gecko
		 }
	   else {
		 e.returnValue=false; // For Trident
	   }
	 }
	}
}
function csakszamesenter(e)  {
   var k;
   if (e.charCode)	{
	 k = e.charCode; 
	 }
   else if (e.keyCode)	{
	 k = e.keyCode; // For Presto
	 }
  if (k != 37 && k != 38 && k != 39 && k != 40 && k != 35 && k != 46 && k != 8 && k != 36 && k != 9 && k != 45 )  {
	 if ( k < 47 || k > 57 ) {
	   if ( e.preventDefault )  {
		 e.preventDefault(); // For Presto and Gecko
		 }
	   else {
		 e.returnValue=false; // For Trident
	   }
	 }
	}
  if (k===13) Web_ID_Search();
}

function intvalid (num) {
  var szam=num.value;
  i=szam.indexOf(".",0);	   
  if (i!=-1) {
     szam=szam.substring(0,i);	  
     num.value=szam;
  }
  var  n='';
  for (var x=0; x<szam.length; x++) {
    if (!isNaN(parseInt(szam.charAt(x)))) {
	   n=n+szam.charAt(x);
	}
  }
  num.value=n;
//  for (var x=0; x<n.length; x++) {
//   if (isNaN(parseInt(n[x]))) {
//      alert ('Only positive integer is allowed ! I think '+num.value+' is not a positive integer ! (but not sure :-))');
//      num.value="";  
//	  break;
//	}
//  }
}

function js_newlocation(l) {
alert(l);
location=l;
}

// EZTET en raktam ide, ez szkrollogtatja a DIVET

scrollStep=2

timerUp=""
timerDown=""

function toTop(id){
document.getElementById(id).scrollTop=0
}

function scrollDivDown(id){
clearTimeout(timerDown) 
document.getElementById(id).scrollTop+=scrollStep
timerDown=setTimeout("scrollDivDown('"+id+"')",10)
}

function scrollDivUp(id){
clearTimeout(timerUp)
document.getElementById(id).scrollTop-=scrollStep
timerUp=setTimeout("scrollDivUp('"+id+"')",10)
}

function toBottom(id){
document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight
}

function stopMe(){
clearTimeout(timerDown) 
clearTimeout(timerUp)
}

// na es itt a vege

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// ezt megin en raktam ide, tooltip

var tooltip=function(){
	var id = 'tt';
	var top = 0;
	var left = 0;
	var maxw = 500;
	var speed = 60;
	var timer = 60;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w,ttleft,tttop){
			if (ttleft == null) {left = 20;} else {left = ttleft;}
			if (tttop == null) {top = -50;} else {top = tttop;}
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
		// For IE6 compatibity - nick 22/08/2008 11:32
		var u = 0, l = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				u = window.pageYOffset;
				l = window.pageXOffset;
				} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
					//DOM compliant
					u = document.body.scrollTop;
					l = document.body.scrollLeft;
					} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
						//IE6 standards compliant mode
						u = document.documentElement.scrollTop;
						l = document.documentElement.scrollLeft;
					}
		u = ie ? event.clientY + u : e.pageY;
		l = ie ? event.clientX + l : e.pageX;
		tt.style.top = (u - h) + 'px';
		tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

// itt a toooltip vege


//--------------------------------------------------FORM.JS----------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------//

test=false;

var xmlHttp;

function GetXmlHttpObject() {
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
	try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support HTTP Request !");
      return false;
      }
	}  
  }
return xmlHttp;
}

function showTime()   {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    if (xmlHttp.responseText=='login')
      alert ('You have to log in for this service !');
	if (xmlHttp.responseText) {
      if (document.getElementById('ID_fav'+xmlHttp.responseText).className=='myitem') {
        document.getElementById('ID_fav'+xmlHttp.responseText).className='fav1';
        document.getElementById('ID_fav'+xmlHttp.responseText).title='Add to watch list';
	    alert ('It has been deleted from watch list !');
	    }
	   else {
	    document.getElementById('ID_fav'+xmlHttp.responseText).className='myitem';
        document.getElementById('ID_fav'+xmlHttp.responseText).title='Clear from watch list';
	    alert ('It has been inserted to watch list !');
	  }
	  }
	 else {
	  alert ('Watch list update is failed !');
	}
  }  
}

function runphp(phpName) {
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
   return;
 xmlHttp.onreadystatechange=showTime;
 xmlHttp.open("GET",phpName,true);
 xmlHttp.send(null);
}

function active_response()   {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    if (xmlHttp.responseText=='login')
      alert ('You have to log in for this service !');
	if (xmlHttp.responseText) { 
      if (document.getElementById('ID_status'+xmlHttp.responseText).innerHTML=='Suspend') {
		document.getElementById('ID_DIV_status_text'+xmlHttp.responseText).innerHTML='SUSPENDED';
        document.getElementById('ID_status'+xmlHttp.responseText).innerHTML='Activate';
        document.getElementById('ID_status'+xmlHttp.responseText).title='ACTIVATE This Ad';
	    document.getElementById('ID_DIV_status_text'+xmlHttp.responseText).className='status_S';
        document.getElementById('ID_relist'+xmlHttp.responseText).style.display="none";
		alert ("It has been suspended !");
	    }
	   else {
		document.getElementById('ID_DIV_status_text'+xmlHttp.responseText).innerHTML='ACTIVE';
        document.getElementById('ID_status'+xmlHttp.responseText).innerHTML='Suspend';
        document.getElementById('ID_status'+xmlHttp.responseText).title='SUSPEND This Ad';
	    document.getElementById('ID_DIV_status_text'+xmlHttp.responseText).className='status_A';
        document.getElementById('ID_relist'+xmlHttp.responseText).style.display="inline";
	    alert ('It has been activated !');
	  }
	 }
	 else {
	  alert ('Item status update is failed !');
	}
  }  
}

function run_php_active (phpName) {
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
   return;
 xmlHttp.onreadystatechange=active_response;
 xmlHttp.open("GET",phpName,true);
 xmlHttp.send(null);
}


function delete_response()   {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    if (xmlHttp.responseText=='login')
      alert ('You have to log in for this service !');
	if (xmlHttp.responseText) {
	    document.getElementById('ID_DIV_van_tetel_'+xmlHttp.responseText).style.display="none";
		alert (xmlHttp.responseText+" item has been deleted !");
    }
    else {
	  alert ('Item delete is failed !');
	}
  }
}

function run_php_delete (phpName) {
 if (confirm (' Are you sure to delete item(s) ? ')) {
   xmlHttp=GetXmlHttpObject();
   if (xmlHttp==null)
     return;
   xmlHttp.onreadystatechange=delete_response;
   xmlHttp.open("GET",phpName,true);
   xmlHttp.send(null);
 }
}

function relist_response()   {
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//	alert (xmlHttp.responseText);
    if (xmlHttp.responseText=='login')
      alert ('You have to log in for this service !');
	if (xmlHttp.responseText) {
	    document.getElementById('ID_DIV_van_tetel_'+xmlHttp.responseText).style.display="none";
		alert (xmlHttp.responseText+" item has been relisted !");
    }
    else {
	  alert ('Item relist is failed !');
	}
  }
}

function run_php_relist (phpName) {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      return;
    xmlHttp.onreadystatechange=relist_response;
    xmlHttp.open("GET",phpName,true);
    xmlHttp.send(null);
}

function setmailalert_response()   {
//  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//      alert (xmlHttp.responseText);
//  }
}

function run_php_setmailalert (phpName) {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      return;
    xmlHttp.onreadystatechange=setmailalert_response;
    xmlHttp.open("GET",phpName,true);
    xmlHttp.send(null);
}

function orderformvalidate()  {
  var errorstr=''; 
  if (document.contact.webid.value=='') 
     errorstr='You have to fill the Web.id field !';
  if (document.contact.phone.value=='')  
     errorstr='You have to fill the phone field !';
  if (errorstr.length>0) 
    alert (errorstr);	
  document.FV_returnValue = (errorstr == '');
}
function wantedformvalidate()  {
  var errorstr=''; 
  if (document.wantedform.Ititle.value=='') 
     errorstr='You have to fill the * fields ! (Title is empty)';
  if (document.wantedform.Idesc.value=='') 
     errorstr='You have to fill the * fields ! (Message is empty)';
  if (errorstr.length>0) {
    alert (errorstr);	
	}
	else {
	 mehet=confirm (' Are you sure to post this message ? ');
	}
  document.FV_returnValue = ((errorstr == '') && (mehet));
}

function itemformvalidate()  {
  var errorstr=''; 
  if (document.itemform.Ititle.value=='') 
     errorstr='You have to fill the * fields ! (Title is empty)';
  if (document.itemform.Iprice.value<1)  
     errorstr='You have to fill the * fields ! (Price is maybe too low :-))';
  if (document.itemform.Icity.value=='00')  
     errorstr='You have to fill the * fields ! (Select a city)';
  if (document.itemform.Icat.value=='00')  
     errorstr='You have to fill the * fields ! (Select a category)';
  if (errorstr.length>0) 
    alert (errorstr);	
  document.FV_returnValue = (errorstr == '');
}

function fitemformvalidate()  {
  var errorstr=''; 
 // alert(document.findform.Factive.checked);
  if (document.findform.Fminprice.value<0) 
     errorstr='Minimum price is too low !';
  if (Number(document.findform.Fminprice.value) > Number(document.findform.Fmaxprice.value)) 
     errorstr='Minimum price more than maximum price !';
  if (errorstr.length>0) 
    alert (errorstr);	
  document.FV_returnValue = (errorstr == '');
}
// feltölti a legördülö kista elemeit a kiválasztott város area-ival ha volt város változás
function madeSelection (r) {
    var selObj  = document.getElementById('ID_area');
    var selcity = document.getElementById('ID_city').options[document.getElementById('ID_city').selectedIndex].value;
	selObj.options.length = 0;   //mindig elöröl kezdjük a töltikét
    var x=0;
	while (x!=-1) { 	
      i=r.indexOf(":", x);	  //x poziciótól keres : -ot r szrtingben 
	  if (i==-1) break;       //ha nincs : kiszáll
	  s=r.substring(x,i);	  //s-be lerajkja a sztringet
	  x=i+1;                  //átugorjuk a kettös pontot    
	  var code=s;                 //remélhetöleg ez a area kódja

      i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var citycode=s;
	  
	  i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var areaname=s;
	  
      i=r.indexOf(":", x);	  //x poziciótól keres : -ot r szrtingben 
	  if (i==-1) break;       //ha nincs : kiszáll
	  s=r.substring(x,i);	  //s-be lerajkja a sztringet
	  x=i+1;                  //átugorjuk a kettös pontot    
	  var lat=s;                 //remélhetöleg ez a area kódja

      i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var lng=s;
	  
	  i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var zoom=s;

	  i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var polygon=s;

      if (test) 
	    qstr=areaname+'-'+citycode+'-'+code
	   else
	    qstr=areaname;
      if (selcity==citycode) { 
       if (typeof(window.clientInformation) != 'undefined') 
         selObj.add(new Option(qstr, code)); 
	    else
         selObj.add(new Option(qstr, code), null); 
	  }
	}
    selObj.selectedIndex=0;  
}

function changeArea (r) {
	if (polygon_overlay!='none') {
  	   map.removeOverlay(polygon_overlay);
	   polygon_overlay='none';
	}
	if (marker!='none') {
  	   map.removeOverlay(marker);
	   marker='none';
	}
    var selcity = document.getElementById('ID_city').options[document.getElementById('ID_city').selectedIndex].value;
    var selarea = document.getElementById('ID_area').options[document.getElementById('ID_area').selectedIndex].value;
    var x=0;
	while (x!=-1) { 	
      i=r.indexOf(":", x);	  //x poziciótól keres : -ot r szrtingben 
	  if (i==-1) break;       //ha nincs : kiszáll
	  s=r.substring(x,i);	  //s-be lerajkja a sztringet
	  x=i+1;                  //átugorjuk a kettös pontot    
	  var code=s;                 //remélhetöleg ez a area kódja

      i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var citycode=s;
	  
	  i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
      var areaname=s;

      i=r.indexOf(":", x);	  //x poziciótól keres : -ot r szrtingben 
	  if (i==-1) break;       //ha nincs : kiszáll
	  s=r.substring(x,i);	  //s-be lerajkja a sztringet
	  x=i+1;                  //átugorjuk a kettös pontot    
	  var lat=s;                 //remélhetöleg ez a area kódja

      i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var lng=s;
	  
	  i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var zoom=s;

	  i=r.indexOf(":", x);	   
	  if (i==-1) break;
	  s=r.substring(x,i);	  
	  x=i+1;    
	  var polygon=s;

      if ((selcity==citycode) && (selarea==code)) {
		 //alert (lat+'-'+lng+'-'+zoom); 
		if ((lat=='') || (lng=='')) {
		  lat=25.1963;
		  lng=55.2745;
		  zoom=8;
		}
	    map.setCenter(new GLatLng(lat,lng), eval(zoom));
		if (polygon!='') {
		  var encodedPoints = polygon; //"}fbxCc{roIzh@rp@f_B`tAop@b_Ay|Bm~AqOeWUyWju@mu@";
		  var encodedLevels = "B";
		  polygon_overlay = new GPolyline.fromEncoded({
								  color: "#FF0000",weight: 4,opacity: 0.4,points: encodedPoints,levels: encodedLevels,zoomFactor:32, numLevels: 4 });
		  map.addOverlay(polygon_overlay);
		}
	  break;
     }
	}
}

function showfilesfield (c) {
// document.getElementById('ID_pic'+c).value='';
 document.getElementById('ID_pic'+c).style.display="inline";
}
function hidefilesfield (c) {
// document.getElementById('ID_pic'+c).value='';
 document.getElementById('ID_pic'+c).style.display="none";
}

function HandOverDateShow () {
var status=document.getElementById('ID_DIV_handoverdate').style.display;
if (status=="none")
   status="inline"
  else 
   status="none"
document.getElementById('ID_DIV_handoverdate').style.display=status;
}

function calcegysar (s) {
if (document.getElementById('ID_cat').value!=s) { // nem NOSELLCAT tehát eladás vissza kell állni default-re
  document.getElementById('ID_price_prompt').innerHTML='Price*:';
  document.getElementById('ID_egysegar_field').value='';
  document.getElementById('ID_egysegar_prompt').innerHTML='';
  } 
else {
  var inputprice=document.getElementById('ID_price').value; 
  var term=document.itemform.Ipayment.value;
  evi=inputprice;
  havi=inputprice;

  if (term=='01') { evi=inputprice;     havi=inputprice*12;    } //yearly
  if (term=='02') { evi=inputprice/2;   havi=inputprice*6;     } //biyearly
  if (term=='03') { evi=inputprice/3;   havi=inputprice*4;     } //3 csekk
  if (term=='04') { evi=inputprice/4;   havi=inputprice*3;     } //qarterly
  if (term=='05') { evi=inputprice/5;   havi=inputprice*2.4;   } // 5 csekk
  if (term=='06') { evi=inputprice/6;   havi=inputprice*2;     } //2 havi 
  if (term=='07') { evi=inputprice/12;  havi=inputprice;       } //monthly
  if (term=='08') { evi=inputprice/52;  havi=inputprice/4.357; } //weekly
  if (term=='09') { evi=inputprice/365; havi=inputprice/30;    } //daily
  
  termcode=document.getElementById('ID_payment').options[document.getElementById('ID_payment').selectedIndex].value;
  termtext=document.getElementById('ID_payment').options[document.getElementById('ID_payment').selectedIndex].innerHTML;

//08=room   havi kell
  if (document.itemform.Itype.value=='08') {
	   document.getElementById('ID_DIV_sepabath').style.display="inline"; 
	   if (termcode=='00') termtext='Monthly';
	   document.getElementById('ID_price_prompt').innerHTML='Monthly Price:';
	   document.getElementById('ID_egysegar_field').value=Math.round(havi);
	 } 
    else {
      document.getElementById('ID_DIV_sepabath').style.display="none"; 
      document.getElementById('ID_sepabath').checked=false; 
	  if (termcode=='00') termtext='Yearly';
	  document.getElementById('ID_egysegar_field').value=Math.round(evi);
	  document.getElementById('ID_price_prompt').innerHTML='Yearly Price:';
  }
  if ((term=='01') || (term=='02') || (term=='03')|| (term=='04')|| (term=='05')|| (term=='06') )
    document.getElementById('ID_egysegar_prompt').innerHTML='1 Cheque:';
   else
    document.getElementById('ID_egysegar_prompt').innerHTML='Rent '+termtext+':';
}

}

function FreeHoldDivShowSet (s) {
var sel=document.getElementById('ID_cat').value; // ha 02 azaz rent akkor nem kell a freehold,offplan checkbox 
if (sel==s) {
   freehold="none";
   payment="inline";
  }
  else {
   freehold="inline";
   payment="none";
  }
document.getElementById('ID_DIV_freehold').style.display=freehold;
document.getElementById('ID_DIV_payment').style.display=payment;
document.getElementById('ID_DIV_handoverdate').style.display="none";
document.getElementById('ID_freehold').checked=true;
document.getElementById('ID_offplan').checked=false;
document.getElementById('ID_furnished').checked=false;
document.getElementById('ID_sepabath').checked=false; 
document.getElementById('ID_payment').value='00';
calcegysar(s);
}

function RoomsShow (s) {
var sel=document.getElementById('ID_type').value; // ha 02-nél nagyobb akkor nem kell a room,bathroom select 
var status=document.getElementById('ID_DIV_rooms').style.display;
if (sel>s)
   status="none"
  else 
   status="inline"
document.getElementById('ID_DIV_rooms').style.display=status;
document.getElementById('ID_rooms').value='00';
document.getElementById('ID_bathrooms').value='00';
}

function changeFeatcolor (c) {
if (document.getElementById('ID_DIV_check'+c).className=='textbluehoka')
   document.getElementById('ID_DIV_check'+c).className='textgreen';
  else
   document.getElementById('ID_DIV_check'+c).className='textbluehoka';
}



//--------------------------------------------------MAP.JS----------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------//

var test=false;
var map;
var is_marker = false;
var marker='none';
var polygon_overlay='none';


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function setloadevent(x,y,z,p) {
  addLoadEvent(map_initialize(x,y,z,p));
  if (window.attachEvent) {
        window.attachEvent("onunload", function() {
                GUnload();      // Internet Explorer
        });
   } else {
        window.addEventListener("unload", function() {
                GUnload(); // Firefox and standard browsers
        }, false);
  }
}  

function map_initialize(center_lat, center_lng, zoom_level, polygon) {
 //center_lat=25.077200666275154;
 //center_lng=55.140380859375;
 if (GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(center_lat, center_lng), eval(zoom_level));
  map.addControl(new GMapTypeControl());
  map.addControl(new GSmallMapControl());
  maplat=document.getElementById("ID_maplat").value;
  maplng=document.getElementById("ID_maplng").value;
  clickmarker_func =function(latlng) {
								  map.openInfoWindowHtml(latlng, "It's a property location ! It's nice place !");
						 	   }
  dragmarker_func = function(latlng) {     
 								       var marker_latitude=latlng.lat();
								       var marker_longitude=latlng.lng();
								       document.getElementById("ID_maplat").value=marker_latitude;
								       document.getElementById("ID_maplng").value=marker_longitude;
 								       //alert (marker_latitude+' kint '+marker_longitude);
								     }
  drg=false;
  if (document.getElementById("ID_mapdrg").value==true)
    drg=true
  if ((maplat!=0) && (maplng!=0)) {
	markerpoint=new GLatLng(maplat, maplng);
	marker = new GMarker(markerpoint, {draggable: drg})
    GEvent.addListener (marker, "click", clickmarker_func);
    GEvent.addListener(marker,"dragend", dragmarker_func);
    map.addOverlay(marker);
	is_marker=true;
  }
  
  setmarker_func = function(overlay, latlng) {     
                     if ( (latlng) && (document.getElementById("ID_mapdrg").value==true) ) { 
                       if (is_marker) {
                         map.removeOverlay(marker);
                       } 
                       drg=false;
      			       if (document.getElementById("ID_mapdrg").value==true)
					      drg=true
					   marker = new GMarker(latlng, {draggable: drg})
                       clickmarker_func =function(latlng) {
					                                       map.openInfoWindowHtml(latlng, "It's a property location ! It's nice place !");
					                                      }
					   dragmarker_func = function(latlng) {     
														   var marker_latitude=latlng.lat();
														   var marker_longitude=latlng.lng();
														   document.getElementById("ID_maplat").value=marker_latitude;
														   document.getElementById("ID_maplng").value=marker_longitude;
														   //alert (marker_latitude+'  bent '+marker_longitude);
														  }
					   GEvent.addListener (marker, "click",   clickmarker_func);
                       GEvent.addListener (marker, "dragend", dragmarker_func);
                       map.addOverlay(marker);
					   is_marker=true;
                       var marker_latitude=latlng.lat();
                       var marker_longitude=latlng.lng();
                       document.getElementById("ID_maplat").value=marker_latitude;
                       document.getElementById("ID_maplng").value=marker_longitude;
                       //alert (marker_latitude+'   '+marker_longitude);
                     }
                   };
  
    GEvent.addListener(map,"click", setmarker_func);
	if (polygon!=0) {
	  var encodedPoints = polygon; //"}fbxCc{roIzh@rp@f_B`tAop@b_Ay|Bm~AqOeWUyWju@mu@";
	  var encodedLevels = "B";
	  polygon_overlay = new GPolyline.fromEncoded({
							  color: "#FF0000",weight: 4,opacity: 0.4,points: encodedPoints,levels: encodedLevels,zoomFactor:32, numLevels: 4 });
	  map.addOverlay(polygon_overlay);
	}

 } 
}

function login_kell() {
	alert ("Please login first or register !");
}

function form_on(){
	document.getElementById('desc').style.display='none';
	document.getElementById('contact').style.display='none';
	document.getElementById('formcontactus').style.display='block';
	document.getElementById('formcontactus').style.visibility='visible';
}
function form_off(){
	document.getElementById('formcontactus').style.display='none';
	document.getElementById('formcontactus').style.visibility='hidden';
	document.getElementById('desc').style.display='block';
	document.getElementById('contact').style.display='block';
}
function login() {
	var loginForm = document.getElementById("loginForm");
	if (loginForm.username.value == "") {
		alert("Please enter your E-mail.");
		return false;
	}
	if (loginForm.password.value == "") {
		alert("Please enter your password.");
		return false;
	}
	loginForm.submit();
}
function Web_ID_Search(){
	var WID = document.getElementById('Web_ID_Input').value;
	if (WID == "") {
		alert("Please enter an Web ID number !");
		return false;
	}
    location=IGAZIROOT+WID;
}

function change_find(c,t,l){
	if (!l)
	  login_kell();
	 else 
	  location=IGAZIROOT+'searchupdate.php?cfc='+c+'&cft='+t;
}

function delete_find(l,m){
	if (!l)
	  login_kell();
	 else 
	  location=IGAZIROOT+'searchupdate.php?dfc='+m;
}
function new_location_login(l,m){
	if (!l)
	  login_kell();
	 else 
	  location=m;
}
function email_mehet(l){
	if (!l)
	  login_kell();
	 else 
	  form_on();
}
function form_mehet(l){
	if (!l) {
	  login_kell();
	}
	 else {
	 formvalidate();
	 }
}

