//<script>
window.onload = function() {
	addTB();
	initNav();
}

// CSS (if JavaScript is enabled)
function writeJSstyle(){
	document.write('<link rel="stylesheet" type="text/css" media="screen" href="/css/efg-js.css" />');
}


var timers=new Array();
var menuFall=50;
function initNav() {
	var menuElements=getEl('mnu').getElementsByTagName("ul");
	for(var i=0;i<menuElements.length;i++) {
		if(browser.isIE) {
			menuElements[i].onmouseover=function() {
				if(timers[this.parentNode.id]) clearTimeout(timers[this.parentNode.id]);
					if(this.parentNode.parentNode.parentNode.id=="mnu") {
						this.parentNode.parentNode.firstChild.lastChild.style.backgroundPosition="0px -37px";
					} else {
						this.parentNode.parentNode.firstChild.style.color="#fff";
						//this.parentNode.parentNode.firstChild.style.backgroundColor="#98c8e8";
						//this.parentNode.parentNode.firstChild.style.fontWeight="bold";
					}
			}

			menuElements[i].parentNode.parentNode.onmouseover=function() {
				if(this.parentNode.id=="mnu")this.firstChild.lastChild.style.backgroundPosition="0px -37px";
				if(timers[this.lastChild.id]) clearTimeout(timers[this.lastChild.id]);
				this.firstChild.lastChild.style.color="#fff";
				setVVObj(this.lastChild);
			}

			menuElements[i].parentNode.parentNode.onmouseout=function() {
				//this.firstChild.lastChild.style.color="#c5c5c5";
				timers[this.lastChild.id]=setTimeout('setVH("'+this.lastChild.id+'");var liEl=getEl("'+this.id+'");liEl.firstChild.lastChild.style.color="#c5c5c5";if(liEl.parentNode.id=="mnu"&&liEl.className!="act")liEl.firstChild.lastChild.style.backgroundPosition="0px 0px";',menuFall);
			}

		}
	}
}

function isMail(mail){
  var mailre=/^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
  return mailre.test(mail);
}

function reVal(el){
  if(trim(el.value)!="")el.style.backgroundImage="url('images/layout/backgrounds/bg-input.gif')";
}

function checkFrm(f){

	 var emptys=new Array();
	 var invalids=new Array();

	// Global
	if(trim(f.f_name.value)=="")emptys[emptys.length]=new Array(f.f_name,"Jméno a příjmení");
	if(trim(f.f_email.value)=="") {
		emptys[emptys.length]=new Array(f.f_email,"Email");
	} else {
		if(!isMail(trim(f.f_email.value)))invalids[invalids.length]=new Array(f.f_email,"Email");
	}
	if(emptys.length>0 || invalids.length>0){
		var alrt="";
		if(emptys.length>0){
			alrt+="Následující položky nebyly vyplněny:\n\n";
			for(var i=0;i<emptys.length;i++){
				alrt+=emptys[i][1]+"\n";
				emptys[i][0].style.backgroundImage="url('images/layout/crumbs/exclamation-mark.gif')";
			}
		}

		if(invalids.length>0){
			alrt+=(emptys.length>0?"\n\n":"")+"Nasledujici položky nebyly správně vyplněny:\n\n";
			for(var i=0;i<invalids.length;i++){
				alrt+=invalids[i][1]+"\n";
				invalids[i][0].style.backgroundImage="url('images/layout/crumbs/exclamation-mark.gif')";
			}
		}

		alert(alrt);
		return false;
	} else {
		return true;
	}
}

function fakeeml(eml,dom,txt)
	{
	document.write('<a href="mailto:'+eml+'@'+dom+'">'+( ( txt ) ? (txt) : ( eml+'@'+dom ) )+'</a>')
	}


///////////funkce pro zjisteni skutecne polohy objektu v dokumentu zleva
function getRealLeft(el) 
	{
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) 
		{
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    	}
    return xPos;
	}

///////////funkce pro zjisteni skutecne polohy objektu v dokumentu shora
function getRealTop(el) 
	{
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) 
		{
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    	}
    return yPos;
	}

//fce pro kontrolu odesilanych formularu
function controll(cnt)
	{
	if (!cnt) { cnt=document.poptavka;}
	var chyba=""
	if (cnt.firma.value.length < 1) {chyba+="společnost\n";};
	if (cnt.jmeno.value.length < 1) {chyba+="jméno\n";};
	if (cnt.ulice.value.length < 1) {chyba+="ulice\n";};
	if (cnt.mesto.value.length < 1) {chyba+="město\n";};
	if (cnt.telefon.value.length < 1) {chyba+="telefon\n";};
	if (cnt.psc.value.length < 1) {chyba+="PSČ\n";};
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(cnt.mail.value)) {chyba+="e-mail je neplatný \n";};
	if (  chyba.length==0  ) 
		{
		document.poptavka.submit()
		}
	else 
		{
		alert("Ve formuláři se vyskytly chyby.\nZkontrolujte prosím následující poloky\n\n"+chyba)
		};
	}