var IE = document.all?true:false;
var gmarkers = [];
var htmls = [];	
var titles = [];	
var map;
function load() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    try{
    	var setlat = document.getElementById('setlat').value;
    	var setlng = document.getElementById('setlng').value;
    	if(setlat && setlng){
    		map.setMapType(G_HYBRID_MAP);
    		map.setCenter(new GLatLng(setlat,setlng), 11);
				var marker = new GMarker(new GLatLng(setlat,setlng));
				map.addOverlay(marker);
    	}
    }catch(e){
    	 map.setCenter(new GLatLng(47.480929577960126,19.081063270568848), 10);
    	 map.addControl(new GLargeMapControl());
    	 map.addControl(new GMapTypeControl());
    }
    //map.addControl(new GLargeMapControl());
		//map.addControl(new GMapTypeControl());
		//map.enableScrollWheelZoom();
		map.enableContinuousZoom();
		try{
			dothemap();
		}catch(e){}
	}
}
function menuOver(obj)
{
	var cn = getClassName(obj);
	if(!cn.match(/over/))
		setClassName(obj,cn+'over');
}

function menuOut(obj)
{
	var cn = getClassName(obj);
	if(cn.match(/over/))
		setClassName(obj,cn.replace(/over/,""));
}

function setClassName(obj,clsname)
{
	if (obj.getAttribute("class")) obj.setAttribute("class",clsname);
	else obj.setAttribute("className",clsname);
}

function getClassName(obj)
{
	if (obj.getAttribute("class")) return obj.getAttribute("class");
	else return obj.getAttribute("className");
}
function removeallmarker()
{
	map.clearOverlays();
	delete gmarkers;
 	delete titles;
 	delete htmls;
 	gmarkers = [];
	htmls = [];	
	titles = [];	
}
  

function _mapBoundsSet(minlat,minlng,maxlat,maxlng){
	if(maxlat!=minlat && maxlng!=minlng){
		z = map.getBoundsZoomLevel(pbounds);
		if(z<18 && z>1)	map.setZoom(map.getBoundsZoomLevel(pbounds)-1);
		var ujcenter= new GLatLng(  (maxlat+minlat)/2,(maxlng+minlng)/2 );
		map.panTo( ujcenter );
	}else{
		var ujcenter= new GLatLng(  (maxlat+minlat)/2,(maxlng+minlng)/2 );
		map.panTo( ujcenter );
	}
}
function _markerToMap(id,type,iconname,iconw,iconh,tit,lat,lng,onclk,onclk_func,bubi,html){
	try{
		gmarkers[type+id].remove();
	}catch(e){}
	pbounds.extend(new GLatLng( lat,lng ) );// elvileg ezzel tudjuk mekkora tkell :)
	marker = _createMarker(id,type,iconname,iconw,iconh,tit,lat,lng,onclk,onclk_func,bubi,html);
	gmarkers[type+id] = marker;
  titles[type+id] = tit;
  htmls[type+id] = html;
	map.addOverlay(marker);
}
function _createMarker(id,type,iconname,iconw,iconh,tit,lat,lng,onclk,onclk_func,bubi,html){
	
	o = new Object();
	o.bouncy=true;
	//var baseIcon = new GIcon();
	//baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	//baseIcon.shadowSize = new GSize(35, 35);
	//baseIcon.iconAnchor = new GPoint(9, 34);
	//baseIcon.infoWindowAnchor = new GPoint(9, 2);
	//baseIcon.infoShadowAnchor = new GPoint(18, 25);
	
	//var icon = new GIcon(baseIcon);
	//icon.image = "images/"+iconname;
	//baseIcon.iconSize = new GSize(iconw, iconh);
	
	//o.icon = icon;
	//icon.iconSize = baseIcon.iconSize;
	var latlng = new GPoint( lng,lat );
	var marker = new GMarker(latlng,o);
	GEvent.addListener(marker, 'click', function() {
		if(bubi && html.length > 0){
			_openBubi(id,type);
		}
		if(onclk && onclk_func.length > 0){
			eval(onclk_func);
		}
	});

	if(tit.length > 0){
		GEvent.addListener(marker, "mouseover", function() {
			_onMouseOverInfo(tit);
	  });
	  GEvent.addListener(marker, "mouseout", function() {
			_onMouseOutInfo(tit);
	  });
	}

	return marker;
}
function _openBubi(id,type) {
	gmarkers[type+id].openInfoWindowHtml(htmls[type+id]);
}

var onmouseoverinfo=0;
function _onMouseOverInfo(m)
{
	onmouseoverinfo=1;
	document.getElementById('onmouseoverinfo').innerHTML=m;
	return true;
}

function _onMouseOutInfo()
{
	onmouseoverinfo=0;
	document.getElementById('onmouseoverinfo').style.visibility='hidden';
	document.getElementById('onmouseoverinfo').innerHTML='';
	return true;
}

if (!IE)
	document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = function(e)
	{
		getMouseXY(e);
		if (onmouseoverinfo)
		{
			try{
				document.getElementById('onmouseoverinfo').style.top = (tempY-26)+"px";
				document.getElementById('onmouseoverinfo').style.left = (tempX-30)+"px";
				document.getElementById('onmouseoverinfo').style.visibility = "visible";
			}catch(e){}
		}
	}

var tempX = 0;
var tempY = 0;

function getMouseXY(e)
{
	if (IE) {	// grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {	// grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0) { tempX = 0; }
	if (tempY < 0) { tempY = 0; }
	return true;
}

function onchSumit(f,obj)
{
	document.getElementById(f).submit();
}
function getSelectValue(selid)
{
	return document.getElementById(selid).options[document.getElementById(selid).selectedIndex].value;
}

function res()
{
	if (typeof document.body.style.maxHeight != "undefined") {
	  // IE 7, mozilla, safari, opera 9
	  var D= (document.body.clientHeight)? document.body: document.documentElement;
	  he=parseInt(document.documentElement.clientHeight);
	 	if(document.getElementById('bodymain').clientHeight < he){
	 		document.getElementById('bodymain').style.height=he+'px';
	 	}
	} else {
	  // IE6, older browsers
	  he=parseInt(document.body.clientHeight);
	  document.getElementById('bodymain').style.height=he+'px';
	  document.getElementById('main111').style.height=(he-158)+'px';
	}
}

function hEvt(obj,evtName,fnCall)
{
  evtName=evtName.toLowerCase();
  doCapture=false;
  if (obj.addEventListener){  
		
		obj.addEventListener(evtName.replace('on',''),function(){eval(fnCall);},false);
  }else if(obj.attachEvent){
  	obj.attachEvent(evtName,function(){eval(fnCall);});
   //also do detachEvent later
  }else{
    eval(obj+"."+evtName +"="+ fnCall);
  }
}

function keres()
{
	if(getID('megye_jaras').value!="" && getID('megye_jaras').value.length<3){
		alert("Szabad szavas keresők esetén minimum 3 karakter megadása kötelező!");
		return false;
	}
	if(getID('telepules').value!="" && getID('telepules').value.length<3){
		alert("Szabad szavas keresők esetén minimum 3 karakter megadása kötelező!");
		return false;
	}
	if(getID('nev').value!="" && getID('nev').value.length<3){
		alert("Szabad szavas keresők esetén minimum 3 karakter megadása kötelező!");
		return false;
	}
	if(getID('vezeto').value!="" && getID('vezeto').value.length<3){
		alert("Szabad szavas keresők esetén minimum 3 karakter megadása kötelező!");
		return false;
	}
	document.searchform.submit();
}


function orderby(t,i)
{
	getID('order').value=t;
	getID('irany').value=i;
}
function getID(i)
{
	return document.getElementById(i);
}

function new_category(t)
{
	getID('newcategory').style.display='inline';
}
function omover(obj,color)
{
	obj.style.backgroundColor=color;
}
function omout(obj,color)
{
	obj.style.backgroundColor=color;
}

function ajaxurl(url,id,callback)       
{
   	var request = GXmlHttp.create();
		request.open('GET', url, true);
		request.onreadystatechange = function() {
		    if (request.readyState == 4) {
		        if (request.status==200 && request.responseText)
		            {
		            var html = request.responseText;
		            //alert(request.responseText.substring(1,1000));
		            try{
		            	if(id != ''){
		                if(document.getElementById(id).style.display=='none')
		                	document.getElementById(id).style.display = 'block';
		                document.getElementById(id).innerHTML = html;
		            	}
		            }catch(e){}
		            if (callback != null){
		                callback();
		            }
		        }
		    }
		}
		request.send(null);
		return false;
}

function onchangeorszag(obj)
{
	ajaxurl("../piszka/telepules_lista.php?orszag="+getSelectValue('orszag'),'lista');
}


function search_submit(form_name)
{
    document.getElementById('p').value="1";
    document.getElementById(form_name).submit();

    return false;
}

function search_orderby(v,form_name)
{
    document.getElementById('orderby').value=v;

    var desc = document.getElementById('desc').value;
    if (desc == "" || desc == "asc")
    {
        document.getElementById('desc').value = "desc";   
    }
    else
    {
        document.getElementById('desc').value = "asc";  
    }
    
    //alert($("#p").val());
    document.getElementById(form_name).submit();
}


function search_pager(v,form_name)
{
    var pval = 1;
    if(document.getElementById('p').value)
        pval = parseInt(document.getElementById('p').value);
    if (parseInt(v) == 1)
    {
        document.getElementById('p').value=pval+1;
    }
    else
    {
        document.getElementById('p').value=pval-1;
    }
    //alert($("#p").val());
    document.getElementById(form_name).submit();
}


function calcHeight()
{
    if (document.getElementById('query_iframe') != undefined)
    {
        //find the height of the internal page
        var the_height = document.getElementById('query_iframe').contentWindow.document.body.scrollHeight;
        
        //change the height of the iframe
        document.getElementById('query_iframe').height = the_height;
    }

}