﻿window.onload = reposLayout;

var flashImagesCount = 0;

//**************************************************
function reposLayout(){
	if(typeof(oAdText)!="undefined"){
		gObject("addata").innerHTML = oAdText;
	}
	if(document.getElementById("hparlist")){
		return reposHomepage();
	}else{
		return reposSecondLevel();
	}
}
//**************************************************
function reposHomepage(){

	var oLC = gObject("mlcolumn");
	var oMC = gObject("mmcolumn");
	var oRC = gObject("mrcolumn");

	if(!oLC) return;

	//FLASH NEWS
	var oHeight = Math.max(oLC.offsetHeight, oMC.offsetHeight);
	    oHeight = Math.max(oHeight, oRC.offsetHeight + gObject("mrcolumnfiller").offsetHeight);
	if(oHeight>oLC.offsetHeight){
		gObject("hparlistfooter").style.display = "block";
		gObject("hparlistfooter").style.height  = (oHeight-oLC.offsetHeight) + "px";
		oLC.style.height  = oHeight + "px";
	}

	if(oHeight>oMC.offsetHeight){
		oMC.style.height  = oHeight + "px";
		gObject("mrcolumnfillerheaderleft").style.height  = (oHeight - gObject("hpflashnews").offsetHeight) + "px";
	}
	if(oHeight>oRC.offsetHeight){
		var oCols = Math.max(gObject("bnrstl").offsetHeight, gObject("bnrstr").offsetHeight);
		oRC.style.height  = oHeight + "px";
		gObject("mrcolumnfiller").style.top  = (oCols) + "px";
		gObject("mrcolumnfiller").style.height  = (oHeight - oCols) + "px";
	}

	//MAIN BOXES
	var oLB 	= gObject("dbleft");
	var oMB 	= gObject("dbmiddle");
	var oRB 	= gObject("dbright");
	var oHeight 	= Math.max(oLB.offsetHeight, oMB.offsetHeight);
	    oHeight 	= Math.max(oHeight, oRB.offsetHeight);

	if(oHeight>oLB.offsetHeight){
		gObject("dbleftfiller").style.height = (oHeight - oLB.offsetHeight + gObject("dbleftfiller").offsetHeight) + "px";
		oLB.style.height  = oHeight + "px";
	}
	if(oHeight>oRB.offsetHeight){
		oRB.style.height  = oHeight + "px";
	}
	if(oHeight>oMB.offsetHeight){
		oMB.style.height  = oHeight + "px";
	}
	return true
}
//**************************************************
function hackFlash(){
	if(document.getElementsByTagName){
		var objects = document.getElementsByTagName('EMBED'); 
		for (var i=0; i<objects.length; i++) { 
			objects[i].outerHTML = objects[i].outerHTML; 
		} 
	}
}
//**************************************************
function gObject(oName){
	return document.getElementById(oName);
}
//**************************************************
function reposSecondLevel(){
	try{
	var oCat = gObject("catHack");
	var oLC = gObject("mlcolumn");
	var oRC = gObject("mrcolumn");
	var oFR = gObject("adrtextframe");
	
	if(!oLC) return;

	if(oCat){
		gObject("catHackInfo").style.display = "none";
		oCat.style.display = "block";
	}

	if(oLC.offsetHeight > oRC.offsetHeight){
		oFR.style.height  = (oLC.offsetHeight-oRC.offsetHeight+oFR.offsetHeight) + "px";	
	}
}catch(e){}
	return true
}
//**************************************************
// THUMBNAILS
//**************************************************
function showFullThumbNail(which){
	var rndm = "thumb" + Math.floor(1000000*Math.random());
	var wa   = window.open("/ShowFullThumbNail.aspx?id_file=" + which, rndm, "status=1, tollbar=0");
}

function ShowFullThumbNail(id_file, width, height, title, action){
  if (action != null){
    window.open("/ShowFullThumbNail.aspx?id_file=" + id_file + "&width=" + width + "&height=" + height + "&title=" + title + "&" + action.replace("|", "&"),"fullImage" + id_file, "scrollbars=no,status=yes,width=" + width + ",height=" + height);
  }else{
    window.open("/ShowFullThumbNail.aspx?id_file=" + id_file + "&width=" + width + "&height=" + height + "&title=" + title,"fullImage" + id_file, "scrollbars=no,status=yes,width=" + width + ",height=" + height);
  }
  return false;
}

//**************************************************
// PRINT
//**************************************************
function preparePrint(idarticle){
	if(parseInt(idarticle)>0){
		var wa = window.open("/default.aspx?textartimg=1&prnwin=1&article=" + idarticle, "prn", "width=680, height=520, status=1, scrollbars=1, tollbar=0, resizable=1");
	}else{
		var wa = window.open("/default.aspx?printcourse=1&prnwin=1", "prnc", "width=700, height=400, status=1, scrollbars=1, tollbar=0, resizable=1");
	}
}
//**************************************************
function prepareCatalogPrint(){
	var wa = window.open("/catalogPrint.htm", "prncat", "width=600, height=400, status=1, scrollbars=1, tollbar=0, resizable=1");
}
//**************************************************
function InsSm(which){
	var oObj = gObject("Editor");
	if(oObj){
		oObj.value += which;
	}else{
		if(typeof(mailerEditor)!="undefined"){
			mailerEditor.value += which;
		}
	}
}
//**************************************************
function runMailClient(mMail){
	if(!mMail) return;
	var eAdd = new String("") + mMail.replace(" zavinac ", "@");
	eAdd = eAdd.replace(/\$/igm, ".");
	document.location = "mailto:" + eAdd;
	
}

//**************************************************
function showppp(){
	var wa = window.open("/adolozka.htm", "adol", "width=300, height=360, status=1, scrollbars=0, tollbar=0, resizable=0");
}

//**************************************************
// DISCUSSION
//**************************************************
function displayDiscTab(){
	var oObj = gObject("disctabdata0");
	if(oObj){
		if(oObj.style.display=="block"){
			oObj.style.display = "none";
			gObject("disctabdata1").style.display = "block";
			gObject("disctabtx").innerHTML = "Zpět na diskusi";
		}else{
			oObj.style.display = "block";
			gObject("disctabdata1").style.display = "none";
			gObject("disctabtx").innerHTML = "Zadat dotaz";
		}
	}
}



//**************************************************
// INQUIRY
//**************************************************
function arInquiry(quest){
	this.items	= null;
	this.header	= quest;
	this.footer	= new String();

	this.draw 	= fnDrawInquiry;
	this.addStrip	= fnAddInquiryStrip;
	this.addFooter	= fnAddInquiryFooter;

	return this;
}
//**************************************************
function fnDrawInquiry(){
	var oObj = gObject("arinquiry");
	if(oObj && this.items!=null){
		var iText = new String();
		iText += "<div class='inqclip'>\n";
		iText += "<h3>Anketa</h3>\n";
		iText += "<p>" + this.header + "</p>\n";
		iText += "<div class='inqdata'>\n";
		for(var i=0; i< this.items.length; i++){
			iText += '<div class="inqanswer"><a href="javascript:PubSystemControlsRunInquiryVote(' + this.items[i].idInquiry + ', ' + this.items[i].idAnswer + ')">' + this.items[i].answer + '</a></div>\n';
			iText += '<div class="inqstate">\n';
			iText += '<span class="inqstatestrip"><a href="javascript:PubSystemControlsRunInquiryVote(' + this.items[i].idInquiry + ', ' + this.items[i].idAnswer + ')"><span style="width:' + this.items[i].clicks + 'px;"></span></a></span>\n';
			iText += '<span class="inqstatecount">' + this.items[i].clicks + '%</span>\n';
			iText += '</div>\n';
		}
		iText += "</div><br class=\"clear\">\n";
		iText += this.footer;
		iText += "</div>\n";
		oObj.innerHTML = iText;
	}
}
//**************************************************
function fnAddInquiryStrip(idI, idIS, answer, clicks){
	if(this.items==null){
		this.items = new Array();
	}
	this.items.push(new arInquiryStrip(idI, idIS, answer, clicks));
}
//**************************************************
function fnAddInquiryFooter(desc){
	this.footer = "<p class=\"inquirySummx\">" + desc + "<br />&raquo; <a href=\"/default.aspx?ireport=1\">starší ankety</a></p>\n";	
}
//**************************************************
function arInquiryStrip(idI, idIS, answer, clicks){
	this.idInquiry 	= idI;
	this.idAnswer	= idIS;
	this.answer	= answer;
	this.clicks	= clicks;

	return this;
}

//**************************************************
// COMMENTS
//**************************************************
var tAreaActive = false;
var tMailActive	= false;

function handleAreaFocus(oObj, which){
	if(!which){
		oObj.value = "";
	}	
	return true;
}

//**************************************************
// MENU
//**************************************************

var defMenu	= 0;
var sbMenuMain  = new Array();
var sbMenuSec 	= new Array();
var sbTimer	= null;

//**************************************************
function menuItem(oUrl, oName){
	this.url 	= oUrl;
	this.name	= oName;
	return this;
}
//**************************************************
function reallyHideSubMenu(){
	if(sbTimer!=null){
		clearTimeout(sbTimer);
		sbTimer = null;
		if(document.getElementById("bnrhacksky"))
		{
			document.getElementById("customsubmenu").style.visibility = "hidden";
			document.getElementById("bnrhacksky").style.visibility = "visible";
			document.getElementById("bnrhacksqr").style.visibility = "visible";
			if(document.getElementById("bnrstl")) document.getElementById("bnrstl").style.visibility = "visible";
		}
	}
}
//**************************************************
function hideSubMenu(){
	sbTimer = setTimeout("reallyHideSubMenu()", 1000);
	return
}
//**************************************************
function skipHideSubMenu(){
	if(sbTimer!=null){
		clearTimeout(sbTimer);
		sbTimer = null;
	}
	return
}
//**************************************************
function showSubMenu(which, oObj){
	var cMenu 	= which==1 ? sbMenuMain : sbMenuSec;
	skipHideSubMenu();
	if(defMenu!=which){
		var cMenuText	= new String();
		for(var i=0; i<cMenu.length; i++){
			cMenuText += "<div" + (i<cMenu.length-1 ? " class='sbmnitem'" : " class='sbmnitemlast'") + "><a href='" + cMenu[i].url + "' onmouseover='skipHideSubMenu()' onmouseout='hideSubMenu()'>" + cMenu[i].name + "</a></div>"
		}
		document.getElementById("customsubmenu").innerHTML = cMenuText;
		defMenu = which;
		document.getElementById("customsubmenu").style.left = oObj.offsetLeft + "px";
	};
	if(document.getElementById("bnrhacksky"))
	{
		document.getElementById("customsubmenu").style.visibility = "visible";
		document.getElementById("bnrhacksky").style.visibility = "hidden";
		document.getElementById("bnrhacksqr").style.visibility = "hidden";
		if(document.getElementById("bnrstl")) document.getElementById("bnrstl").style.visibility = "hidden";
	}
}


//**************************************************
// VIDEOGALLERY
//**************************************************
function getStream(oUrl, w, h, id_item){
	var cUrl	= "/showStream.aspx?f=" + oUrl.replace("http://video.mobilmania.superhosting.cz/player.swf?idname=", "") + "&w=" + w + "&h=" + h + "&id_item=" + id_item;
	var mW = screen.availWidth;
	var mH = screen.availHeight;
	var leftPos = parseInt((mW-w)/2);
	var topPos = parseInt((mH-h-60)/2);
	var ucw = window.open(cUrl, "vpreview", "width="+w+",height="+parseInt(parseInt(h)+60)+",top="+topPos+",left="+leftPos+",resizable=0,status=yes,address=0");
  	ucw.focus();
}

//**************************************************
// OLD AE
//**************************************************
function BigImg1(ARI,IMI)
{
	var rndm = "thumb" + Math.floor(1000000*Math.random());
	var wa = window.open("/ShowFullThumbNailOldAE2.aspx?ari=" + ARI + "&imi=" + IMI.replace("x","/"), rndm,'status=1, tollbar=0');
}
function BigImg(ARI,IMI)
{
	var rndm = "thumb" + Math.floor(1000000*Math.random());
	var wa = window.open("/ShowFullThumbNailOldAE.aspx?ari=" + ARI + "&imi=" + IMI + IMI, rndm,'status=1, tollbar=0');
}

//**************************************************
// ENTER KEY HANDLER
//**************************************************
var sButtonId = null;
document.onkeypress = checkENTER;

//**************************************************
function checkENTER(e){
	var key = window.event ? window.event.keyCode : e.which;
	var hnd	= window.event ? window.event.srcElement.id : e.target.id;
	var wsrc = window.event ? window.event.srcElement : e.target;
	if(key==13){
		if(wsrc.getAttribute("forceClick")!=null){
			e.cancelBubble = false;
			eval(unescape(document.getElementById(wsrc.getAttribute("forceClick")).href).replace("javascript:", ""));
			return false;
		}else{
				if(sButtonId!=null){
					//ADVANCED SEARCH
					eval(unescape(gObject(sButtonId).href).replace("javascript:", ""));
					if(window.event){
						e.cancelBubble = false;
					}else{
						window.event.cancelBubble = false;
					}
					return false
				}
		}
	}
	return true
}

//**************************************************
// FULL SIZE IMAGE HANDLER
//**************************************************
function ShowFullThumbNail(id_file, width, height, title){
	window.open("/ShowFullThumbNail.aspx?id_file=" + id_file + "&width=" + width + "&height=" + height + "&title=" + title,"fullImage" + id_file, "scrollbars=no,status=yes,width=" + width + ",height=" + height);
	return false;
}
//**************************************************
function ShowArticleImage(id_file, width, height, title, action){
  if(ArImage && (action != null) && (action.indexOf("slideshow=1") > -1) && (typeof(isTxVer)=="undefined" || !isTxVer)){
    window.open("/ShowArticleImages.aspx?file=" + id_file + "&article=" + ArImage + "&" + action.replace("|", "&"), "fullImage" + id_file, "scrollbars=no,status=yes,width=800,height=600");
  }else{
    return ShowFullThumbNail(id_file, width, height, title, action);
  }
  return false;
}

//**************************************************
// PRINT INTERSTITIAL
//**************************************************
var timerAd	= null;
var runActionAd	= null;

//**************************************************
function AfterISPrint(){
	if(timerAd!=null){
		clearTimeout(timerAd);
		timerAd = null;
	}
	if(document.getElementById("printis")!=null){
		document.getElementById("printis").style.display="none";
	}
	if(runActionAd!=null){
		eval(runActionAd);
		runActionAd=null;
	}
}
//**************************************************
function BeforeISPrint(action){
	runActionAd = action;
	if(document.getElementById("printis")!=null){
		document.getElementById("printis").style.top = document.documentElement.scrollTop + "px";
		document.getElementById("printis").style.height = document.documentElement.offsetHeight + "px";
		document.getElementById("printis").style.width = (document.documentElement.offsetWidth - 25) + "px";
		document.getElementById("printis").style.display="block";
	}
	if(timerAd!=null){
		clearTimeout(timerAd);
		timerAd = null;
	}
	timerAd = setTimeout("AfterISPrint()", 7000);
}

//**************************************************
// PASSPORT
//**************************************************
function DisplayAutomate(hideit){
	gObject("uautomate").style.visibility = !hideit ? "visible" : "hidden";
}