//Tuto funkci je potřeba vyvolat při onkeypress události textboxu. Jako parametr se předává ID submitu, který se má potvrdit, když je stisknut enter
function KontrolujEnter(event, id){
  if(event.keyCode==13 && id){
    window.document.getElementById(id).click();
    return false;
  }
  return true;
}

function TinyClean() {
	try {
		for (id in tinyMCE.editors) {
	        tinyMCE.execCommand('mceRemoveControl', false, id);
	    }
	} catch (ex) { }
}

function TinySave() {
	//testovat znaky vložená z wordu nebo outlooku
	//alert(tinyMCE.activeEditor.getContent());

	var _c = 0;
	var _s = tinyMCE.activeEditor.getContent(); // haystack

	var _m = '<!--'; // needle

	for ( var i=0 ; i<_s.length ; i++ ) {
	    if ( _m == _s.substr ( i , _m.length ) )
		_c++;
	}

	var _n = '&lt;!--';
	for ( var i=0 ; i<_s.length ; i++ ) {
	    if ( _n == _s.substr ( i , _n.length ) )
		_c++;
	}
	
	if(_c > 0){

	    alert('Zadaný text obsahuje nepovolené formátování! Zkuste překopírovat obsah do poznámkového bloku a poté znovu vložit.');
	    return false;
	    
	} else {

	    try {
		tinyMCE.triggerSave();
		return true;
	    } catch (ex) {
		alert("Chyba při ukládání textu. Pokud jste psali v editoru text, možná jste o něj přišli. To je nám moc líto. Nahlašte prosím tento problém, abychom ho mohli opravit. Děkujeme.\n\n" + ex);
		return false;
	    }

	}


	

}

function set_homepage()  
{  
	document.body.style.behavior='url(#default#homepage)';  
	document.body.setHomePage('http://www.autosystem.cz');  
}
function CreateBookmarkLink() {

 title = "AutoSystem.cz"; 
  // Blogger - Replace with <$BlogItemTitle$> 
  // MovableType - Replace with <$MTEntryTitle$>

 url = "http://www.autosystem.cz";
  // Blogger - Replace with <$BlogItemPermalinkURL$> 
  // MovableType - Replace with <$MTEntryPermalink$>
  // WordPress - <?php bloginfo('url'); ?>

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }
 




function Presmerovat(url) {
  window.location = url;
}

function ValidovatRegistraci() {  
	
	box = document.getElementById('jmeno');
	if ((box.value)=='') {
	  window.alert("Jméno je povinná položka.");
	  box.focus();
	  return false;
	} 

	box = document.getElementById('jmeno');
	var reg = /(([a-zA-Z0-9]){2,100})/ //Kontrola na minimalni delku 2 znaků
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadané jméno je příliš krátké! Jméno musí obsahovat minimálně 2 znaky.");
	  box.focus();
	  return false;
	}
	
	box = document.getElementById('prijmeni');
	if ((box.value)=='') {
	  window.alert("Příjmení je povinná položka.");
	  box.focus();
	  return false;
	}
	
	box = document.getElementById('prijmeni');
	var reg = /(([a-zA-Z0-9]){2,100})/ //Kontrola na minimalni delku 2 znaků
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadané příjmení je příliš krátké! Příjmení musí obsahovat minimálně 2 znaky.");
	  box.focus();
	  return false;
	}
	
	/*
	box = document.getElementById('psc'); 
	if ((box.value)=='') {
	  window.alert("PSČ je povinná položka.");
	  box.focus();
	  return false;
	}
	*/
	
	
	box = document.getElementById('psc');
	var reg = /^([0-9]{5}|[0-9]{3}\s[0-9]{2}){1}\s*$/ 
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("PSČ není ve správném formátu! Platný tvar PSČ je např.: 110 01");
	  box.focus();
	  return false;
	}



	box = document.getElementById('telefon');
	var reg = /^\s*[+]?\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9\s]+\s*$/ //Kontrola na minimalni delku 9 cislic
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadané telefonní číslo je ve špatném tvaru! Telefonní číslo musí obsahovat minimálně 9 číslic, nebo ponechte pole prázdné");
	  box.focus();
	  return false;
	}
		
	var box = document.getElementById('email');
	if ((box.value)=='') {
	  window.alert("Email je povinná položka.");
	  box.focus();
	  return false;
	}
	
	var reg = /\s*[a-zA-Z0-9_\-\+\.]+@([a-zA-Z0-9\-_]+\.)+[a-zA-Z]{2,4}\s*/
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadaný email není ve správném formátu. Platný email je např. jmeno.prijmeni@email.cz. ");
	  box.focus();
	  return false;
	}
	/*	
	var box = document.getElementsByName('pwd_registrace')[0];
	var box2 = document.getElementsByName('pwd_check')[0];
	
	if (box.value=='') {
	  window.alert("Heslo je povinná položka.");
	  box.focus();
	  return false;
	}
	if (box2.value=='' && box.value!='') {
	  window.alert("Zopakujte heslo.");
	  box2.focus();
	  return false;
	}
	
	
	if (!(box.value == box2.value)) {
	  window.alert("Zadaná hesla se neshodují.");
	  box2.focus();
	  return false;
	} 
	*/
	
	/*
	var label = document.getElementById('uziv_jmeno_kontrola');
	
	if (label.innerHTML != "") {
	  alert('Zvolené uživatelské jméno je již použito.');
	}
	*/
	
    var box = document.getElementsByName('confirm')[0];	
	if (!box.checked) {
	  window.alert("Je nutno vyjádřit souhlas s podmínkami.");
	  box.focus();
	  return false;
	}
	
    /*
	box = document.getElementById('captcha_code');
	if (box.value=='') {
	  window.alert("Pro ukončení registrace opište kód.");
	  box.focus();
	  return false;
	} 
    */
	
	return true;
}



function ValidovatRegistraciFirmy() {  
 	box = document.getElementById('jmeno');
	if ((box.value)=='') {
	  window.alert("Jméno je povinná položka.");
	  box.focus();
	  return false;
	} 
	
	box = document.getElementById('ic');
	if ((box.value)=='') {
	  window.alert("IČ je povinná položka.");
	  box.focus();
	  return false;
	} 

	box = document.getElementById('ic');
	var reg = /^[0-9]{8,10}$/
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadané IČ není ve správném formátu. Správný formát je např. 26329328");
	  box.focus();
	  return false;
	}
	box = document.getElementById('dic');
	if ((box.value)=='') {
	  window.alert("DIČ je povinná položka.");
	  box.focus();
	  return false;
	} 

	box = document.getElementById('dic');
	var reg = /^[a-zA-Z]{2}(\s*)[0-9]{8,10}$/
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadané DIČ není ve správném formátu. Správný formát je např. CZ26329328");
	  box.focus();
	  return false;
	}
	box = document.getElementById('sidlo_ulice');
	if ((box.value)=='') {
	  window.alert("Adresa sídla firmy je povinná položka.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('sidlo_obec');
	if ((box.value)=='') {
	  window.alert("Obec sídla firmy je povinná položka.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('sidlo_psc');
	if ((box.value)=='') {
	  window.alert("PSČ sídla firmy je povinná položka.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('sidlo_psc');
	var reg = /^([0-9]{5}|[0-9]{3}\s[0-9]{2}){1}\s*$/ 
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("PSČ není ve správném formátu! Platný tvar PSČ je např.: 110 01");
	  box.focus();
	  return false;
	}
	box = document.getElementById('misto_podnikani_ulice');
	if ((box.value)=='') {
	  window.alert("Adresa místa podnikání je povinná položka.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('misto_podnikani_obec');
	if ((box.value)=='') {
	  window.alert("Obec místa podnikání je povinná položka.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('misto_podnikani_psc');
	if ((box.value)=='') {
	  window.alert("PSČ místa podnikání je povinná položka.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('misto_podnikani_psc');
	var reg = /^([0-9]{5}|[0-9]{3}\s[0-9]{2}){1}\s*$/ 
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("PSČ místa podnikání není ve správném formátu! Platný tvar PSČ je např.: 110 01");
	  box.focus();
	  return false;
	}

	box = document.getElementById('karta_mobil');
	var reg = /^\s*[+]?\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9\s]+\s*$/ //Kontrola na minimalni delku 9 cislic
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadané číslo mobilu je ve špatném tvaru! Číslo mobilu musí obsahovat minimálně 9 číslic, nebo ponechte prázdné.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('karta_telefon');
	if ((box.value)=='') {
	  window.alert("Telefon umístěný na kartě vozu je povinná položka.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('karta_telefon');
	var reg = /^\s*[+]?\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9\s]+\s*$/ //Kontrola na minimalni delku 9 cislic
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadané číslo telefonu je ve špatném tvaru! Číslo telefonu musí obsahovat minimálně 9 číslic.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('karta_fax');
	var reg = /^\s*[+]?\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9\s]+\s*$/ //Kontrola na minimalni delku 9 cislic
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadané číslo faxu je ve špatném tvaru! Číslo faxu musí obsahovat minimálně 9 číslic, nebo ponechte prázdné.");
	  box.focus();
	  return false;
	}
	box = document.getElementById('karta_email');
	if ((box.value)=='') {
	  window.alert("Email umístěný na kartě vozu je povinná položka.");
	  box.focus();
	  return false;
	}
	var reg = /\s*[a-zA-Z0-9_\-\+\.]+@([a-zA-Z0-9\-_]+\.)+[a-zA-Z]{2,4}\s*/
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadaný email není ve správném formátu. Platný email je např. jmeno.prijmeni@email.cz. ");
	  box.focus();
	  return false;
	}
	/*
  box = document.getElementById('web');
	if ((box.value)=='') {
	  window.alert("Adresa internetových stránek je povinná položka.");
	  box.focus();
	  return false;
	} */
	
	box = document.getElementById('web');
	var reg = /^(http:\/\/)?([0-9a-z-]{1,10}\.)+([a-z]){2,4}.*$/
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadaná internetová adresa není ve správném formátu. Platná internetová adresa je např. www.automodul.cz.");
	  box.focus();
	  return false;
	}
	
  /*
	box = document.getElementById('mapa');
	if ((box.value)=='') {
	  window.alert("Mapa k sídlu firmy je povinná položka.");
	  box.focus();
	  return false;
	}
	*/
	
	box = document.getElementById('mapa');
	var reg = /^(http:\/\/)?([0-9a-z-]{1,10}\.)+([a-z]){2,4}.*$/
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadaná internetová adresa není ve správném formátu. Platná internetová adresa je např. www.automodul.cz.");
	  box.focus();
	  return false;
	}
	
  /*
	box = document.getElementById('znacky');
	if ((box.value)=='') {
	  window.alert("Seznam prodáváných značek je povinná položka.");
	  box.focus();
	  return false;
	}
  */
   
	box = document.getElementById('usr');
	if ((box.value)=='') {
	  window.alert("Uživatelské jméno je povinná položka.");
	  box.focus();
	  return false;
	}
	
	box = document.getElementById('usr');
	var reg = /^[a-z0-9.]{3,32}$/ 
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Neplatné uživatelské jméno: Uživatelské jméno smí obsahovat pouze alfanumerické znaky a tečku a musí být dlouhé 3 až 32 znaků.");
	  box.focus();
	  return false;
	} 
	
	var box = document.getElementsByName('pwd')[0];
	
	
	if ((box.value)=='') {
	  window.alert("Heslo je povinná položka.");
	  box.focus();
	  return false;
	}

	var reg = /^.{4,1000}$/ 
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Nevhodné heslo: Heslo musí obsahovat minimálně 4 znaky.");
	  box.focus();
	  return false;
	} 
	var box2 = document.getElementsByName('pwd_check')[0];
	if (box2.value=='' && box.value!='') {
	  window.alert("Zopakujte heslo.");
	  box2.focus();
	  return false;
	}
	
	if (!(box.value == box2.value)) {
	  window.alert("Zadaná hesla se neshodují.");
	  box2.focus();
	  return false;
	} 
	
	var box = document.getElementsByName('confirm')[0];	
	if (!box.checked) {
	  window.alert("Je nutno vyjádřit souhlas s podmínkami.");
	  box.focus();
	  return false;
	}
	
	
	
	return true;
}



function ValidovatPoptavku() {
  
  box = document.getElementById('jmeno');
  if ((box.value == '')) {
    window.alert("Vyplňte prosím jméno.");
    box.focus();
    return false;
  }
  
  box = document.getElementById('prijmeni');
  if ((box.value == '')) {
    window.alert("Vyplňte prosím příjmení.");
    box.focus();
    return false;
  }
  
  box = document.getElementById('ulice');
  if ((box.value == '')) {
    window.alert("Vyplňte prosím ulici.");
    box.focus();
    return false;
  }
  
  box = document.getElementById('cp');
  if ((box.value == '')) {
    window.alert("Vyplňte prosím číslo popisné.");
    box.focus();
    return false;
  }
  
  
  box = document.getElementById('obec');
  if ((box.value == '')) {
    window.alert("Vyplňte prosím obec.");
    box.focus();
    return false;
  }
  
  box = document.getElementById('psc');
	var reg = /^([0-9]{5}|[0-9]{3}\s[0-9]{2})+\s*$/ 
	if ((box.value)=='') {
	  window.alert("Vyplňte prosím PSČ.");
	  box.focus();
	  return false;
	} 
	
	box = document.getElementById('psc');
	var reg = /^([0-9]{5}|[0-9]{3}\s[0-9]{2}){1}\s*$/ 
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("PSČ není ve správném formátu. Platný tvar PSČ je např.: 110 01");
	  box.focus();
	  return false;
	} 
  
  box = document.getElementById('telefon');
	var reg = /([0-9]{5}|[0-9]{3}\s[0-9]{2})+\s*/ 
	if ((box.value)=='') {
	  window.alert("Vyplňte prosím telefon.");
	  box.focus();
	  return false;
	}
  
	box = document.getElementById('telefon');
	var reg = /^\s*[+]?\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9\s]+\s*$/ //Kontrola na minimalni delku 9 cislic
  /* var reg = /(([^0-9]?[0-9]){9,100}[^0-9]?)/ //Kontrola na minimalni delku 9 cislic */
  if (!reg.test(box.value)) {
    window.alert("Telefonní číslo není ve správném formátu, musí obsahovat minimálně 9 číslic.");
    box.focus();
    return false;
	}
	
	box = document.getElementById('email');
	if ((box.value)=='') {
	  window.alert("Vyplňte prosím email.");
	  box.focus();
	  return false;
	}
	
	var reg = /\s*[a-zA-Z0-9_\-\+\.]+@([a-zA-Z0-9\-_]+\.)+[a-zA-Z]{2,4}\s*/
	if (!reg.test(box.value) && (box.value)!='') {
	  window.alert("Zadaný email není ve správném formátu. Platný email je např. jmeno.prijmeni@email.cz. ");
	  box.focus();
	  return false;
	}
  
  
  var box = document.getElementsByName('confirm')[0];
	
  if (!box.checked) {
    window.alert("Je nutno vyjádřit souhlas s podmínkami.");
    box.focus();
    return false;
  }
  return true;
}


function ValidovatZadaniAuta() {
  year = (new Date()).getYear();
  if (year < 2000) year += 1900;
  
  var box = document.getElementsByName('znacka')[0];
  var box1 = document.getElementsByName('znacka_man')[0];  
  
  if (box.value == 0 || (box.value =='man' && box1.value == '')) {
    window.alert("Není zadána značka.");
    box.focus();
    return false;
  }

  var box = document.getElementsByName('model')[0];
  var box1 = document.getElementsByName('model_man')[0];  
  
  if (box.value == 0 || (box.value =='man' && box1.value == '')) {
    window.alert("Není zadán model.");
    box.focus();
    return false;
  }

  
  /*
  var box = document.getElementsByName('vzor')[0];
  var box1 = document.getElementsByName('vzor_man')[0];  
  
  if (box.value == 0) {
    window.alert("Není zadáno upřesnění modelu.");
    box.focus();
    return false;
  }
  */
  
  var box = document.getElementsByName('vykon')[0];

  var reg =/^[0-9]{1,3}$/
  if (!reg.test(box.value)) {
    window.alert("Neplatný výkon motoru:\n\nVýkon musí být číslo od 0 do 999.");
    box.focus();
    return false;
  }


  var box = document.getElementsByName('objem')[0];
  
  var reg =/^([0-9]{2,5}|[0-9]{1,2}\s[0-9]{3,3})$/
  if (!reg.test(box.value)) {
    window.alert("Neplatný objem motoru:\n\nObjem musí být číslo od 10 do 99 999.");
    box.focus();
    return false;
  }
  
  
  var box = document.getElementById('barva');
  var box2 = document.getElementById('barva_man');
  
  var reg =/^.+$/
  if (box.value == 0 || (box.value == 'man' && box2.value == '')) {
      window.alert("Není zadána barva.\n\nBarva je povinný údaj.");
      box.focus();
      return false;
  }
  
  
  var box = document.getElementsByName('najeto')[0];
  
  var reg =/^([0-9]{1,7}|[0-9]{1,3}(\s[0-9]{3,3}){1}|[0-9]{1}(\s[0-9]{3,3}){2})$/
  if (!reg.test(box.value)) {
    window.alert("Neplatný počet najetých kilometrů:\n\nNajeto musí být číslo od 0 do 9 999 999.");
    box.focus();
    return false;
  }

//Vazba najeto a stav  
  var najeto = document.getElementsByName('najeto')[0];
	var stav = document.getElementsByName('stav')[0];
	
	if (stav.selectedIndex == 0 && najeto.value > 0) {
		window.alert("Nový vůz nesmí mít najety žádné kilometry.");
		najeto.focus();
		return false;
	}
	
	if (stav.selectedIndex == 2 && najeto.value == 0) {
		window.alert("Referenční vůz nesmí mít nulové kilometry.");
		najeto.focus();
		return false;
	}
	
	//getElementById('stav').value == id_stavu (podle ostré DB)
		
	if (stav.selectedIndex == 3 && !(najeto.value > 0)) {
		window.alert("Ojetý vůz musí mít najeté kilometry.");
		najeto.focus();
		return false;
	}
  
	var box = document.getElementsByName('rok_vyroby')[0];
  var reg =/^[0-9]{4}$/
  if (!reg.test(box.value) || box.value > year || box.value < "1900") {
    window.alert("Neplatný rok výroby:\n\nRok výroby musí být číslo mezi 1900 a " + year + ".");
    box.focus();
    return false;
  }
  
  
  var box = document.getElementsByName('cena')[0];
  
  var reg =/^([0-9]{4,8}|[0-9]{1,3}(\s[0-9]{3,3}){1}|[0-9]{1,2}(\s[0-9]{3,3}){2})$/
  if (!reg.test(box.value)) {
    window.alert("Neplatná cena:\n\nCena musí být číslo od 1 000 do 99 999 999.");
    box.focus();
    return false;
  }
  cena = box.value;
  
  /*
  var box = document.getElementsByName('bezna_cena')[0];
  
  if (box.value != "") {
    var reg =/^[0-9]{4,8}$/
    if ((!reg.test(box.value)) || box.value <= cena) {
      window.alert("Neplatná běžná cena cena:\n\nBěžná cena musí být číslo od 1 000 do 99 999 999 a musí být vyšší než zadaná cena. Nemusí být zadána.");
      box.focus();
      return false;
    }
  }
  */
	 
/*
var box = document.getElementsByName('fotonocheck');

//fotky
if (box.length == 0) {
	cnt = 0;
	for (i = 0; i < 10; i++) {
		fotka = document.getElementsByName('foto' + i)[0];
		if (fotka.value != '') 
			cnt++;
	}
	if (!cnt) {
		window.alert('Zadejte alespoň jednu fotografii.');
		return false;
	}
}
*/

  return true;
}


function NahratNovouFotkuNaKarte(url_cela, url_nahled, index) {
	
	var content = '<a id="hlavni_fotka_link" rel="lightbox" target="_blank" href=""><img id="hlavni_fotka" alt="" src="" /></a>';
	
	
	
	
	layer = document.getElementById('hl-foto-in') ;
	layer.innerHTML = content ;
	
	var a = document.getElementById('hlavni_fotka_link');
	var img = document.getElementById('hlavni_fotka');
	
	a.href = url_cela;
	img.src = url_nahled;
	
	$('.minifoto').attr('rel', 'lightbox');
	$('#minifoto' + index).attr('rel', '');
	  
	$('a[@rel*=lightbox]').lightBox();
}

function ZobrazitKompletniVybavyNaKarte() {
    var e1 = document.getElementById('vybava-prepinac');
    var e2 = document.getElementById('dalsi-vybava');

    e1.style.display = "none";
    e2.style.display = "block";
}

function PrepnoutViditelnostZnacky() {
    var e0 = document.getElementById('znacka');
    var e1 = document.getElementById('znacka_man');
    var e3 = document.getElementById('model_man');
    var e6 = document.getElementById('model');
    var e4 = document.getElementById('vzor');
    //var e5 = document.getElementById('typ');
    
    
    if (e0.value == 'man') {
      e1.style.display = "";
      e3.style.display = "";
      if (e4) e4.style.display = "none";
      e5.style.display = "";
  	  e5.value = "";
      e6.style.display = "none";
	  e6.value = "man";
      
    } else {
      e1.style.display = "none";
      e3.style.display = "none";
      if (e4) e4.style.display = "";
      e5.style.display = "none";
      e6.style.display = "";
      
    }
}

function PrepnoutViditelnostModelu() {
    var e0 = document.getElementById('model');
    var e1 = document.getElementById('model_man');
    var e2 = document.getElementById('model');
    var e4 = document.getElementById('vzor');
    //var e5 = document.getElementById('typ');
    
    if (e0.value == 'man') {
      e1.style.display = "";
      if (e4) e4.style.display = "none";
      if (e5) e5.style.display = "";
	  if (e5) e5.value = "";
    } else {
      e1.style.display = "none";
      if (e4) e4.style.display = "";
      //if (e5) e5.style.display = "none";
    }
}

function PrepnoutViditelnostVzoru() {
    var e0 = document.getElementById('vzor');
    var e2 = document.getElementById('typ');
    
    if (e0.value == 'man') {
      e2.style.display = "";
	  e2.value = "";
    } else {
      e2.style.display = "none";
    }
}
function PrepnoutViditelnostBarev() {
    var e0 = document.getElementById('barva');
    var e2 = document.getElementById('barva_man');
    
    if (e0.value == 'man') {
      e2.style.display = "";
    } else {
      e2.style.display = "none";
    }
}

function ZmenaStavu(){

	if( document.getElementById('stav').value == '23' ){
		$('.stav-leasing').css('display','inline');
	} else {
		$('.stav-leasing').css('display','none');
	}

  var dph_pamet = document.getElementById('dph').checked;
	if (document.getElementById('stav').selectedIndex == 0 ) {
	 document.getElementById('dph').checked = true;
	 document.getElementById('dph').disabled = true;
  } else {
    document.getElementById('dph').disabled = false;
  }

  DphChanged();
}

function DphChanged(){   
    $('#dph_hidden').attr( 'value' , $('#dph').attr('checked') ? '1' : '' );
}


function otevrit_okno(url, width, height) {
   if (screen.height) {
      screenY = screen.height
      screenX = screen.width
   }

   var top = ((screenY/2)-(height/2)-40);
   var left = ((screenX/2)-(width/2));
   x = window.open('/popup' + url,'','resizable=no,status=yes,scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left+'');
   if (x) return false;
}

function stat_cust(pv_id, parameter, value) {
	var url;
	url = '/scripts/automodul/statcust.php?id=' + urlencode(pv_id)
	+ '&p=' + urlencode(parameter) + '&v=' + urlencode(value);
	$.get(url);
}

function stat_pv(pv_id) {
	var url;
	url = '/scripts/automodul/statpv.php?id=' + urlencode(pv_id);
	$.get(url);
}

function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                                     
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}



function tooltip() {
	/* CONFIG */
		xOffset = 10;
		yOffset = 20;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$(".tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};


$(document).ready(function(){tooltip();});