function createCookie(name,value,time) {
	if (time) {
		var date = new Date();
		date.setTime(date.getTime()+(time*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function obtiznost_hesla(idInput,idDiv) {
	elObtHesla=document.getElementById(idInput);
	elObtHesla2=document.getElementById(idDiv);
	elObtHesla.onkeyup=function() {
		obtiznost_hesla_zmena(elObtHesla,elObtHesla2);
	}
	obtiznost_hesla_zmena(elObtHesla,elObtHesla2);
}

function obtiznost_hesla_zmena(el,el2) {
	var obtiznost=0;
	var heslo=el.value;
	if (obtiznost_hesla_pocet(heslo,"abcdefghijklmnopqrstuvwxyz")) {obtiznost+=15;}
	if (obtiznost_hesla_pocet(heslo,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {obtiznost+=20;}
	if (obtiznost_hesla_pocet(heslo,"0123456789")) {obtiznost+=20;}
	if (obtiznost_hesla_pocet(heslo,"áčďěéíňóřšťúůýž")) {obtiznost+=10;}
	if (obtiznost_hesla_pocet(heslo,"ÁČĎĚÉÍŇÓŘŠŤÚŮÝŽ")) {obtiznost+=10;}
	if (obtiznost_hesla_pocet(heslo,".-_%=/!?,")) {obtiznost+=15;}
	
	obtiznost=Math.pow(obtiznost,Math.pow(heslo.length,1/3));
	if (obtiznost>0) obtiznostLog=Math.log(obtiznost);
		else obtiznostLog=0;
	obtiznostLog=Math.ceil(obtiznostLog*2);
	obtiznostLog-=5;
	
	if (obtiznostLog>16) obtiznostLog=16;
	if (obtiznostLog<0) obtiznostLog=0;
	
	if (obtiznostLog<6) barva="#FF0000";
	else if (obtiznostLog<8) barva="#FF9900";
	else if (obtiznostLog<11) barva="#999900";
	else barva="#009900";
	
	tip="";
	if (obtiznostLog>0 && obtiznostLog<8) tip="<div><small><br />Vaše heslo je slabé.<br />Zkuste jej prodloužit, použít velká i malá písmena, znaky s diakritikou nebo číslice.<small></div>";	
	if (obtiznostLog>0 && obtiznostLog<6) tip="<div><small><br />Vaše heslo je velmi slabé.<br />Zkuste jej prodloužit, použít velká i malá písmena, znaky s diakritikou nebo číslice.<small></div>";
	
	el2.innerHTML="	<div style='float:left; margin-right:20px;'>Síla hesla: </div>		<div style='float:left; margin-top:4px; border:solid 1px black; width:160px; height:10px;'>			<div style='width:"+(obtiznostLog*10)+"px; height:10px; background:"+barva+";'></div>		</div>		<div style='float:left; margin-left:20px;'>"+obtiznostLog+" bodů</div>		<div class='cleaner'></div>	"+tip+"";
	
}
function obtiznost_hesla_pocet(zdroj,skupina) {
	var vrat=false;
	for (i=0;i<skupina.length;i++) {
		if (zdroj.indexOf(skupina.charAt(i))!=-1) vrat=true;
	}
	return vrat;
}
var formAutoVal=new Array();
var formPuvodniClass=new Array();
function checkAutoVal(zdroj,id) {
	if (formAutoVal[id]==undefined || formAutoVal[id]=="") return;
	if (zdroj.value==formAutoVal[id]) {
		zdroj.value="";
		zdroj.className=formPuvodniClass[id];
	}
}
createCookie("js","a",900);

function kontrola_vychoziho_textu_hledej(zdr,vych) {
	if (zdr.value==vych) zdr.value="";
}

function trim(vstup,nbsp) {
	if (nbsp==undefined) nbsp=false;
	//zleva
	vstup=vstup+"";
	while (vstup.charAt(0)==" " || vstup.charAt(0)=="\n" || vstup.charAt(0)=="\r" || vstup.charAt(0)=="\t") {
		vstup=vstup.substring(1);
	}
	//zprava
	konec=vstup.length-1;
	while (vstup.charAt(konec)==" " || vstup.charAt(konec)=="\n" || vstup.charAt(konec)=="\r" || vstup.charAt(konec)=="\t") {
		vstup=vstup.substring(0,konec);
		konec--;
	}
	if (nbsp) {
		while (vstup.substring(0,6)=="&nbsp;") {
			vstup=vstup.substring(6);
		}
		konec=vstup.length-6;
		while (vstup.substring(konec)=="&nbsp;") {
			vstup=vstup.substring(0,konec);
			konec-=6;
		}
	}
	return vstup;
}

function explode(oddelovac,zdroj,neprazdne) {
	if (neprazdne==undefined) neprazdne=false;
	var pole = new Array();
	var i=0;
	var ind=0;
	var pos=0;
	for (i=0;i<zdroj.length;i++) {
		if (zdroj.charAt(i)==oddelovac || i==zdroj.length-1) {
			if (i==zdroj.length-1) i++;
			if (pos!=i || neprazdne==false) {
				pole[ind]=zdroj.substring(pos,i);	
				ind++;					
			}
				pos=i+1;
		}
	}
	return pole;
}
function implode(slucovac,zdroj) {
	var str="";
	var i;
	for (i=0;i<zdroj.length;i++) {
		if (i) str+=slucovac;
		str=str+zdroj[i];
	}
	return str;
}
function hlaska(co) {
	var d=document.createElement("div");
	co=str_replace("<","&lt;",co);
	co=str_replace(">","&gt;",co);
	d.innerHTML=co;
	d.style.padding="3px 10px 3px 10px";
	document.body.appendChild(d);
}
function has_attribute(el,attr) {
	if (el.hasAttribute) return el.hasAttribute(attr);
	//Zbytek je pro IE <= 7
	if (el.getAttribute(attr)) return el.getAttribute(attr);
	else return false;
}