Ext.onReady(function() {

	var el = Ext.get("helyiseg_reszletek");
	if (el){
		el.on('click',function(e){
			var th = Ext.get("helyisegek");
			if(th.getStyle('display')!='none') {
				th.setDisplayed('none');
			}
			else {
				th.setDisplayed('block');
			}
		});
	}
	var em = Ext.get("email_kuld_ikon");

	em.on('click',function(e){
		var th = Ext.get("email_ism");
		if(th.getStyle('display')!='none') {
			th.setDisplayed('none');
		}
		else {
			th.setDisplayed('block');
		}
	});

	var email_ismer=Ext.get("email_ism_kuld");

	email_ismer.on('click',function(e){
		var valid=true;
		var nev=Ext.get("email_ism_nev");
		var code=Ext.get("code");
		var email=Ext.get("email_ism_cim");
		var inid=Ext.get("inid");

		var lat=Ext.get("lat");
		var lng=Ext.get("lng");
		var origokey=Ext.get("origokey");

		var email_mask = /^([\w]+)(\.[\w]+)*@([\w\-]+\.){1,5}([A-Za-z]){2,4}$/;
		var v=email.getValue();
		if (!email_mask.test(v)){
			valid=false;
			email.focus()
			alert ('Nem megfelelő e-mail formátum! A helyes formátum: pelda@example.com');
		}
		if (nev.getValue().length==0){
			valid=false;
			nev.focus()
			alert ('A ön nevének kitöltése kötelező!');
		}

		if (valid){
			Ext.Ajax.request({
				url: 'email_ismeros.php',
				success: function(r,o){
					var obj = Ext.decode(r.responseText);
					//console.dir(obj);

					if (obj.success==true){
						alert('Az e-mail elküldésre került!')
					}else{
						alert('Nem sikerült elküldeni az e-mail, próbálja meg később!')
					}
					var th = Ext.get("email_ism");
					th.setDisplayed('none');
					//document.getElementById('captcha_img').src = 'securimage/captcha.php?sid=' + Math.random();
				},
				failure: function(r,o){
					alert('Nem sikerült elküldeni az e-mail, próbálja meg később!')
				},
				params: {
					nev: nev.getValue(),
					inid: inid.getValue(),
					lat: lat.getValue(),
					lng: lng.getValue(),
					email:email.getValue(),
					origokey:origokey.getValue()
				}
			});
		}
	});



	var email_sub=Ext.get("email_kuld");

	email_sub.on('click',function(e){

		var valid=true;
		var nev=Ext.get("email_nev");
		var email=Ext.get("email_email");
		var code=Ext.get("code");
		var inid=Ext.get("inid");
		var iid=Ext.get("iid");
		var uid=Ext.get("uid");
		var telefon=Ext.get("email_telefon");
		var tovabbi=Ext.get("email_tovabbi");
		var megnezni=Ext.get("email_megnezni");
		var megjegyzes=Ext.get("email_megjegyzes");
		var webcim=Ext.get("webcim");
		
		var email_mask = /^([\w]+)(\.[\w]+)*@([\w\-]+\.){1,5}([A-Za-z]){2,4}$/;
		var v=email.getValue();
		if (!email_mask.test(v)){
			valid=false;
			email.focus()
			alert ('Nem megfelelő e-mail formátum! A helyes formátum: pelda@example.com');
		}

		if (valid){
			Ext.Ajax.request({
				url: 'email.php',
				success: function(r,o){
					var obj = Ext.decode(r.responseText);
					//console.dir(obj);

					if (obj.success==true){
						//alert(r.responseText);
						Ext.get('captcha_img').set({src : 'securimage/captcha.php?sid=' + Math.random()});
						code.dom.value="";
						alert('Üzenete elküldésre került! Köszönjük!')
					}else{
						if (obj.code==false){
							alert('Hibás biztonsági kódot adott meg!\n Próbálja meg újra vagy kérjen új kódot a kép bal oldalán található ikonra kattintva!')
						}else{
						alert('Nem sikerült elküldeni az üzenetét, próbálja meg később!')
						}
					}
					//document.getElementById('captcha_img').src = 'securimage/captcha.php?sid=' + Math.random();
				},
				failure: function(r,o){

				},
				params: {
					nev: nev.getValue(),
					code: code.getValue(),
					inid: inid.getValue(),
					iid: iid.getValue(),
					uid: uid.getValue(),
					telefon: telefon.getValue(),
					tovabbi: tovabbi.getAttribute('checked'),
					megnezni: megnezni.getAttribute('checked'),
					megjegyzes: megjegyzes.getValue(),
					link:location.href,
					webcim: webcim.getValue(),
					email:email.getValue()
				}
			});
		}
	});

});


function OpenPrintWindow(){
	if (location.search.length==0)
	{
		var s='?print=1';
	}else{
		var s=location.search+'&print=1';

	}

	printLocation = location.protocol+'//'+location.host+location.pathname+s;

	window.open(printLocation,'_blank');
}
