var Mac = navigator.appVersion.indexOf('Mac',0) != -1;
var Win = navigator.appVersion.indexOf('Win',0) != -1;
var IE  = navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1;
var NN  = navigator.appName.indexOf("Netscape",0) != -1;
var Moz = navigator.userAgent.indexOf("Gecko") != -1;
var Vmajor = parseInt(navigator.appVersion); // ex. 3
var Vminor = parseFloat(navigator.appVersion); // ex. 3.01
var WinIE = (Win && IE);
var MacIE5 = ((Mac && navigator.appVersion.indexOf('MSIE 5',0) != -1) || (Mac && IE && VER > 4));


var MacIE4 = ((Mac && navigator.appVersion.indexOf('MSIE 4.',0) != -1));
var MacIE3 = ((Mac && navigator.appVersion.indexOf('MSIE 3.',0) != -1));

var bAgent = navigator.userAgent;
var d = document;
function sniffer(){
this.Win = bAgent.indexOf("Win",0) != -1 ? 1 :0;
this.Mac = bAgent.indexOf("Mac",0) != -1 ? 1 :0;
this.Moz = ((bAgent.indexOf("Gecko") != -1) && (bAgent.indexOf("Safari",0) == -1)) ? 1 :0;
this.OPERA = bAgent.indexOf("Opera",0) != -1 ? 1 :0;
this.SAFARI = bAgent.indexOf("Safari",0) != -1 ? 1 :0;
this.checkObj = d.all?(d.getElementById?3:2):(d.getElementById?4:(d.layers?1:0));
this.allObj = ((this.checkObj == 1) || (this.checkObj == 2) || (this.checkObj == 3) || (this.checkObj == 4));
return this;
}
var usr = new sniffer;

 if(!window.saveInnerWidth) {
   window.onresize = resizeIt;
   window.saveInnerWidth = window.innerWidth;
   window.saveInnerHeight = window.innerHeight;
 }
 
function resizeIt() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        window.history.go(0);
    }
}

	function getWindowXOffset(){
		if(usr.checkObj == 2 || usr.checkObj == 3){
			return d.body.scrollLeft;
		}else if(usr.checkObj == 1 || usr.checkObj == 4){
			return window.pageXOffset;
		}
	}
	function getWindowYOffset(){
		if(usr.checkObj == 2 || usr.checkObj == 3){
			return d.body.scrollTop;
		}else if(usr.checkObj == 1 || usr.checkObj == 4){
			return window.pageYOffset;
		}
	}

	function getDocHeight(){
		if(usr.checkObj == 1){
			return getTagTop('end') + 1;
		}else if(usr.checkObj == 2 || usr.checkObj == 3 || usr.checkObj == 4){
			return getTagTop('end');
		}
	}

	function getDistanceMaxY(){
		if(usr.allObj){
			return (getDocHeight() - getWindowHeight());
		}
	}

	function setObj(idName){
		return d.all ? d.all(idName) : d.getElementById ? d.getElementById(idName) : d.layers[idName];
	}

	function getTagTop(idName) {
		var obj = setObj(idName);
		var tagCoords = new Object();

		if(usr.OPERA && usr.Mac){
			return idName;
		} else if((usr.checkObj == 2) || (usr.checkObj == 3) || (usr.checkObj == 4)) {
			tagCoords.y = obj.offsetTop;
			while ((obj = obj.offsetParent) != null) {
				tagCoords.y += obj.offsetTop;
			}if(usr.Mac && usr.Moz){
				return tagCoords.y - 12;
			}else if((usr.Win && usr.Moz) || (usr.Mac && usr.SAFARI)){
				return tagCoords.y - 9;
			}else{
				return tagCoords.y;
			}
		} else if(usr.checkObj == 1) {
			tagCoords.y = d.anchors[idName].y;
			return tagCoords.y;
		}return idName;
	}

	/*PageScroller*/
	var pageScrollTimer;
	function pageScroll(toX,toY,frms,frX,frY) {
		if(pageScrollTimer) clearTimeout(pageScrollTimer);
		var spd = usr.Mac ? 14 :16;
		var actX = getWindowXOffset();
		var actY = getWindowYOffset();
		if(!toX || toX < 0) toX = 0;
		if(!toY || toY < 0) toY = 0;
		if(!frms) frms = usr.NN ? 10 :usr.Mac ? 4 :5;
		if(!frX) frX = 0 + actX;
		if(!frY) frY = 0 + actY;

		frX += (toX - actX) / frms;
		if (frX < 0) frX = 0;
		frY += (toY - actY) / frms;
		if (frY < 0) frY = 0;
		var posX = Math.ceil(frX);
		var posY = Math.ceil(frY);
		window.scrollTo(posX, posY);
		if((Math.floor(Math.abs(actX - toX)) < 1) && (Math.floor(Math.abs(actY - toY)) < 1)){
			clearTimeout(pageScrollTimer);
			window.scroll(toX,toY);
		}else if(posX != toX || posY != toY){
			pageScrollTimer = setTimeout("pageScroll("+toX+","+toY+","+frms+","+frX+","+frY+")",spd);
		}else{
			clearTimeout(pageScrollTimer);
		}
	}

	function jumpToAnchor(idName) {
		if(usr.allObj){
			if(!!idName){
				var anchorY = getTagTop(idName);
				var dMaxY = getDistanceMaxY();
				var setY = (anchorY<1)?0:(anchorY>dMaxY)?dMaxY:anchorY;
				if(anchorY>1){
					pageScroll(0,setY);
				}else if(anchorY<=1){
					pageScroll(0,0);
				}else{
					location.hash = idName;
				}
			}else{
				pageScroll(0,0);
			}
		}else{
			!!idName ? location.hash = idName : location.hash = "top";
		}
	}
	function jumpToPageTop() {
		if(usr.allObj){
			pageScroll(0,0);
		}else{
			!!idName ? location.hash = idName : location.hash = "top";
		}
	}
	
	function pozn(msg){
  			return alert(msg);
    	}
		
		function verify(msg){
  			return confirm(msg);
    	}

		function userinf(user, id, uroven)
          {
               x=570;
               y=300;
               window.open(uroven + '/klub/user.info.php?user=' +
     user + '&id=' + id,'Info','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		 function help(id, uroven)
          {
               x=500;
               y=500;
               window.open(uroven + '/help/?page=' + id,'Help','resizable=1,scrollbars=1,menubar=0,width=' + x + ',height=' + y);
          }
		  
		  function zalozky(add, tema)
          {
               x=400;
               y=200;
               window.open('../diskuse/zalozky/edit.php?add=' + add + '&tema=' + tema,'Zalozky','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		  function zalozky_page(page)
          {
               x=400;
               y=200;
               window.open('/diskuse/zalozky/edit.php?' + page,'Zalozky','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		  function ignore(add)
          {
               x=400;
               y=200;
               window.open('../diskuse/ignore/edit.php?add=' + add,'Ignore','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  function nevhodnazprava(page, id, uroven)
          {
               x=650;
               y=300;
               window.open(uroven + '/klub/administrator-nevhodna-zprava.php?page=' + page + '&id=' + id,'Nevhodnazprava','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		   function hodnoceniprispevku(page, id, uroven, hodnoceni)
          {
               x=450;
               y=230;
               window.open(uroven + '/klub/hodnoceniprispevku.php?page=' + page + '&id=' + id + '&hodnoceni=' + hodnoceni,'Hodnoceniprispevku','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		   function clanek_del(id, uroven)
          {
               x=400;
               y=100;
               window.open(uroven + '/clanky/edit-nazory-del.php?id=' + id,'Smazani nazoru','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		   function clanek_edit(id, uroven)
          {
               x=550;
               y=450;
               window.open(uroven + '/clanky/edit-nazory-edit.php?id=' + id,'Editace nazoru','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		   function encyklopedie_del(id, uroven)
          {
               x=400;
               y=100;
               window.open(uroven + '/atlas/edit-nazory-del.php?id=' + id,'Smazani nazoru','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		   function encyklopedie_edit(id, uroven)
          {
               x=550;
               y=450;
               window.open(uroven + '/atlas/edit-nazory-edit.php?id=' + id,'Editace nazoru','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		     function shop_del(id, uroven)
          {
               x=400;
               y=100;
               window.open(uroven + '/shop/edit-nazory-del.php?id=' + id,'Smazani nazoru','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		  
		   function shop_edit(id, uroven)
          {
               x=550;
               y=450;
               window.open(uroven + '/shop/edit-nazory-edit.php?id=' + id,'Editace nazoru','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		 
		   function rename_rema(tema)
          {
               x=400;
               y=200;
               window.open('../diskuse/renametema.php?tema=' + tema, 'Tema','resizable=0,scrollbars=0,menubar=0,width=' + x + ',height=' + y);
          }
		 function setColor(el, bg) {
		  if (el.style) el.style.backgroundColor = bg;
		}
		

var mins
var secs;

function cd() {
 	mins = 1 * m("28"); 
 	secs = 0 + s(":00"); 
 	redo();
}

function m(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(0, i));
}

function s(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(i + 1, obj.length));
}

function dis(mins,secs) {
 	var disp;
 	if(mins <= 9) {
  		disp = " 0";
 	} else {
  		disp = " ";
 	}
 	disp += mins + ":";
 	if(secs <= 9) {
  		disp += "0" + secs;
 	} else {
  		disp += secs;
 	}
 	return(disp);
}

function redo() {
 	secs--;
 	if(secs == -1) {
  		secs = 59;
  		mins--;
 	}
	
	document.cd.disp.value = dis(mins,secs);
	
	if((mins == 6) && (secs == 00)) {
		document.getElementById(123).style.display="block";
 	}
	
	if((mins == 4) && (secs == 00)) {
		es1=document.getElementById(123).style;
			es1.background="#ff8c00";
 	}
	
	if((mins == 2) && (secs == 00)) {
		es3=document.getElementById(123).style;
			es3.background="#FF0000";
				es3.color="#FFFFFF";
 	}
	

 	if((mins == 1) && (secs == 00)) {
		document.getElementById(1234).style.display="none";
		es5=document.getElementById(123).style;
			es5.background="#000000";
				es5.color="#FFFFFF";
		window.alert("Byli jste dlouho neaktivní, systém Vás do minuty odhlásí!");
 	} 
	
	cd = setTimeout("redo()",1000);

}



function loadremote(page, destination){
  var httpRequest;
  
  if(typeof window.ActiveXObject != 'undefined'){
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    httpRequest = new XMLHttpRequest();
  }
  httpRequest.open("GET", page, true);
  httpRequest.onreadystatechange= function (){
    processRequest(httpRequest, destination)
  };
  httpRequest.send(null);
}
function processRequest(httpRequest, destination){
  if (httpRequest.readyState == 4){
    if (( httpRequest.status >= 200 && httpRequest.status < 300 ) || httpRequest.status == 304){
      if (typeof destination == 'string'){
        document.getElementById(destination).innerHTML = httpRequest.responseText;
      }
      if (typeof destination == 'function'){
        destination(httpRequest.responseText);
      }
    }
    else {
      alert("Error " + httpRequest.status +" : "+ httpRequest.statusText);
    }
  }
  else {
    if (typeof destination == 'string' && destination != ''){
      document.getElementById(destination).innerHTML = ' <img src="http://www.akvarista.cz/web/a-global/design/loading.gif"> ';
    }
  }
}
