var geocoder;
var map;
var markersArray = [];

// hirdetés feladáshoz, szerksztéshez térkép
function feladasTerkep(lat, long, zooom, jel) {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(lat, long);
    var myOptions = {
      zoom: zooom,
      center: latlng,
	  disableDefaultUI: true,
	  scrollwheel: false,
	  disableDoubleClickZoom: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("mapFeladas"), myOptions);
	
	if(jel == true){
	var marker = new google.maps.Marker({
        position: latlng, 
        map: map
    });
	
	markersArray.push(marker);	
	}
}

// ingatlan adatlapra térkép
function adatlapterkep(lat, long, zooom) {
  	  var myLatlng = new google.maps.LatLng(lat, long);
	  
  	  var myOptions = {
      zoom: zooom,
      center: myLatlng,
	  navigationControl: true,
 	  mapTypeControl: true,
 	  scaleControl: false,
	  scrollwheel: false,
	  disableDoubleClickZoom: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
	
    map = new google.maps.Map(document.getElementById("mapAdatlap"), myOptions);
	
	
	
    var marker = new google.maps.Marker({
        position: myLatlng, 
        map: map
    });
	
	 markersArray.push(marker);	
	 
}


// markerek törlése
function clearOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
  }
}

// cím alapján lat, lng
function showLocation(adr) {
    var address = adr;
    if (geocoder) {
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
	 
		
			
		  clearOverlays();
          map.setCenter(results[0].geometry.location);
		  map.setZoom(15);
		  
          var marker = new google.maps.Marker({
              map: map, 
              position: results[0].geometry.location
          });
		 
		 
		 document.getElementById('lat').value = marker.getPosition().lat();
		 document.getElementById('lng').value = marker.getPosition().lng(); 
		 		 
		  
		 markersArray.push(marker);
		 
		 $('#tovabb').removeClass('disabled');
		 
        } else if(status == "ZERO_RESULTS") {         
		  $('#tovabb').addClass("disabled");	  
		  document.getElementById('lat').value = "";
		  document.getElementById('lng').value = "";
		  alert("Kérjük pontosítsa az ingatlan címét!");		   
        }else if(status == "OVER_QUERY_LIMIT") {
		  $('#tovabb').addClass("disabled");
		   document.getElementById('lat').value = "";
		  document.getElementById('lng').value = "";
          alert("Kérjük próbálja később! Adja fel hirdetését nyugodtan, később majd a hirdetések kezelése menüpontban korrigálhatja a térképet.");
        }
		
      });
    }
}

/* cím összeollózása */
function getCim(){
	var v_ok = "";
	
	var v = $('#Varosok :selected').text();
	
	if(v != "Válasszon!"){
		var v_ok = v;
	}	
	
	var u = document.getElementById("utca").value;
	var hsz = document.getElementById("hazszam").value;
	// kérjünk hozzá koordinátát
	showLocation(v_ok + " " + u + " " + hsz);
}










/* aktív menüpont kijelölése */ 

function activeMenu(m){
	var currTabElem = document.getElementById(m);
	var n = currTabElem.className;
	currTabElem.setAttribute("class", n+" active");
	currTabElem.setAttribute("className", n+" active"); 
}


/* number format */


function removeMask(str) {
	return str.replace(/[\s\.]/g,'');
}

function tagolas(szam){
	szam = removeMask(szam);
	var sRegExp = new RegExp('([0-9]+)([0-9]{3})');
	while(sRegExp.test(szam)) {
		szam = szam.replace(sRegExp, '$1 $2');
	}
	return szam;
}



function isNumericKey(key) 
{
	//return (key >= 48 && key <= 57 or key == 188 or key ==190);
	return (key >= 48 && key <= 57);
}

function isPrintable(key) {
	return (key >= 32);
}


/* előzmények, kedvencek */	


function elozmenyekhez(hid, uid) {
	$("#elozmenyek").html('<img src="images/ajax-loader.gif" alt="" />');
	$("#elozmenyek").load("base/templates/kedvencek/tmp.php?p=elozmenyekhez&hid="+hid+"&uid="+uid+"");
}




function kedvencekhez(hid,uid) {
	$("#kedvencek").html('<img src="images/ajax-loader.gif" alt="" />');
	$("#kedvencek").load("base/templates/kedvencek/tmp.php?p=kedvencekhez&hid="+hid+"&uid="+uid+"");
}


/* email megjelenítése */

function emailMutat(uid,VALID) {
    if (VALID == 1)
    {
	$("#emailMutat").html("<strong>Email: </strong>Egy pillanat...");
	$("#emailMutat").load("base/templates/email/email.php?p=&uid="+uid+"");
    }
    else {
	$("#emailMutat").html("<strong>Email: </strong>Nem engedélyezett!");
    
    }

}


/* email címek kiírása */

function MailMe(name) {
	document.write("<a href='mailto:"+name+"@eladokiadoingatlan.hu ' title='Levél írása'>"+name+"@eladokiadoingatlan.hu</a>");
}
// MailMe("info");



/* scrollTo */


function goToByScroll(id){
     	$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}


/* új ablak */


$(function(){
	$('a.new-window').click(function(){
	window.open(this.href);
	return false;
	});
});


/* böngésző kedvenceihez */


function bookmarksite(title,url){
			if (window.sidebar){
			 // firefox
			window.sidebar.addPanel(title, url, "");
			}
				else if(window.opera && window.print){ // opera
				var elem = document.createElement('a');
				elem.setAttribute('href',url);
				elem.setAttribute('title',title);
				elem.setAttribute('rel','sidebar');
				elem.click();
			} 
			else if(document.all)// ie
					window.external.AddFavorite(url, title);
}

/* select feltöltése regnél, keresőnél */


    hova=""
    
    function urit() {
	
	document.getElementById('Varosok').options.length = 0;
	document.getElementById('Varosok').options[0] = new Option("Várjon...", "");
	document.getElementById('Varosok').disabled = true;	
	
    }

    function uritSZ() {
	
	document.getElementById('sz_varos').options.length = 0;
	document.getElementById('sz_varos').options[0] = new Option("Várjon...", "");
	document.getElementById('sz_varos').disabled = true;	
	}

    function uritSZP() {
	
	document.getElementById('p_varos').options.length = 0;
	document.getElementById('p_varos').options[0] = new Option("Várjon...", "");
	document.getElementById('p_varos').disabled = true;	
	}

    function enTombom(n)
    {
	this.length = n;
	for (var x = 0; x <= n-1; n++) {
	    this[x] = 0;
	}
    return this;
    }
    

    function selectMegye(MegyeID)
    {
    urit();

    // Mozilla and Friends 
    if (window.XMLHttpRequest)
    { 
    req = new XMLHttpRequest(); 
    }
    else
    {
	if (window.ActiveXObject)
	{
	// Internet Explorer
	req = new ActiveXObject("Microsoft.XMLHTTP");
	}
    }
    req.onreadystatechange = processChoices;
    req.open("GET", "get.php?MegyeID="+MegyeID, true);
    req.send(null);
    }

    function processChoices()
    {
	if (req.readyState == 4)
        {
	    if (req.status == 200)
	    {
		vissza=req.responseText
		adatok=vissza.split(';');
		
		document.getElementById('Varosok').disabled = false;	
		
	
		document.getElementById('Varosok').options[0] = new Option("Válasszon!", "");
		
		
		for (i = 0; i < (adatok.length-1); i++)
		{

		adatok2=adatok[i].split(',');
		
		if (adatok2[2])
		{
		    document.getElementById('Varosok').options[i+1] = new Option(adatok2[1]+", "+adatok2[2], adatok2[0]);
		}
		else {
		    document.getElementById('Varosok').options[i+1] = new Option(adatok2[1], adatok2[0]);
		}
		} // for
	    }
	    else { alert("Can't retrieve XML: " + req.statusText); } // if 3
	} // if 2
    } // if 1
    
    /*
	Számlázási adatok: számlázás
    */

    function selectMegyeSzamlazasPosta(MegyeID)
    {
    uritSZP();
    // Mozilla and Friends
    if (window.XMLHttpRequest) {
	req = new XMLHttpRequest(); 
    }
    else {
	if (window.ActiveXObject)
	{
	// Internet Explorer
	req = new ActiveXObject("Microsoft.XMLHTTP");
	}
    }
    req.onreadystatechange = processChoicesSzamlazasPosta;
    req.open("GET", "get.php?MegyeID="+MegyeID, true);
    req.send(null);
    }

    function processChoicesSzamlazasPosta()
    {
	if (req.readyState == 4)
        {
	    if (req.status == 200)
	    {
		vissza=req.responseText
		adatok=vissza.split(';');
		document.getElementById('p_varos').disabled = false;
		document.getElementById('p_varos').options[0] = new Option("Válasszon!", "");
		for (i = 0; i < (adatok.length-1); i++) {

		    adatok2=adatok[i].split(',');
		
		    if (adatok2[2])
		    {
		    document.getElementById('p_varos').options[i+1] = new Option(adatok2[1]+", "+adatok2[2], adatok2[0]);
		    }
		    else {
		    document.getElementById('p_varos').options[i+1] = new Option(adatok2[1], adatok2[0]);
		    }
		} // for
	    }
	    else { alert("Can't retrieve XML: " + req.statusText); } // if 3
	} // if 2
    } // function

    /*
	Számlázási adatok: postacím
    */

    function selectMegyeSzamlazas(MegyeID)
    {
    uritSZ();
    // Mozilla and Friends
    if (window.XMLHttpRequest) {
	req = new XMLHttpRequest(); 
    }
    else {
	if (window.ActiveXObject)
	{
	// Internet Explorer
	req = new ActiveXObject("Microsoft.XMLHTTP");
	}
    }
    req.onreadystatechange = processChoicesSzamlazas;
    req.open("GET", "get.php?MegyeID="+MegyeID, true);
    req.send(null);
    }

    function processChoicesSzamlazas()
    {
	if (req.readyState == 4)
        {
	    if (req.status == 200)
	    {
		vissza=req.responseText
		adatok=vissza.split(';');
		document.getElementById('sz_varos').disabled = false;
		document.getElementById('sz_varos').options[0] = new Option("Válasszon!", "");
		for (i = 0; i < (adatok.length-1); i++) {

		    adatok2=adatok[i].split(',');
		
		    if (adatok2[2])
		    {
		    document.getElementById('sz_varos').options[i+1] = new Option(adatok2[1]+", "+adatok2[2], adatok2[0]);
		    }
		    else {
		    document.getElementById('sz_varos').options[i+1] = new Option(adatok2[1], adatok2[0]);
		    }
		} // for
	    }
	    else { alert("Can't retrieve XML: " + req.statusText); } // if 3
	} // if 2
    } // function






$(document).ready(function() {
$('.csakszam').keypress(function(e) {	

				var keycode = e.keyCode ? e.keyCode : e.which;

				if (isPrintable(keycode) && !isNumericKey(keycode)) {
					e.preventDefault();
					e.isDefaultPrevented();
					e.stopPropagation();
					e.isPropagationStopped();
					e.stopImmediatePropagation();
					e.isImmediatePropagationStopped();
				}

});


$('.szamforma').keyup(function(e) {	
				var $tagolt = tagolas($(this).val());
				$(this).val($tagolt);	
});

/*
$(".hirdetesek img").lazyload({ 
			placeholder : "images/white.jpg",  
			threshold : 280,
			effect : "fadeIn"
});
*/


});




function ticker(){
	var first = 0;
	var speed = 800;
	var pause = 8000;
	
		function removeFirst(){
			first = $('ul#listticker li:first').html();
			$('ul#listticker li:first')
			.animate({opacity: 0}, speed)
			.toggle('fast', function() {$(this).remove();});
			addLast(first);
		}
		
		function addLast(first){
			last = '<li style="display:none;">'+first+'</li>';
			$('ul#listticker').append(last)
			$('ul#listticker li:last')
			.animate({opacity: 1}, speed)
			.fadeIn('slow')
		}
	
	interval = setInterval(removeFirst, pause);
	
	$('#listticker').mouseover(function() {
  		clearInterval(interval);
	});
	
	$('#listticker').mouseout(function() {
  		interval = setInterval(removeFirst, pause);
	});
}



$(document).ready(function(){
	$(".horisontal-slider li a.title").bigTarget({
		  hoverClass: 'over', 
		  clickZone : '.click'
	 });
	 $(".horisontal-slider li").css("cursor", "pointer");
});


$(document).ready(function(){
	$('.number').numeric({allow:"."});
});
