function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function checkout_submit(){
   var chyby = 0;
   var text = ''; var result = 0;
   
   var chybny_udaj = 'Chybně vyplněný údaj';
   
   id = 'f_jmeno'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_prijmeni'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_ulice'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_mesto'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_psc'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_stat'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_tel'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_mail'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   
   id = 'f_firma'; if((document.getElementById('ch_firma').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_ico'; if((document.getElementById('ch_firma').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'f_dic'; if((document.getElementById('ch_firma').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   
   id = 'd_jmeno'; if((document.getElementById('ch_dorucovaci').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'd_prijmeni'; if((document.getElementById('ch_dorucovaci').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'd_ulice'; if((document.getElementById('ch_dorucovaci').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'd_mesto'; if((document.getElementById('ch_dorucovaci').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'd_psc'; if((document.getElementById('ch_dorucovaci').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'd_stat'; if((document.getElementById('ch_dorucovaci').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'd_tel'; if((document.getElementById('ch_dorucovaci').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'd_mail'; if((document.getElementById('ch_dorucovaci').checked == true) && (trim(document.getElementById(id).value) == '')){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   
   var vyraz = new RegExp("^[_a-zA-Z0-9-]+([\.]{1}[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+([\.]{1}[a-zA-Z0-9-]+)*[\.]{1}[a-z]{2,3}$");
   
   id = 'f_mail'; text = document.getElementById(id).value; result = text.search(vyraz); if(result == -1){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'd_mail'; text = document.getElementById(id).value; result = text.search(vyraz); if((document.getElementById('ch_dorucovaci').checked == true) && (result == -1)){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   
   if(chyby == 0){document.forms.pokladna.submit();}else{alert("Vyplňte správně formulář.");}
   
}

function foto_submit(){
   var chyby = 0;
   var text = ''; var result = 0;
   
   var chybny_udaj = 'Chybně vyplněný údaj';
   
   id = 'jmeno'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'prijmeni'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'mesto'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'mail'; if(trim(document.getElementById(id).value) == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   id = 'foto_1'; if(document.getElementById(id).value == ''){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   
   var vyraz = new RegExp("^[_a-zA-Z0-9-]+([\.]{1}[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+([\.]{1}[a-zA-Z0-9-]+)*[\.]{1}[a-z]{2,3}$");
   
   id = 'mail'; text = document.getElementById(id).value; result = text.search(vyraz); if(result == -1){chyby += 1; document.getElementById(id+'_td').innerHTML = '<span class="err">'+chybny_udaj+'</span>';}else{document.getElementById(id+'_td').innerHTML = '';}
   
   if(chyby == 0){document.forms.foto.submit();}else{alert("Vyplňte správně formulář.");}
   
}

function contact_send(){
   var chyby = 0;
   id = 'k_name'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   id = 'k_mail'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   id = 'k_text'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   
   var text = document.getElementById('k_mail').value;
	var vyraz = new RegExp("^[_a-zA-Z0-9-]+([\.]{1}[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+([\.]{1}[a-zA-Z0-9-]+)*[\.]{1}[a-z]{2,3}$");
	var result = text.search(vyraz);
	if(result == -1){chyby += 1;}
   
   if(chyby == 0){document.forms.kontakt.submit();}else{alert('Prosíme, vyplňte správně všechna povinná pole označená hvězdičkou.');}
}

$(function() {
	$('a[@rel*=lightbox]').lightBox();
});

function play(file){
	var s1 = new SWFObject('/js/player.swf','playera','275','200','9');
	s1.addParam('allowfullscreen','true');
	s1.addParam('allowscriptaccess','always');
	s1.addParam('flashvars','file='+file);
	s1.autostart = false;
	s1.write('video_player');
}

function reg_submit(){
   chyby = 0;
   id = 'name'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   id = 'surname'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   id = 'mail'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   id = 'pass'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   if(document.getElementById('pass').value != document.getElementById('pass2').value){chyby += 1;}
   
   if(chyby == 0){document.forms.reg.submit();}else{alert('Pro úspěšné dokončení registrace, prosíme, vyplňte správně všechna povinná pole označená hvězdičkou.');}
}

function comment_form_toggle(){
   $("#comment_form").slideToggle(200);
}

function comment_send(){
   var chyby = 0;
   id = 'c_name'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   id = 'c_mail'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   id = 'c_text'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   
   var text = document.getElementById('c_mail').value;
	var vyraz = new RegExp("^[_a-zA-Z0-9-]+([\.]{1}[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+([\.]{1}[a-zA-Z0-9-]+)*[\.]{1}[a-z]{2,3}$");
	var result = text.search(vyraz);
	if(result == -1){chyby += 1;}
   
   if(chyby == 0){document.forms.comment_form.submit();}else{alert('Pro vložení komentáře, prosíme, vyplňte správně všechna povinná pole označená hvězdičkou.');}
}

function recomm_send(){
   var chyby = 0;
   id = 'name'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   id = 'mail'; if(trim(document.getElementById(id).value) == ''){chyby += 1;}
   
   var text = document.getElementById('mail').value;
	var vyraz = new RegExp("^[_a-zA-Z0-9-]+([\.]{1}[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+([\.]{1}[a-zA-Z0-9-]+)*[\.]{1}[a-z]{2,3}$");
	var result = text.search(vyraz);
	if(result == -1){chyby += 1;}
   
   if(chyby == 0){document.forms.recomm.submit();}else{alert('Pro odeslání doporučení, prosíme, vyplňte správně Vaše jméno a e-mailovou adresu.');}
}

function headline_rotate(act){
   $("p.headlines").fadeOut(1000);
   if(!document.getElementById('headline_'+act)){
      act = 1;
   }
   setTimeout(function(){
      $("p#headline_"+act).fadeIn("slow");
   }, 1000);
   setTimeout(function(){
      headline_rotate(act + 1);
   }, 10000);
}

function gift_save(gift){
   var so1 = new sack();
	so1.requestFile = '/ajax/gift.php';
	so1.method = 'POST';
	so1.setVar('gift', gift);
	so1.runAJAX();
}