var lang = 'hu';

function FotoWin(uri,title,w,h) {
  var okno = window.open('','','width='+w+',height='+h+',top='+(screen.height/2-h/2)+',left='+(screen.width/2-w/2));
  okno.document.write('<html><head><meta http-equiv="content-type" content="text/html; charset=windows-1250"><title>'+(title!='' ? title : 'fotogalerie')+'</title><link rel="stylesheet" href="http://www.***.cz/_template/okno.css" type="text/css"></head>');
  okno.document.write('<body>');
  okno.document.write('<a href="javascript:self.close()"><img alt="" title="Kliknut?zav?e" border=0 src="http://www.zoznamrealit.sk'+uri+'"></a>');
  if(title!='') okno.document.write('<p>'+title+'</p>');
  okno.document.write('</body>');
  okno.document.write('</htm>');
  okno.focus();
}
function BdM_swf (img,wsize,hsize,wmode){
    document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\""+wsize+"\" height=\""+hsize+"\">");
    document.write("<param name=\"movie\" value=\""+img+"\">");
    document.write("<param name=\"quality\" value=\"high\">");
    document.write("<param name=\"wmode\" value=\""+wmode+"\" />");
    document.write("<embed src=\""+img+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+wsize+"\" height=\""+hsize+"\" wmode=\""+wmode+"\"></embed>");
    document.write("</object>");
}
function WriteFlashCodeWithJS(f,w,h,q,b,t) {
  var output="";
  if(window.navigator.userAgent.indexOf("MSIE") != -1 && window.navigator.userAgent.indexOf("Windows") != -1){
    output=output+"<object id=\"flashmovie\" width=\""+w+"\" autostart=\"1\"height=\""+h+"\" type=\"application/x-shockwave-flash\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\">";
    output=output+"<param name=\"movie\" value=\""+f+"\">";
    output=output+"<param name=\"menu\" value=\"false\">";
	output=output+"<param name=\"autoplay\" value=\"1\">";
    output=output+"<param name=\"bgcolor\" value=\""+b+"'\">";
    output=output+"<param name=\"quality\" value=\""+q+"\">";
    if(t==1) output=output+"<param name=\"wmode\" value=\"transparent\">";
    output=output+"<"+"/object>";
  } else {
    output=output+"<object id=\"flashmovie\" data=\""+f+"\" width=\""+w+"\" height=\""+h+"\" type=\"application/x-shockwave-flash\">";
    output=output+"<param name=\"movie\" value=\""+f+"\">";
    output=output+"<param name=\"menu\" value=\"false\">";
	output=output+"<param name=\"autostart\" value=\"true\">";
    output=output+"<param name=\"bgcolor\" value=\""+b+"'\">";
    output=output+"<param name=\"quality\" value=\""+q+"\">";
    if(t==1) output=output+"<param name=\"wmode\" value=\"transparent\">";
    output=output+"<"+"/object>";
  }
  return output;
}

function SubmitToMap(count) {
    var answer = true;
    if (count > 300) {
        answer = confirm("Zvolili jste zobrazení více než 300 realitních nabídek na mapě, což může mít za následek výrazné ZPOMALENÍ systému!")
    }
    if (answer) {
        document.fHledani.action = "/szlovakia-terkepe-vagyonok";
        document.fHledani.akce.value = "mapa";
        document.fHledani.submit();
    }
}

function getObj(name)
{
  if (document.getElementById)
    {this.obj = document.getElementById(name);
    this.style = document.getElementById(name).style;}
  else if (document.all)
    {this.obj = document.all[name];
    this.style = document.all[name].style;}
  else if (document.layers)
    {this.obj = document.layers[name];
    this.style = document.layers[name];}
}

function hidestyle(whichid)
{
  mainobject = new getObj(whichid);
  if (mainobject.style.display=='none')
    {mainobject.style.display='';}
  else
    {mainobject.style.display='none';}
}
function hidestyleON(whichid)
{
  mainobject = new getObj(whichid);
  mainobject.style.display="none";
}

function hidestyleOFF(whichid)
{
  mainobject = new getObj(whichid);
  mainobject.style.display='';
}
function ShowHide(id) {
    obj = document.getElementsByTagName("div");
    if (obj[id].style.visibility == 'visible'){
		obj[id].style.display = 'none';
		obj[id].style.visibility = 'hidden';
	} else {
		obj[id].style.visibility = 'visible';
		obj[id].style.display = '';
	}
}
function ObnovOkresy(kraj) {
  document.forms['newitemform'].okres.options.length = 0;
  if(kraj>0) {
    for(i=0;i<okresy[kraj].length;i++) {
      document.forms['newitemform'].okres.options[i] = new Option(okres[okresy[kraj][i]],okresy[kraj][i]);
    }
  }
}

function ReverseString(str) {
	var res = new String();
	var length = str.length;
	var resArr = new Array(length-1);
	for(i=0;i<=length;i++) {
		resArr[length-1-i] = str.charAt(i);
	}
	for(i=0;i<length;i++) {
		res += resArr[i];
	}
	return res;
}
function IsNumeric(sText, box) {
	var ValidChars = "0123456789";
	var res = "";
	for(i=0;i<sText.value.length;i++) {
		Char = sText.value.charAt(i); 
		if (ValidChars.indexOf(Char) != -1) {
			res = res + sText.value.charAt(i);
		}
	}
	switch (box) {
		case 1:
			document.newitemform.zastplocha.value = res;
		break;
		case 2:
			document.newitemform.obytplocha.value = res;
		break;
		case 3:
			document.newitemform.plochapozem.value = res;
		break;
	}
}
function NewItemProcess(id) {
	switch(id) {
		case "selvykurovanievlastne":
			if(document.newitemform.selvykurovanie.value == 1)
				hidestyleOFF(id);
			else
				hidestyleON(id);
		break;
	}
}
function NewItemName(inputBox) {
	if(inputBox.value.length > 55)
        inputBox.value = inputBox.value.substring(0,55);
}
function ShowMesto() {
	var mesto_id = document.mesto.mesto.value;
	window.location = 'http://www.zoznamrealit.sk/mesta-a-obce?mesto='+mesto_id;
}
function VyberRK(sel, lang) {
	if (sel == 1) { // nazov rk
		var ajaxRequest;
		if (ajaxRequest = testAjax()) {
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4){
					window.location = '/ingatlaniroda/'+ajaxRequest.responseText;
				}
			}
		}
		var idreal = document.vyberrk.nazovrk.value;
		var queryString = "?idreal=" + idreal;                                       
		ajaxRequest.open("GET", "http://"+HOST+"/ajaxCode2Lokalita.php" + queryString, true);
		ajaxRequest.send(null);
	} else { // lokalita
		var ajaxRequest;
		if (ajaxRequest = testAjax()) {
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4){
					window.location = '/ingatlanirodak-vagyonok/'+ajaxRequest.responseText;
				}
			}
		}
		var lokalita = document.vyberrk.lokalitark.value;
		if (lokalita != "") {
			var queryString = "?lokalita=" + lokalita;
			ajaxRequest.open("GET", "http://"+HOST+"/ajaxCode2Lokalita.php" + queryString, true);
			ajaxRequest.send(null);
		}
	}
}
function FormatCena(cena, value) {
	var num = new NumberFormat();
	num.setInputDecimal('.');
	num.setNumber(cena); // obj.value is '10000'
	num.setPlaces('0', false);
	num.setCurrencyValue(value);
	num.setCurrency(true);
	num.setCurrencyPosition(num.RIGHT_INSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(false);
	num.setSeparators(true, '.', ',');
	return num.toFormatted();
}
function PopulateCenaDropdown(_od, _do, unl, lang) {
	var mySel = document.fHledani.cenaod;
	var secSel = document.fHledani.cenado;
    var milStr = "Mil";
    if (lang == 'de') {
        milStr = "Mio"
    }
    lang = 'de'; // kvoli euru

    for (i = mySel.length - 1; i>=0; i--) {
        mySel.remove(i);
    }
    for (i = secSel.length - 1; i>=0; i--) {
        secSel.remove(i);
    }
    secSel.options[0] = new Option("" + unl + "", "");    

    if (lang != 'de') {
        if (document.fHledani.typ.selectedIndex == 0 || document.fHledani.typ.selectedIndex == 2) {
            for (i = 0; i < 30001; i += 2500) {
		        mySel.options[mySel.options.length] = new Option(FormatCena(i, ',-'),i);
		        secSel.options[secSel.options.length] = new Option(FormatCena(i, ',-'),i);	
	        }
	        for (i = 35000; i < 50001; i += 5000) {
		        mySel.options[mySel.options.length] = new Option(FormatCena(i, ',-'),i);
		        secSel.options[secSel.options.length] = new Option(FormatCena(i, ',-'),i);		
	        }
	        for (i = 60000; i < 100001; i += 10000) {
		        mySel.options[mySel.options.length] = new Option(FormatCena(i, ',-'),i);
		        secSel.options[secSel.options.length] = new Option(FormatCena(i, ',-'),i);		
	        }
	        for (i = 150000; i < 250001; i += 50000) {
		        mySel.options[mySel.options.length] = new Option(FormatCena(i, ',-'),i);
		        secSel.options[secSel.options.length] = new Option(FormatCena(i, ',-'),i);		
	        }
        } 
        if (document.fHledani.typ.selectedIndex == 0 || document.fHledani.typ.selectedIndex == 1) {
            if (document.fHledani.typ.selectedIndex == 0) {
                i = 500000;
            } else {
                i = 0;
            }
            for (i; i < 5000001; i += 250000) {
		        mySel.options[mySel.options.length] = new Option(FormatCena(i, ',-'),i);
		        secSel.options[secSel.options.length] = new Option(FormatCena(i, ',-'),i);		
	        }
	        for (i = 5500000; i < 10000001; i += 500000) {
		        mySel.options[mySel.options.length] = new Option(FormatCena(i, ',-'),i);
		        secSel.options[secSel.options.length] = new Option(FormatCena(i, ',-'),i);	
	        }
	        for (i = 11000000; i < 20000001; i += 1000000) {
		        mySel.options[mySel.options.length] = new Option(FormatCena(i, ',-'),i);
		        secSel.options[secSel.options.length] = new Option(FormatCena(i, ',-'),i);	
	        }
        }
    } else { // pre nemcinu sa nastavi euro
        for (i = 0; i < 1001; i += 100) {
            mySel.options[mySel.options.length] = new Option(FormatCena(i, " EUR"),i);
            secSel.options[secSel.options.length] = new Option(FormatCena(i, " EUR"),i);        
        }
        for (i = 2000; i < 10001; i += 1000) {
            mySel.options[mySel.options.length] = new Option(FormatCena(i, " EUR"),i);
            secSel.options[secSel.options.length] = new Option(FormatCena(i, " EUR"),i);    
        }
        for (i = 20000; i < 80001; i += 10000) {
            mySel.options[mySel.options.length] = new Option(FormatCena(i, " EUR"),i);
            secSel.options[secSel.options.length] = new Option(FormatCena(i, " EUR"),i);    
        }
        for (i = 100000; i < 180001; i += 20000) {
            mySel.options[mySel.options.length] = new Option(FormatCena(i, " EUR"),i);
            secSel.options[secSel.options.length] = new Option(FormatCena(i, " EUR"),i);    
        }
        for (i = 200000; i < 1000000; i += 50000) {
            mySel.options[mySel.options.length] = new Option(FormatCena(i, " EUR"),i);
            secSel.options[secSel.options.length] = new Option(FormatCena(i, " EUR"),i);    
        }
            mySel.options[mySel.options.length] = new Option("1 "+milStr+". EUR", 1000000);
            secSel.options[secSel.options.length] = new Option("1 "+milStr+". EUR", 1000000);
    }
	for (i = mySel.length - 1; i>=0; i--) {
	    if (mySel.options[i].value == _od) {
			document.fHledani.cenaod.selectedIndex = i;
		}
	}
	if (_do != 0) {
		for (i = secSel.length - 1; i>=0; i--) {
		    if (secSel.options[i].value == _do) {
				document.fHledani.cenado.selectedIndex = i;
				
			}
		}
	}
}
function testAjax() {
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return ajaxRequest;
}
function ajaxRefreshZakazky(lang) {
	var ajaxRequest;
	if (ajaxRequest = testAjax()) {
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4){
				var ajaxDisplay = document.getElementById('hledanisubmit');
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			}
		}
	}
	var typ = 13;
    var cbPredaj = document.getElementById('typ-predaj');
    var cbPrenajom = document.getElementById('typ-prenajom');
    if (cbPredaj.checked && !cbPrenajom.checked) {
        typ = 11;
    } else if (cbPrenajom.checked && !cbPredaj.checked) {
        typ = 12;
    }
	var lokalita = document.fHledani.lokalita.options[document.fHledani.lokalita.selectedIndex].value;
	var druh = document.fHledani.druh.options[document.fHledani.druh.selectedIndex].value;
	var cenaod = document.fHledani.cenaod.options[document.fHledani.cenaod.selectedIndex].value;
	var cenado = document.fHledani.cenado.options[document.fHledani.cenado.selectedIndex].value;
	var fulltext = document.fHledani.fulltext.value;
	var checkbox = '';
	if (document.fHledani.ibaobr.checked) {
		checkbox = '&ibaobr=1';
	}
	var queryString = "?typ=" + typ + "&lokalita=" + lokalita + "&druh=" + druh + "&cenaod=" + cenaod + "&cenado=" + cenado + "&fulltext=" + fulltext + checkbox;
	ajaxRequest.open("GET", "http://"+HOST+"/poc-zakaziek.php" + queryString, true);
	ajaxRequest.send(null); 
}

function removeElement(divId) {
    var olddiv = document.getElementById(divId);
    document.body.removeChild(olddiv);
}
function showAddress(lat, lng, e) {
    CreateMapaPopup(e);
    var map = new GMap2(document.getElementById('mapa'));
    map.setCenter(new GLatLng(lat, lng), 15);
    map.addControl(new GMapTypeControl());
    map.addControl(new GLargeMapControl());
    map.addControl(new TextualZoomControl());
    var marker = new GMarker(new GLatLng(lat, lng));
    map.addOverlay(marker);
}
function TextualZoomControl() {}
TextualZoomControl.prototype = new GControl();

TextualZoomControl.prototype.initialize = function(map) {
    var container = document.createElement("div");
    var closeDiv = document.createElement("div");
    this.setButtonStyle_(closeDiv);
    container.appendChild(closeDiv);
    closeDiv.appendChild(document.createTextNode("CLOSE"));
    
    GEvent.addDomListener(closeDiv, "click", function() {
        GUnload();
        removeElement('mapa');
    });

    map.getContainer().appendChild(container);
    return container;
}

TextualZoomControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(20, 40));
}

TextualZoomControl.prototype.setButtonStyle_ = function(button) {
    button.style.textDecoration = "none";
    button.style.color = "#fff";
    button.style.backgroundColor = "red";
    button.style.font = "small Arial";
    button.style.border = "3px solid black";
    button.style.padding = "2px";
    button.style.marginBottom = "3px";
    button.style.textAlign = "center";
    button.style.width = "9em";
    button.style.cursor = "pointer";
}
// vrati suradnice kliku
function GetClickCoords(e) {
    var posx = 0;
    var posy = 0;
    if (!e) { var e = window.event; }
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    } else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    var Coor = new Array(posx, posy);
    return Coor;
}
// pomocna funkcia, workaround pre setAttribute() pre IE
function rzCC(s) {
    for(var exp=/-([a-z])/; 
        exp.test(s); 
        s=s.replace(exp,RegExp.$1.toUpperCase()));
    return s;
}
// pomocna funkcia, workaround pre setAttribute() pre IE
function _setStyle(element, declaration) {
    if (declaration.charAt(declaration.length-1)==';') {
        declaration = declaration.slice(0, -1);
    }
    var k, v;
    var splitted = declaration.split(';');
    for (var i=0, len=splitted.length; i<len; i++) {
        k = rzCC(splitted[i].split(':')[0]);
        v = splitted[i].split(':')[1];
        eval("element.style."+k+"='"+v+"'");
    }
}
// vytvori popup s mapou
function CreateMapaPopup(e) {
    if (document.getElementById('mapa')) {
        removeElement('mapa');
    }
    var Coor = GetClickCoords(e);
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', 'mapa');
    var top = 200;
    if (Coor[1] > 700) {
        top = 450;
    }
    _setStyle(newdiv, 'top: '+(Coor[1]-top)+'px; left: '+(Coor[0]-340)+'px;');        
    document.body.appendChild(newdiv);
}

function SetMesto() {
	var val = document.newitemform.okreslokalita.value;
	if (val.length != 8) {
		return;
	}
	var kod = val.substring(0,5);
	if (kod >= 10020 && kod < 10026) {
		document.newitemform.mesto.value = 'Bratislava';
	}
	if (kod >= 10030 && kod < 10035 && val != 10030000) {
		document.newitemform.mesto.value = 'Košice';
	}
	/*if (val == 10090000) {
		document.newitemform.stat.selectedIndex = 0;*/
		/*var tr = document.getElementById('drop_stat');
		tr.style.display = '';*/
	/*} else {
		document.newitemform.stat.selectedIndex = 1;*/
	/*	var tr = document.getElementById('drop_stat');
		tr.style.display = 'none';*/
	/*}*/
}
function SetRozlohy() {
	var selDruh = document.newitemform.druh.selectedIndex;
	if (selDruh >= 4 && selDruh <= 10) {
		document.newitemform.zastplocha.disabled = 'disabled';
		document.newitemform.plochapozem.disabled = 'disabled';
		document.newitemform.obytplocha.disabled = '';
	} else if (selDruh >= 18 && selDruh <= 23) {
		document.newitemform.zastplocha.disabled = 'disabled';
		document.newitemform.obytplocha.disabled = 'disabled';
		document.newitemform.plochapozem.disabled = '';
	} else {
		document.newitemform.zastplocha.disabled = '';
		document.newitemform.obytplocha.disabled = '';
		document.newitemform.plochapozem.disabled = '';
	}
}
/* FUNKCIA NA PRIDANIE STRANKY MEDZI OBLUBENE */
function add2fav()
{
	url = "http://"+HOST;
	title = "Ingatlan-Szlovakia.hu";
if(document.all)
window.external.AddFavorite(url,title)
}

function SetExportCookies(id_zakazky) {
	var ajaxRequest;
	if (ajaxRequest = testAjax()) {
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4){
				
			}
		}
	}
	var queryString = "?id=" + id_zakazky;
	ajaxRequest.open("GET", "http://www.zoznamrealit.sk/ajaxExportCookie.php" + queryString, true);
	ajaxRequest.send(null);
}


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);
}

function CutAddress(address) {
    var arr = address.split(', ');
    var newArray = arr.slice(1, arr.length);
    var newAddress = newArray[0];
    for(var i = 1; i < newArray.length; i++) {
        newAddress += ', '+newArray[i];    
    }
    return newAddress;
}

function ajaxGeocodeAddress(id_zakazky, id_realitky, address) {
    geocoder = new GClientGeocoder();
    if (geocoder) {
        geocoder.getLatLng(
            address,
            function(point) {
                if (!point) { // ak sa nenasla adresa, skrati sa adresa a skusi sa najst znova
                    if (address != "") {
                        newAddress = CutAddress(address);
                        if (id_zakazky != 0) {
                            ajaxGeocodeAddress(id_zakazky, 0, newAddress);
                        } else if (id_realitky != 0) {
                            ajaxGeocodeAddress(0, id_realitky, newAddress);
                        }
                    }
                } else {
                    var ajaxRequest = testAjax();
			        if (id_zakazky != 0 && id_realitky == 0) {
	                    var queryString = "?coord=" + point + "&id_zak=" + id_zakazky;
			        } else if (id_zakazky == 0 && id_realitky != 0) {
			            var queryString = "?coord=" + point + "&id_real=" + id_realitky;
			        }		
                    ajaxRequest.open("GET", "http://www.zoznamrealit.sk/ajaxInsertCoords.php" + queryString, true);
                    ajaxRequest.send(null);
                }
            }
        );
    }
}

function NumberOnlyBox() {
    var cena = document.newitemform.cena.value;
    var re5digit = /^\d*/
    if (cena.search(re5digit) == -1) {
        document.newitemform.cena.value = cena.substring(0, cena.length-1);    
    }
}
function FilterBox(box) {
    var text = box.value;
    for (var i = 0; i < filter_arr.length; i++) {
        var regex = eval("/" + filter_arr[i] + "/i");
        text = text.replace(regex, '');
    }
    box.value = text;
}
function ReplaceNazov(box) {
    var text = box.value;
    for (var i = 0; i < replace_arr.length; i++) {
        var regex = eval("/" + replace_arr[i] + "/");
        text = text.replace(regex, replace_with[i]);
    }
    box.value = text;
}
function ajaxSledujPonuku(id_ponuky, nesledovat) {
    var ajaxRequest = testAjax();
    if (nesledovat == 1) {
        var queryString = "?nesledovat=" + id_ponuky;
    } else {
        var queryString = "?sledovat_id=" + id_ponuky;
    }
    ajaxRequest.open("GET", "http://www.zoznamrealit.sk/ajaxSledovatPonuku.php" + queryString, true);
    ajaxRequest.send(null);
}

/* FUNKCIE PRE VELKU GOOGLE MAPU */
var map = null;

function markerClick(markerId) {
    marker = map.getMarkerById(markerId);
    var popis = GetZakazkaPopis(markerId);
    marker.openInfoWindowHtml(popis);  
}

var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);


function addNewMarker(id,lat,lng,istop,novostavba) {
    var icon = new GIcon(baseIcon);
    if (istop == 1) {
        icon.image = "http://www.zoznamrealit.sk/_ico/marker_top.png";        
        icon.iconSize = new GSize(27, 46);
        icon.shadow = "http://www.zoznamrealit.sk/_ico/shadow_top.png";
        icon.shadowSize = new GSize(50, 46);
    } else if (novostavba == 1) {
        icon.image = "http://www.zoznamrealit.sk/_ico/marker_novostavba.png";        
        icon.iconSize = new GSize(20, 34);
        icon.shadow = "http://www.zoznamrealit.sk/_ico/shadow_normal.png";
        icon.shadowSize = new GSize(37, 34);
    } else {
        icon.image = "http://www.zoznamrealit.sk/_ico/marker_normal.png";        
        icon.iconSize = new GSize(20, 34);
        icon.shadow = "http://www.zoznamrealit.sk/_ico/shadow_normal.png";
        icon.shadowSize = new GSize(37, 34);
    }
    var marker = new PdMarker(new GLatLng(lat, lng), icon);
    //marker.setTooltip(id);
    marker.setUserData(istop);
    marker.setId(id);
    /* (istop == 1) {
        marker.zIndex = 1500;
    } else {
        marker.zIndex = 10;
    }*/
    var markerId = marker.getId();
    
    GEvent.addListener(marker, "click", function() {
         markerClick(markerId);
    });
    if (istop != 1) {
        GEvent.addListener(marker, "mouseover", function() {
            marker.topMarkerZIndex();
        });
        GEvent.addListener(marker, "mouseout", function() {
            marker.restoreMarkerZIndex();
        });
    }
        
    map.addOverlay(marker);
    return marker;
}

function SetMarkers(address) {
    for (var i = 0; i < address.length; i++) {
        var info = new Array();
        /*
        ##### POPIS POLA INFO #####
        [0] = latitude
        [1] = longitude
        [2] = id
        [3] = istop
        [4] = novostavba
        ###########################
        */
        info = address[i].split('|');
        addNewMarker(info[2], info[0], info[1], info[3], info[4]);
    }
    var marker = map.getFirstMarker();
    while (marker != null)
    {
        if(marker.getUserData() == 1) {
            marker.topMarkerZIndex();
        }
        marker = map.getNextMarker();
    }
}

function initialize(suradnice) {
    if (GBrowserIsCompatible()) {
    if (map != null) {
        GUnload();
    }
        var cent_lat = 48.669026;
        var cent_lng = 19.699024;
        var cent_zoom = 7;
        
        var tmp_lat = readCookie("center-lat");
        var tmp_lng = readCookie("center-lng");
        var tmp_zoom = readCookie("zoom");
        
        if(tmp_lat != null) {
            cent_lat = tmp_lat;
        }
        if (tmp_lng != null) {
            cent_lng = tmp_lng;
        }
        if (tmp_zoom != null) {
            cent_zoom = tmp_zoom;
        }
        
        if (suradnice != "") {
            var tmparr = suradnice.split('|');
            cent_lat = tmparr[0];
            cent_lng = tmparr[1];
            cent_zoom = tmparr[2];
        }
        SetMapCoords(new GLatLng(cent_lat, cent_lng), parseInt(cent_zoom));
        map = new GMap2(document.getElementById("bigmap"));
        map.setCenter(new GLatLng(cent_lat, cent_lng), parseInt(cent_zoom));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        GEvent.addListener(map, "moveend", function() {
            SetMapCoords(map.getCenter(), map.getZoom());
            //var box = document.getElementById("dropdown-lokalita-mapa");
            //box.selectedIndex = 0;
        });
        GEvent.addListener(map, "zoomend", function() {
            SetMapCoords(map.getCenter(), map.getZoom());
        });
    }
}                            

function GetZakazkaPopis(id_zakazky) {
    var ajaxRequest;
    if (ajaxRequest = testAjax()) {
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function() {
            if(ajaxRequest.readyState == 4){
                //return 'ss';//ajaxRequest.responseText;
            }
        }
    }
    var queryString = "?id_zakazky=" + id_zakazky + "&lang=" + lang;
    ajaxRequest.open("GET", "http://"+HOST+"/ajaxGetZakazkaDetail.php" + queryString, false);
    ajaxRequest.send(null);
    return ajaxRequest.responseText;
}

function SetMapCoords(center, zoom) {
    var lat = center.lat();
    var lng = center.lng();
    createCookie("center-lat",lat,0);
    createCookie("center-lng",lng,0);
    createCookie("zoom",zoom,0);
}

function Submit() {
    document.fMapaFilter.submit();
}
/*********************************/
/******** MAPA V ITEM ********/
var itemmap = null;
function InitializeItemMap(myLat, myLng, mapDiv) {
    if (GBrowserIsCompatible()) {
        if (itemmap != null) {
            GUnload();
        }
        itemmap = new GMap2(document.getElementById(mapDiv));
        var center = new GLatLng(myLat, myLng);
        itemmap.setCenter(center, 7);    
        itemmap.addControl(new GLargeMapControl());
        itemmap.addControl(new GMapTypeControl());
        
        var marker = new GMarker(center, {draggable: true});
       
        GEvent.addListener(itemmap, "click", function(overlay, point) {
            if (point) {
                marker.setPoint(point);
                SetHiddenForms(marker);    
            }
        });

        GEvent.addListener(marker, "dragend", function() {
            
            SetHiddenForms(marker);
        });
        itemmap.addOverlay(marker);
    }    
}
function ShowAddressOnMap(formname) {
    if (formname == "newitem") {
        var ulica = document.newitemform.ulice.value;
        var mesto = document.newitemform.mesto.value;
        if (mesto == "") {
            //var okres = document.newitemform.okreslokalita.options[document.newitemform.okreslokalita.selectedIndex].text;
            mesto = document.newitemform.okres.options[document.newitemform.okres.selectedIndex].text;
        }
        var stat = document.newitemform.stat.options[document.newitemform.stat.selectedIndex].text;
    } else if (formname == "profilRK") {
        var ulica = document.newitemform.ulice.value;
        var mesto = document.newitemform.mesto.value;
        var okres = document.newitemform.okreslokalita.options[document.newitemform.okreslokalita.selectedIndex].text;
    }
    
    var address = ulica + ', ' + mesto + ', ' + stat;
    SetItemMapCenter(address);
}
function SetItemMapCenter(address) {
    geocoder = new GClientGeocoder();
    if (geocoder) {
        geocoder.getLatLng(
            address,
            function(point) {
                if (!point) { 
                    // nebola najdena adresa, skratime ju
                    newAddress = CutAddress(address);
                    SetItemMapCenter(newAddress);
                } else {
                    itemmap.setCenter(point);
                    itemmap.setZoom(15);
                    itemmap.clearOverlays();
                    
                    var marker = new GMarker(point, {draggable: true});
                    SetHiddenForms(marker);
                    GEvent.addListener(marker, "dragend", function() {
                        SetHiddenForms(marker);
                    });
                    GEvent.clearListeners(itemmap, "click");
                    GEvent.addListener(itemmap, "click", function(overlay, point) {
                        if (point) {
                            marker.setPoint(point);
                            SetHiddenForms(marker);    
                        }
                    });
                    itemmap.addOverlay(marker);
                }
            }
        );
    }
}



function SetItemMapCenterEdit(_lat, _lng) {
    var point = new GLatLng(_lat, _lng);
    itemmap.setCenter(point);
    itemmap.setZoom(15);
    itemmap.clearOverlays();
    
    var marker = new GMarker(point, {draggable: true});
    SetHiddenForms(marker);
    GEvent.addListener(marker, "dragend", function() {
        SetHiddenForms(marker);
    });
    GEvent.clearListeners(itemmap, "click");
    GEvent.addListener(itemmap, "click", function(overlay, point) {
        if (point) {
            marker.setPoint(point);
            SetHiddenForms(marker);    
        }
    });
    itemmap.addOverlay(marker);
}

function SetHiddenForms(marker) {
    try {
        document.kontaktinfo.itemGLat.value = marker.getLatLng().lat();
        document.kontaktinfo.itemGLng.value = marker.getLatLng().lng();
    } catch (err) {
    }                
    try {
        document.newitemform.itemGLat.value = marker.getLatLng().lat();
        document.newitemform.itemGLng.value = marker.getLatLng().lng();
    } catch (err) {
    }
}
function setKraje(IDstat, IDokres) {
    var browser = navigator.appName;
    document.getElementById('selMesta').style.display = "none";
    if (IDstat > 0) {
        document.getElementById('loading').style.display = "";
        document.getElementById('loading').src = "/_ico/loading.gif";
        var ajaxRequest;
        if (ajaxRequest = zXmlHttp.createRequest()) {
            ajaxRequest.onreadystatechange = function() {
                if(ajaxRequest.readyState == 4) {
                    document.getElementById('loading').style.display = "none";
                    if (browser == "Microsoft Internet Explorer") {
                        document.getElementById('dMesta').innerHTML = ajaxRequest.responseText;
                    } else {
                        document.getElementById('selMesta').innerHTML = ajaxRequest.responseText;
                        document.getElementById('selMesta').style.display = "";
                    }
                }
            }            
        }
        var params = "statID="+IDstat+"&browser="+browser;
        if (IDokres > 0) {
            params += "&okresID="+IDokres;            
        }
        ajaxRequest.open("POST", "/_ajax/ajaxVlozitMesta.php", true);
        ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        ajaxRequest.setRequestHeader("Content-length", params.length);
        ajaxRequest.setRequestHeader("Connection", "close");
        ajaxRequest.send(params);
    }
}
 /*****************************/
function checkFormCaptcha(frm) {
    if (frm.captcha_code.value != frm.captcha.value) {
        alert('Please insert the result of an easy mathematical exercise in the column next to the "Send" bottom, and then press it to send your message.');
        return false;
    }
    frm.submit();
}
function initializeRKMap(markerData) {
    if (GBrowserIsCompatible()) {
        rkmap = new GMap2(document.getElementById("mapark"));
        rkmap.setCenter(new GLatLng(48.669026, 19.699024), 7);
        rkmap.addControl(new GLargeMapControl());
        rkmap.addControl(new GMapTypeControl());
    }
    var len = markerData.length;
    for (var i = 0; i < len; i++) {
        var info = new Array();
        /*
        ##### POPIS POLA INFO #####
        [0] = latitude
        [1] = longitude
        [2] = id
        ###########################
        */
        info = markerData[i].split('|');
        addMarker(rkmap, info[0], info[1], info[2])
    }
}
function addMarker(dest_map, lat, lng, id) {
    var icon = new GIcon(baseIcon);
    icon.image = "http://www.zoznamrealit.sk/_ico/marker_rk.png";        
    icon.iconSize = new GSize(20, 34);
    icon.shadow = "http://www.zoznamrealit.sk/_ico/shadow_rk.png";
    icon.shadowSize = new GSize(37, 34);
    var marker = new PdMarker(new GLatLng(lat, lng), icon);
    marker.setId(id);
    var markerId = marker.getId();
    
    GEvent.addListener(marker, "click", function() {
        markerRKClick(markerId);
    });
    
    GEvent.addListener(marker, "mouseover", function() {
        marker.topMarkerZIndex();
    });
    GEvent.addListener(marker, "mouseout", function() {
        marker.restoreMarkerZIndex();
    });
    
    dest_map.addOverlay(marker);
}
function markerRKClick(markerId) {
    marker = rkmap.getMarkerById(markerId);
    var popis = getRKPopis(markerId);
    marker.openInfoWindowHtml(popis);  
}

function getRKPopis(id) {
    var ajaxRequest;
    if (ajaxRequest = testAjax()) {
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function() {
            if(ajaxRequest.readyState == 4){
                //return 'ss';//ajaxRequest.responseText;
            }
        }
    }
    var queryString = "?id=" + id + "&lang=" + lang;
    ajaxRequest.open("GET", "/ajaxGetRKDetail.php" + queryString, false);
    ajaxRequest.send(null);
    return ajaxRequest.responseText;
} 