function kat1Change(){
		var kat1_index = document.frm_katfilter.kat1.selectedIndex;
		document.frm_katfilter.kat2.options.length = 1;		
		if(kat1_index == 0) return;
		for(var i=1; i < kat2s[kat1_index].length; i++){
			addItem('kat2',kat2s[kat1_index][i]);
		}
}

function addItem(box, id) {
   var sel = document.getElementById(box);
   var opt = document.createElement("OPTION");
   opt.value = id;
	var txt = document.createTextNode(id);
	opt.appendChild(txt);
   sel.appendChild(opt);
}

function kat2Change(){
	var kat1_index = document.frm_katfilter.kat1.selectedIndex;
	var kat2_index = document.frm_katfilter.kat2.selectedIndex;
	document.frm_katfilter.kat3.options.length = 1;
	if(kat2_index == 0) return;
	for(var i=1; i < kat3s[kat1_index][kat2_index].length; i++){
		addItem('kat3',kat3s[kat1_index][kat2_index][i]);
	}
}

function ValidateEmail( email){
	var regStr = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if( !regStr.test(email)){
		alert("Vámi zadaná e-mailová adresa nemá platný formát.");
		return false;
	}
	return true;
}

function ValidateEmailNotStrict( email){
	if(email == '') return true;
	var regStr = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if( !regStr.test(email)){
		alert("Vámi zadaná e-mailová adresa nemá platný formát.");
		return false;
	}
	return true;
}

function ValidateNotEmpty( values){
	for(var i=0; i<values.length; i++){
		if(values[i] == ''){
			alert("Vyplňte prosím požadované údaje.");
			return false;
		}
	}
	return true;
}

function HighlightSearchButton(){
	document.getElementById("findBtn").src = "/img/find_highlighted.gif";
}

function create_account(){
	if( !ValidateEmail(document.frm_create_account.email_address.value) ) return false;
	var notempties = new Array(document.frm_create_account.firstname.value, document.frm_create_account.lastname.value, document.frm_create_account.street_address.value, document.frm_create_account.city.value, document.frm_create_account.postcode.value, document.frm_create_account.password.value, document.frm_create_account.confirmation.value, document.frm_create_account.telephone.value);
	if( !ValidateNotEmpty(notempties) ) return false;
	
	if(document.frm_create_account.password.value != document.frm_create_account.confirmation.value){
		alert("Hesla se neshodují, prosím opravte.");
		return false;
	}
	return true;
}

function bazar(frm){
  var kontakt = frm.email.value + frm.telefon.value;
  if ( frm.email.value != '' && !ValidateEmail(frm.email.value) ) return false;
  if( ValidateNotEmpty( new Array( frm.predmet.value, frm.cena.value, frm.jmeno.value, kontakt ) )  ) return true;
	return false;
}

function objednat(){
  if( !ValidateEmail(document.checkout_form.email.value) ) return false;
	var notempties = new Array(document.checkout_form.firstname.value, document.checkout_form.lastname.value, document.checkout_form.street_address.value, document.checkout_form.city.value, document.checkout_form.postcode.value, document.checkout_form.telephone.value);
	if( !ValidateNotEmpty(notempties) ) return false;	
	return true;
}

function updatePayment(){
	document.checkout_form.shipping.disabled = false;
	if(document.checkout_form.payment.value==p_id[1]){
			deleteItems('shipping');
			newItem('shipping',0);
			newItem('shipping',2);
			newItem('shipping',3);
			document.getElementById('hlaska_karta').style.display='none';
			document.getElementById('hlaska_splatka').style.display='none';
	}else if(document.checkout_form.payment.value==p_id[2]){
			deleteItems('shipping');
			newItem('shipping',0);
			newItem('shipping',4);
			newItem('shipping',5);
			document.getElementById('hlaska_karta').style.display='none';
			document.getElementById('hlaska_splatka').style.display='none';
	}else if(document.checkout_form.payment.value==p_id[3]){
			deleteItems('shipping');
			newItem('shipping',1);
			document.getElementById('hlaska_karta').style.display='none';
			document.getElementById('hlaska_splatka').style.display='none';
	}else if(document.checkout_form.payment.value==p_id[4]){
			deleteItems('shipping');
			newItem('shipping',0);
			newItem('shipping',6);
			newItem('shipping',7);
			document.getElementById('hlaska_karta').style.display='none';
			document.getElementById('hlaska_splatka').style.display='none';
	}else if(document.checkout_form.payment.value==p_id[5]){
			deleteItems('shipping');
			newItem('shipping',0);
			newItem('shipping',8);
			newItem('shipping',9);
			document.getElementById('hlaska_karta').style.display='none';
			document.getElementById('hlaska_splatka').style.display='none';
	}else if((document.checkout_form.payment.value==p_id[6]) || (document.checkout_form.payment.value==p_id[7]) || (document.checkout_form.payment.value==p_id[8]) || (document.checkout_form.payment.value==p_id[9])){
			deleteItems('shipping');
			newItem('shipping',0);
			newItem('shipping',2);
			newItem('shipping',3);
			document.getElementById('hlaska_karta').style.display='block';
			document.getElementById('hlaska_splatka').style.display='none';
	}else if((document.checkout_form.payment.value==p_id[10]) || (document.checkout_form.payment.value==p_id[11]) || (document.checkout_form.payment.value==p_id[12]) || (document.checkout_form.payment.value==p_id[13])){
			deleteItems('shipping');
			newItem('shipping',0);
			newItem('shipping',6);
			newItem('shipping',7);
			document.getElementById('hlaska_karta').style.display='block';
			document.getElementById('hlaska_splatka').style.display='none';
	}else if(document.checkout_form.payment.value==p_id[14]){
			deleteItems('shipping');
			newItem('shipping',0);
			newItem('shipping',1);
			newItem('shipping',3);
			newItem('shipping',10);
			document.getElementById('hlaska_karta').style.display='none';
			document.getElementById('hlaska_splatka').style.display='block';
	}else{
		deleteItems('shipping');
		newItem('shipping',0);
		//document.checkout_form.shipping.disabled = true;
		document.getElementById('hlaska_karta').style.display='none';
	  document.getElementById('hlaska_splatka').style.display='none';
	}
}

function deleteItems(box){
	var sel = document.getElementById(box);
	sel.options.length = 0;
}

function newItem(box, id) {
	var sel = document.getElementById(box);
	var opt = document.createElement("OPTION");
		
	if(box=='shipping'){
		if( id == 0 ){
			opt.value = 0;
			var txt = document.createTextNode("-- Vyberte způsob dopravy --");
		}else{
			opt.value = s_method[id]+";"+s_price[id];
			var txt = document.createTextNode(s_method[id]+" (+"+s_priceformated[id]+")");	
			//var txt = document.createTextNode(s_method[id]);		
		}	
	if(s_posted == opt.value) opt.selected = true; 
	}
	else if (box=='payment'){
		if( id == 0 ){
			opt.value = 0;
			var txt = document.createTextNode("-- Vyberte způsob platby --");
		}else{
			opt.value = p_method[id]+";"+p_price[id];
			var txt = document.createTextNode(p_method[id]+" (+"+p_priceformated[id]+")");
		}
	}
	opt.appendChild(txt);
	sel.appendChild(opt);
}

function SetShipping(){
	if( (document.checkout_form.payment.value == 0) || (document.checkout_form.shipping.value == 0) ){ 
		
		alert('Vyberte prosím způsob dopravy a platby.'); 
		return false;
	} 
	return true;
}

function modinfoPrvni(){
	var notempties = new Array(document.frm_change_account.firstname.value, document.frm_change_account.lastname.value, document.frm_change_account.street_address.value, document.frm_change_account.city.value, document.frm_change_account.postcode.value, document.frm_change_account.telephone.value);
	if( !ValidateNotEmpty(notempties) ) return false;	
	return true;
}

function modinfoDruhy(){
	var notempties = new Array(document.frm_change_account.password.value, document.frm_change_account.confirmation.value);
	if( !ValidateNotEmpty(notempties) ) return false;
	if(document.frm_change_account.password.value != document.frm_change_account.confirmation.value){
		alert("Hesla se neshodují, prosím opravte.");
		return false;
	}
	return true;
}

function modinfoTreti(){
	var notempties = new Array(document.frm_change_account.firstname.value, document.frm_change_account.lastname.value, document.frm_change_account.street_address.value, document.frm_change_account.city.value, document.frm_change_account.postcode.value);
	if( !ValidateNotEmpty(notempties) ) return false;
	return true;
}

var wnd = false;
function OpenWindow(kam, attribs){
	if( !wnd || wnd.closed ) {
		wnd = window.open(kam, null, attribs);
	}else{
		wnd.focus();
		wnd.location=kam;
	}	
}

function setSelectedVar(radio){
  selectedVar = radio.value;
}

function UpdateInfoTextHeights(div1, div2){
	var h1 = div1.offsetHeight;
	var h2 = div2.offsetHeight;
	if(h1 > h2) div2.style.height = (h1-20)+"px";
	else div1.style.height = (h2-20)+"px";
}

function profil(){
	var notempties = new Array(document.frm_change_account.firstname.value, document.frm_change_account.lastname.value, document.frm_change_account.street_address.value, document.frm_change_account.city.value, document.frm_change_account.postcode.value, document.frm_change_account.telephone.value);
	if( !ValidateNotEmpty(notempties) ) return false;	
	if(document.frm_change_account.password.value != document.frm_change_account.confirmation.value){
		alert("Hesla se neshodují, prosím opravte.");
		return false;
	}
	return true;
}

function pujcovna(){
  if( document.frm_create_reserve.do1.value == 'zpet' ) return true;
  if( !ValidateEmail(document.frm_create_reserve.email_address.value) ) return false;
	var notempties = new Array(document.frm_create_reserve.firstname.value, document.frm_create_reserve.lastname.value, document.frm_create_reserve.street_address.value, document.frm_create_reserve.city.value, document.frm_create_reserve.postcode.value, document.frm_create_reserve.telephone.value);
	if( !ValidateNotEmpty(notempties) ) return false;
	return true;
}
