 
 

_editor_url = "../lib/HTMLArea/";
_editor_lang = "cz";
_relative_url = "";

function potvrzeni(f){
	//window.alert("href: "+f.getAttribute('href'));
	if(null == f.getAttribute('ask')) 
		window.location.href=f.getAttribute('href');
	else
		if(confirm(f.getAttribute('ask')))
			window.location.href=f.getAttribute('href');
}

function isEmpty(str) {
	for (var intLoop = 0; intLoop < str.length; intLoop++)
		if (" " != str.charAt(intLoop))
			return false;
	return true;
}

function Cislo(event) {
	if (((event.keyCode < 43) || (event.keyCode > 57)) && (event.keyCode != 47)) 
		event.returnValue = false;
}
	
function Datum(event) {
	if (((event.keyCode < 46) || (event.keyCode > 57)) && (event.keyCode != 47)) 
		event.returnValue = false;
}
	
function Countit(textarea,pocet) {
	//var str = document.forms[0].text.value;
	if(textarea.value.length>pocet)
		textarea.value = textarea.value.substr(0,pocet);
	//document.getElementById("charsWritten").innerHTML = textarea.value.length;
	//document.getElementById("charsLeft").innerHTML = pocet - textarea.value.length;
	textarea.parentElement.charslenght.value = textarea.value.length + '/' + (pocet - textarea.value.length);
}

function check_all(f) {
	var strError = "";
	var form;  
	var req;  
	var val,x,pop;  
	
	for (var intLoop = 0; intLoop<f.elements.length; intLoop++){
		form=f.elements[intLoop].getAttribute("format");
		req =f.elements[intLoop].getAttribute("required");
		pop =f.elements[intLoop].getAttribute("popis");
		val=f.elements[intLoop].value;
		x=true;
		if (null== pop) 
			pop =f.elements[intLoop].name ; 
		
		if (null!=req && isEmpty(f.elements[intLoop].value)) 
			strError += "Vyplnit položku :  " + pop + "\n";
		
		if (null!= form && !isEmpty(f.elements[intLoop].value))
			x=check_it(f.elements[intLoop].value,form);
			
		if(!x)
			strError += "Chybný formát  "+ pop + " -> "  + form +"\n";
		
	}//cyklus
	if ("" != strError) {
		alert("Chybové hlášení:\n" + strError);
		return false;
	}
}

function check_it(item,f) {
	// definice proměnných
	var pom=".";
	var text;
	//načtení formátu a required
	var typ = f.substring(0,1); 
	var p   = f.indexOf(pom);
	var d   = f.length;
	
	switch(typ){
	case "f" :	//čísla s desetinnou  fx.y   x - počet míst celých, y-počet za desetinnou čárou
		var horni=f.substring(1,p);
		var dolni=f.substring(p+1,d);
		x="^[-\+]?[0-9]{0,"+horni+"}([\\.\\,]{1}[0-9]{0,"+dolni+"}){0,1}$";
		re=new RegExp(x,"");
		var arr=item.match(x)
		x=(arr == null)?false:true;	
	break;
	
	case "n" :
		var horni=f.substring(1,p);
		var dolni=f.substring(p+1,d);
		x="^[-\+]?[0-9]{"+dolni+","+horni+"}$";
		re=new RegExp(x,"i");
		var arr=item.match(x)
		x=(arr == null)?false:true;	
	break;
	
	case "c" :
		var horni=f.substring(1,p);
		var dolni=f.substring(p+1,d);
		x="^.{"+dolni+","+horni+"}$";
		re=new RegExp(x,"i");
		var arr=item.match(x)
		x=(arr == null)?false:true;	
	break;
		
	case "e" :		
		x="^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$";
		re=new RegExp(x,"i");
		var arr=item.match(x)
		x=(arr == null)?false:true;	
	break;
	
	case "d" :
		x="^([0-9]{1,2})[-\\.]{1}([0-9]{1,2})[-\\.]{1}[0-9]{4}$";
		re=new RegExp(x,"i");
		var arr=item.match(x)
		x=(arr == null)?false:true;	
	break;
	}
	return(x)
}

function Zobrazeni(but,obj,zobraz,skryj){
	if(but.value == zobraz) {
		but.value=skryj;
		obj.style.display = '';
	}
	else{
		but.value=zobraz;
		obj.style.display = 'none';
	}
}

function showKart(e,b){
	var pole_div=document.getElementsByTagName('div');
	
	for(var intLoop=0; intLoop<pole_div.length; intLoop++){
		if(pole_div[intLoop].id){
			if(pole_div[intLoop].id){
				if(pole_div[intLoop].id.substr(0,2)=='b_'){
					pole_div[intLoop].className='zalozka';
				}
			}
			
			if(pole_div[intLoop].id.substr(0,2)=='l_'){
				pole_div[intLoop].style.visibility='hidden';
				pole_div[intLoop].style.display = 'none';
			}
		}
	}
	
	document.getElementById(b).className='zalozka-activ';
	document.getElementById(e).style.visibility='visible';
	document.getElementById(e).style.display = 'block';
}


