devo.addOnloadMethod("initNav");
devo.addOnloadMethod("fakeSup");
if(browser.isIE)devo.addOnloadMethod("flash");

var timers=new Array();
var menuFall=20;
function initNav() {
	if(browser.isIE) {
		var menuElements=getEl('mnu').getElementsByTagName("ul");
		for(var i=0;i<menuElements.length;i++) {
			menuElements[i].parentNode.parentNode.onmouseover=function() {
				if(timers[this.lastChild.id]) clearTimeout(timers[this.lastChild.id]);
				if(this.parentNode.id=="mnu") {
					setVVObj(this.lastChild);
					this.firstChild.lastChild.style.backgroundPosition="0px -63px";
				}
			}

			menuElements[i].parentNode.parentNode.onmouseout=function() {
				timers[this.lastChild.id]=setTimeout('if("'+this.parentNode.className+'"!="submnulist"){setVH("'+this.lastChild.id+'")};var liEl=getEl("'+this.id+'");if(liEl.parentNode.id=="mnu")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="none";
}

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_phone.value)=="")emptys[emptys.length]=new Array(f.f_phone,"Kontaktní telefon");
	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,"Kontaktní email");
	}
	if(trim(f.f_realty.value)=="")emptys[emptys.length]=new Array(f.f_realty,"Druh nemovitosti");
	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('1/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('1/images/layout/crumbs/exclamation-mark.gif')";
			}
		}

		alert(alrt);
		return false;
	} else {
		return true;
	}
}

function fakeSup() {
  var sups=document.getElementsByTagName("sup");
  if(sups.length>0) {
	  for(var i=0;i<sups.length;i++){
	    var content=sups[i].firstChild.data;
	    var newSpan=document.createElement("span");
	    newSpan.className="fakesup";
	    var newText=document.createTextNode(content);
	    newSpan.appendChild(newText);
	    sups[i].parentNode.insertBefore(newSpan,sups[i]);
	  }

	  for(var i=0;i<sups.length;i++){
	    sups[i].style.display="none";
	  }
	}
}

function rowOver(row){
  var tds=row.getElementsByTagName("td");
  for(var i=0;i<tds.length;i++){
    tds[i].style.color="#fff";
    if(tds[i].firstChild.tagName=="STRONG"){tds[i].firstChild.style.color="#fff";};
	tds[i].style.backgroundColor="#759ed2";
	tds[0].getElementsByTagName("a")[0].style.color="#fff";
  }
}


function rowOut(row){
  var tds=row.getElementsByTagName("td");
  for(var i=0;i<tds.length;i++){
    tds[i].style.color="#53524d";
    if(tds[i].firstChild.tagName=="STRONG") {
		if(tds[i].firstChild.className=="orange") {
			tds[i].firstChild.style.color="#e07f00";
		} else if(tds[i].firstChild.className=="red") {
			tds[i].firstChild.style.color="#DC3700";
		}else{
			tds[i].firstChild.style.color="#4b7dbd";
		}
    }
    tds[i].style.backgroundColor=row.className.indexOf("tr1")<0?"#e5e3d8":"#d9d7cb";
	tds[0].getElementsByTagName("a")[0].style.color="#53524d";
  }
}

var flash=function(){
  var objs=document.getElementsByTagName("object");
  var objl=objs.length;
  for(var i=0;i<objl;i++){
    var obj=objs[i];
    var parent=obj.parentNode;
    var html=obj.outerHTML;
    html=html.substring(0,html.indexOf("</"));
    var params=parent.getElementsByTagName("param");
    var parl=params.length;
    for(var j=0;j<parl;j++)html+=params[j].outerHTML;
    html+="</object>";
    obj.outerHTML=html;
    var nobjs=parent.getElementsByTagName("object");
    setDB(nobjs[0]);
  }  
}



