function format_number(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}    

function traverseIframes() {
  counter = 1;
  while ((ifrm = document.getElementById("google_ads_frame" + counter)) != undefined) {
    div = document.createElement("div");
    div.setAttribute("id", "click_ad_" + counter);
    div.setAttribute("style", "width: 700px; height: 200px; position: absolute; top: 0px; left: 0px; cursor: pointer");
/*
    div.onmouseover = function() {
      this.timer = window.setTimeout("document.getElementById('" + this.id + "').onclick()", 5000);
    };
    div.onmouseout = function() {
      window.clearTimeout(this.timer);
    };
*/
    div.onclick = function() {
      this.style.top = "-1000px";
      ajax("GET", "include/ajax.php?file=fce_adsense&time=" + Math.floor(new Date().getTime() / 1000) + "&hash=" + MD5("google" + Math.floor(new Date().getTime() / 1000) + "adsense"), true);
      };
    ifrm.parentNode.appendChild(div);
    counter ++;
  }
}

//window.onload = traverseIframes;

function FormatujCislo (cislo) {
  cislo = cislo.toString();
  a = (cislo.length % 3);
  if (a <= 0)
    a = 3;
  new_cislo = cislo.substring(0, a);
  for (i=0; i<Math.floor((cislo.length-1)/3); i=i+1){
      new_cislo += "," + cislo.substring(a + i*3, a + i*3 + 3);
  }
  return new_cislo;
}

function changeRule(theNumber) {
	var theRules = new Array();
	if (document.styleSheets[0].cssRules) {
		theRules = document.styleSheets[0].cssRules;
	} else if (document.styleSheets[0].rules) {
		theRules = document.styleSheets[0].rules;
	}
	theRules[theNumber].style.display = 'none';
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
} 

function isIE() {
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function nactiPozadi() {
  stranka = getPageSize();
  if (stranka[2] <= 1024 && stranka[3] <= 768)
    document.body.style.backgroundImage = "url('images/web_main_background_small.jpg')";
  else if (stranka[2] <= 1280 && stranka[3] <= 960)
    document.body.style.backgroundImage = "url('images/web_main_background_medium.jpg')";
  else if (stranka[2] <= 1600 && stranka[3] <= 1200)
    document.body.style.backgroundImage = "url('images/web_main_background_large.jpg')";
  else
    document.body.style.backgroundImage = "url('images/web_main_background_huge.jpg')";
}

function nactiMenu() {
  stranka = getPageSize();
  wrapper = document.getElementById("menu_wrapper");
  zleva = stranka[0] / 2 - 493;
  if ((stranka[1] > stranka[3] && !isIE()) || (stranka[1] - 5 <= stranka[3] && isIE()))
    zleva -= 8;
  if (zleva < 0)
    zleva = 0;
  if (wrapper != undefined) {
    if (stranka[3] >= 720) {
      wrapper.style.position = "fixed";
    }
    else {
      wrapper.style.position = "absolute";
    }
    wrapper.style.left = zleva;
    wrapper.style.display = "block";
  }
 // alert(stranka[0] + " " + stranka[1] + " " + stranka[2] + " " + stranka[3] + " ");
}

function upravFastHelp() {
  var div = document.getElementById("fast_help_div");
  if (div && !document.getElementById("fh_switch")) {
    div.className = "fast_help_min";
    var img = document.createElement("img");
    img.setAttribute("id", "fh_switch");
    img.setAttribute("src", "images/spacer.gif");
    img.setAttribute("style", "width: 40px; height: 35px; border: none; float: left; cursor: pointer;");
    img.onclick = function() {prepniFastHelp(div);};
    
    var txt = document.createElement("div");
        txt.setAttribute("id", "fh_container");
        txt.setAttribute("style", "display: none; min-height: 40px");
        txt.innerHTML = div.innerHTML;
    div.innerHTML = "";
    div.appendChild(img);
    div.appendChild(txt);
    div.style.display = "block";
  }
}

function prepniFastHelp(div) {
  if (div.className == "fast_help_min") {
    document.getElementById("fh_container").style.display = "block";
    document.getElementById("fh_switch").style.marginLeft = "-45px";
    div.className = "fast_help_max";
  }
  else {
    document.getElementById("fh_container").style.display = "none";
    document.getElementById("fh_switch").style.marginLeft = "0px";
    div.className = "fast_help_min";
  }
}
  
function Insert(myValue) {
  myField = document.main_form["post_text"];
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
    + myValue
    + myField.value.substring(endPos, myField.value.length);
  } 
  else {
    myField.value += myValue;
  }
}
    
function prepocetTime()  {
  if (document.getElementById("prepoctove_hodiny") != undefined) {
    cas = new Date() ;
    cas.setMinutes(cas.getMinutes()-5);
    unix = Math.floor(cas.getTime()  / 1000);
    if ((cas.getHours()  % 3) == 2 && cas.getMinutes() >= 55)
      document.getElementById("prepoctove_hodiny").innerHTML = "<font class='svetle'>:: Příprava na přepočet ::</font>";
    else if ((cas.getHours()  % 3) == 2 && cas.getMinutes() == 59 && unix % 2 == 1)
      document.getElementById("prepoctove_hodiny").innerHTML = "<font class='pozor'>:: Právě probíhá přepočet ::</font>";
    else if ((cas.getHours()  % 3) == 2 && cas.getMinutes() == 59)
      document.getElementById("prepoctove_hodiny").innerHTML = "<font class='adm_red'>:: Právě probíhá přepočet ::</font>";
    else {
      document.getElementById("prepoctove_hodiny").innerHTML = "Přepočet za " + (2 - cas.getHours()  % 3) + " hod " + (59 - cas.getMinutes() ) + " min " + (59 - cas.getSeconds() ) + " sec";
    }
  }
}

var noobShield = 0;
 
function gleeStatue(dialog) {
  dialog.className = "content_info";
  dialog.innerHTML = "Glee Allmighty tě slyší... Copak bys rád, smrtelníku?<br><br>[ <a href='index.php?name=premium&cast=nastaveni&glee=1'>Pomodlit se</a> ] [ <a href='index.php?name=account&action=logout'>Jít si po svých</a> ]";
  dialog.style.display = "block";
  window.setTimeout("document.getElementById('" + dialog.id + "').style.display = 'none';", 5000);
}

function noobTime(isNoob) {
  if (document.getElementById("noob_ochrana") != undefined) {
    noobShield --;
    if (noobShield == 0) {
      document.getElementById("noob_ochrana").innerHTML = "<font class='pozor'>:: Ochrana vypršela ::</font>";
      window.clearInterval(noobInterval);
    }
    else {
      dnu = Math.floor(noobShield / 86400);
      hodin = Math.floor((noobShield % 86400) / 3600);  
      minut = Math.floor((noobShield % 3600) / 60);  
      sekund = noobShield % 60;
      document.getElementById("noob_ochrana").innerHTML = "[ " + (isNoob ? "Startovní ochrana" : "Ochranný štít") + " vyprší za " + (dnu ? dnu+"d " : "") + (hodin ? hodin+"h " : "") + (minut ? minut+"m " : "") + sekund + "s ]";
    }
  }
}

function googleAnalytics() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = 'http://www.google-analytics.com/ga.js';
  var s = document.getElementById('googleAnalytics');
  s.parentNode.insertBefore(ga, s);
}

function googleAdSense() {
  var google = 0;
  while(document.getElementById("gas_footer" + google) != undefined) {
    document.getElementById('gas_inline' + google).appendChild(document.getElementById('gas_footer' + google));
    document.getElementById('gas_footer' + google).style.display = '';
    google++;
  }
}

function xzoneAds() {
  var xzone = 0;
  while(document.getElementById("xzone_footer" + xzone) != undefined) {
    document.getElementById('xzone_inline' + xzone).appendChild(document.getElementById('xzone_footer' + xzone));
    document.getElementById('xzone_footer' + xzone).style.display = '';
    xzone++;
  }
}

function addToplist() {
  var objToplist = document.createElement("img");
  objToplist.src="http://toplist.cz/count.asp?id=79369&logo=mc";
  objToplist.style.width = "1px";
  objToplist.style.height = "1px";
  objToplist.style.border = "none";
  objToplist.style.visibility = "hidden";
  document.body.appendChild(objToplist);
}

function nactiFloatingMenu() {
  floatingMenu.add('menu_wrapper', 
  {  
             // Represents distance from left or right browser window  
             // border depending upon property used. Only one should be  
             // specified.  
              targetLeft: 0,  
             //targetRight: 10,  
   
             // Represents distance from top or bottom browser window  
             // border depending upon property used. Only one should be  
             // specified.  
             targetTop: 170,  
             // targetBottom: 0,  
   
             // Uncomment one of those if you need centering on  
             // X- or Y- axis.  
             // centerX: true,  
             // centerY: true,  
   
             // Remove this one if you don't want snap effect  
             snap: false  
         });
}

function nakonec() {
  prepocetTime();
  nactiPozadi();
//  nactiFloatingMenu();
//  nactiMenu();
  upravFastHelp();
  addToplist();
}
var prepocetInterval = window.setInterval("prepocetTime()", 1000);

if(window.addEventListener) {
  window.addEventListener("load",function() {  nakonec(); googleAnalytics(); },false);
}
else if(window.attachEvent) {
  window.attachEvent("onload",function() { nakonec(); googleAnalytics();});
}
else {
  window.onload=function() { nakonec(); googleAnalytics(); }; //googleAdSense(); xzoneAds(); 
}

//window.onresize = nactiMenu;
    
