// ##########     Funkce vycentrování     ##########
function getWidth() {
	if (window.innerWidth) w=window.innerWidth;    	   			 	   // zjištění šířky okna (NN)
	else if (document.body.clientWidth) w=document.body.clientWidth;   // zjištění šířky okna (MSIE)
	y = (w-950) /2													   // výpočet umístění levého okraje hlavního framu
	y = Math.round(y);												   // zaokrouhlení výsledku
	return eval(y);	  	  											   // vrácení pořadované hodnoty
}

function nahled(aaa,bbb) {
	prewiev2 = window.open(aaa+'/obrazek.html?'+bbb,'nahledy','toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,width=200,height=100,left=10,top=10');
	prewiev2.window.focus();
}

function nahled2(aaa,bbb,popis,photos,lang) {
	prewiev2 = window.open(aaa+'/obrazek.php?obrazek='+bbb+'&amp;popis='+popis+'&amp;photos='+photos+'&amp;lang='+lang,'nahledy','toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,width=200,height=100,left=10,top=10');
	prewiev2.window.focus();
}

var dva = "2";

//	Vyměna barvy pozadí
function setBgColor (id, color) {
  if (document.layers)
    document[id].bgColor = color == 'transparent' ? null : color;
  else if (document.all)
    document.all[id].style.backgroundColor = color;
  else if (document.getElementById)
    document.getElementById(id).style.backgroundColor = color;
}

//	Vyměna obrázku pozadí
function setBgImage (id, imageURL) {
  if (document.layers)
    document[id].background.src = imageURL == 'none' ? null : imageURL;
  else if (document.all)
    document.all[id].style.backgroundImage = imageURL == 'none' ? 'none'
: 'url(' + imageURL + ')';
  else if (document.getElementById)
    document.getElementById(id).style.backgroundImage = imageURL ==
'none' ? 'none' : 'url(' + imageURL + ')';
}


//	Přepočet do jiných měn + zaokrouhlení
function setcurr(price,eur,usd) {
	if(document.ex_rate.exchange.value == '1') { document.ex_rate.endprice.value = split_kilo(eval(price),'.') + ',- CZK'; }	//
	if(document.ex_rate.exchange.value == '2') { document.ex_rate.endprice.value = split_kilo(Math.round(eval(price) / eval(eur) / 10) * 10,'.') + ' €'; }	//	€1,000,000
	if(document.ex_rate.exchange.value == '3') { document.ex_rate.endprice.value = '$' + split_kilo(Math.round(eval(price) / eval(usd) / 10) * 10,','); }	//	$1,000,000
}

//	Přepočet do jiných měn + zaokrouhlení (m2)
function setcurr2(price,eur,usd) {
	if(document.ex_rate.exchange.value == '1') { document.ex_rate.endprice.value = split_kilo(eval(price),'.') + ',- CZK / m2'; }	//
	if(document.ex_rate.exchange.value == '2') { document.ex_rate.endprice.value = split_kilo(Math.round(eval(price) / eval(eur) / 10) * 10,'.') + ' € / m2'; }	//	€1,000,000
	if(document.ex_rate.exchange.value == '3') { document.ex_rate.endprice.value = '$' + split_kilo(Math.round(eval(price) / eval(usd) / 10) * 10,',') + ' per m2'; }	//	$1,000,000
}

// Kontrola emailové adresy
function check_email(adresa) {
		re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;
		return adresa.search(re) == 0;
}

//	Odeslání dotazu k inzerátu
function sendquest() {

	var mail = /^([a-zA-Z0-9._-]+)@([a-zA-Z0-9._-]+)\.([a-zA-Z]{2,5})$/;
/*
	if(document.question.qname.value == "") {
		alert("Vyplňte, prosím, Vaše jméno a příjmení!");
		document.question.qname.focus();
		return false;
	}
*/
	if(document.question.qemail.value == "" || document.question.qemail.value == "@") {
		alert("Vyplňte, prosím, Vaši emailovou adresu!");
		document.question.qemail.focus();
	   document.question.qemail.select();
		return false;
	}
	if (mail.test(document.question.qemail.value) == 0) {
		alert ("Vaše emailová adresa není vyplněna správně!");
		document.question.qemail.focus();
		document.question.qemail.select();
		return false;
	}
	if(document.question.qmessage.value == "") {
		alert("Nelze odeslat prázdnou zprávu!");
		document.question.qmessage.focus();
		return false;
	}
	document.question.submit();

}

//	Registrace makléře
function reg_broker() {

	mail = /^([a-zA-Z0-9._-]+)@([a-zA-Z0-9._-]+)\.([a-zA-Z]{2,5})$/;
	tel = /^[\+][0-9]{3}[ ][0-9]{9}$/;

//	Kontrola e-mailu
	if ( document.regbrok.email.value == "" ) {
		alert("Vyplňte prosím Vaši e-mailovou adresu");
		document.regbrok.email.focus();
		return false;
	}

	if (mail.test(document.regbrok.email.value) == 0) {
		alert ("E-mailová adresa není platná");
		document.regbrok.email.focus();
		document.regbrok.email.select();
		return false;
	}

//	Kontrola hesla
	if (document.regbrok.pass1.value.length <= 5) {
		alert ("Heslo je příliš krátké");
		document.regbrok.pass1.focus();
		document.regbrok.pass1.select();
		return false;
	}

	if (document.regbrok.pass1.value != document.regbrok.pass2.value) {
		alert ("Zadaná hesla nejsou totožná!");
		document.regbrok.pass2.focus();
		document.regbrok.pass2.select();
		return false;
	}

	if ( document.regbrok.name.value == "" ) {
		alert("Vyplňte prosím Vaše jméno.");
		document.regbrok.name.focus();
		return false;

	}

	if ( document.regbrok.family.value == "" ) {
		alert("Vyplňte prosím Vaše příjmení.");
		document.regbrok.family.focus();
		return false;

	}

	if ( document.regbrok.address1.value == "" ) {
		alert("Vyplňte prosím Vaši adresu.");
		document.regbrok.address1.focus();
		return false;

	}

	if ( document.regbrok.city.value == "" ) {
		alert("Vyplňte prosím Vaše město.");
		document.regbrok.city.focus();
		return false;

	}

	if ( document.regbrok.zip.value == "" ) {
		alert("Vyplňte prosím Vaše poštovní směrovací číslo.");
		document.regbrok.zip.focus();
		return false;

	}

	if (document.regbrok.phone.value == "") {
		alert ("Vyplňte prosím telefonní číslo");
		document.regbrok.phone.focus();
		return false;
	}
/*
//	Kontrola správného zadání telefonního čísla
	if (document.regbrok.phone.value != "" && document.regbrok.phone.value.length < 9) {
		alert ("Telefonní číslo není platné!");
		document.regbrok.phone.focus();
		document.regbrok.phone.select();
		return false;
	}

// Kontrola formátu telefonního čísla
	if (document.regbrok.phone.value != "" && tel.test(document.regbrok.phone.value) == 0) {
		alert ("Telefonní číslo není zadáno ve správném formátu");
		document.regbrok.phone.focus();
		document.regbrok.phone.select();
		return false;
	}
*/
	if (document.regbrok.accept.checked) {
		dotaz = window.confirm("Jste si jistí, že všechny údaje jsou správně vyplněny?");
		if (dotaz == true) document.regbrok.submit();
	} else {
		alert ("Musíte souhlasit se Smluvními podmínkami!");
		document.regbrok.accept.focus();
		return false;
	}

}

function add_real() {
/*
	if ( document.addreal.code.value == "" ) {
		alert("Vyplňte prosím kód nemovitosti");
		document.addreal.code.focus();
		return false;
	}
*/
	if ( document.addreal.title.value == "" ) {
		alert("Vyplňte prosím název nemovitosti");
		document.addreal.title.focus();
		return false;
	}

	if ( document.addreal.price.value == "" ) {
		alert("Vyplňte prosím cenu nemovitosti");
		document.addreal.price.focus();
		return false;
	}

	document.addreal.submit();

}

function smazat(id,listby,lng) {

	if (lng == "cs") dotaz = window.confirm("Chcete záznam s ID " + id + " skutečně smazat?");
	if (lng == "en") dotaz = window.confirm("Do you want delete record with ID " + id + ".\n Are you sure?");
	if (lng == "nl") dotaz = window.confirm("Do you want delete record with ID " + id + ".\n Are you sure?");
	if (dotaz == true) window.location='index.php?page=admin&action=delete&id_cat=' + id + '&lang=' + lng + '&listby=' + listby;

}

//	Oddělovač tisíců s možnosti volby dělícího znaku
function split_kilo(co,znak) {

	co = co + '';
	var len = co.length;
	var res = '';

	if(len <= 3) res = co;
	if(len > 3 && len <= 6) res = co.substring(0,len-3) + znak + co.substring(len-3,len);
	if(len > 6 && len <= 9) res = co.substring(0,len-6) + znak + co.substring(len-6,len-3) + znak + co.substring(len-3,len);
	if(len > 9 && len <= 12) res = co.substring(0,len-9) + znak + co.substring(len-9,len-6) + znak + co.substring(len-6,len-3) + znak + co.substring(len-3,len);
	if(len > 12 && len <= 15) res = co.substring(0,len-12) + znak + co.substring(len-12,len-9) + znak + co.substring(len-9,len-6) + znak + co.substring(len-6,len-3) + znak + co.substring(len-3,len);

	return res;

}

function ClipBoard(tekst) 
{
holdtext.innerText = tekst;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}

