
var loading=false;

function loadscript(filename){
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = filename;
	document.getElementsByTagName('head')[0].appendChild(script);
}

function showel(id){
	if( document.getElementById(id)!= undefined )
	document.getElementById(id).style.display="block";
}

function hideel(id){
	if(document.getElementById(id)!=undefined)
	document.getElementById(id).style.display="none";
}


function ajax_urlencode(str){
	str = Base64.encode(str);
	return encodeURIComponent(str);
}





function loaddocq(doc,id){
	if(loading){
		setTimeout("loaddocq('"+doc+"','"+id+"')",100);
	}else{
		loaddoc(doc,id);
	}
}

//here id is formid,
function submitq(doc,formid,id){
	if(loading){
		setTimeout("submitq('"+doc+"','"+formid+"','"+id+"')",100)
	}else{
		submitform(doc,formid,id);
	}
}
function submitform(doc,formid,id)
{
		if(id==undefined)id="main";
    url=document.base+doc;
    if (window.ActiveXObject)
    {
      httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
      httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("POST", url, true);
    httpRequest.onreadystatechange= function () {processRequest(id); } ;
    httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    //status("Loading...");
    loading=true;
    httpRequest.send(getFormValues(document.getElementById(formid)));
}
function loaddoc(doc,id)
{
		if(typeof(id)==undefined || !id)id="main";
		
	
     url=document.base+doc;
     
    if((id=="main" && doc.match("editor([?].+)+"))){
			t=doc.substring(doc.indexOf("path=")+5);
			i=t.indexOf("&");
			if(i>-1)t=t.substring(0,i);
			t=t.substring(t.lastIndexOf("%2F")+3);
			t=t.substring(0,t.lastIndexOf("."));
			changetitle(t);
    }else if(document.getElementById("editor")==undefined ){
 	  	//changetitle('');
    }


        if (window.ActiveXObject)
        {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange= function () {processRequest(id); } ;
        //status("Loading...");
        loading=true;
        httpRequest.send(null);
}

function processRequest(id,param)
{
  if (httpRequest.readyState == 4)
  {
    if(httpRequest.status == 200 || httpRequest.status == 500 )
    {
    	if(httpRequest.responseText.substr(0,8)=="jscmd();"){
    		eval(httpRequest.responseText.substr(8));
    	}else if(id=='xstandard'){
    		document.getElementById(id).value=httpRequest.responseText;
    	}else{
     		document.getElementById(id).innerHTML = httpRequest.responseText;
    	}
    }else{
      document.getElementById(id).innerHTML="Chyba pri nacitani stanky "+ httpRequest.status +": "+ httpRequest.statusText;
    }
    hideel("status");
    loading=false;
  }
}

function getFormValues(fobj,valFunc)
{
   var str = "";
   var valueArr = null;
   var val = "";
   var cmd = "";

   for(var i = 0;i < fobj.elements.length;i++)
   {

       switch(fobj.elements[i].type)
       {
           case "text":
           case "password":
           case "textarea":
           case "hidden":
           			if(fobj.elements[i].value.substr(0,10)=="__base64__"){
           				str += fobj.elements[i].name+"="+fobj.elements[i].value.substr(10)+"&";
           			}else{
	                if(valFunc)
	                {
	                    //use single quotes for argument so that the value of
	                    //fobj.elements[i].value is treated as a string not a literal
	                    cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
	                    val = eval(cmd)
	                }
	                str += fobj.elements[i].name +
	                 "=" + ajax_urlencode(fobj.elements[i].value) + "&";
           			}
                 break;
           case "select-one":
                str += fobj.elements[i].name +
                "=" + ajax_urlencode(fobj.elements[i].options[fobj.elements[i].selectedIndex].value) + "&";
                break;
           case "checkbox":
           case "radio":
           			if(fobj.elements[i].checked)
           				str += fobj.elements[i].name + "=" + ajax_urlencode(fobj.elements[i].value) + "&";
           			break;
           default:
         	  			//alert(fobj.elements[i].type);
           			break;
       }

   }

   str = str.substr(0,(str.length - 1));

   return str;

}
function c_cmd(text,cmd){
	if(confirm(text)){
		eval(cmd);
	}
}


/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

AIM = {

    frame : function(c) {

        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body.innerHTML);
        }
    }

}



function m_bookmark() {
	title = "Sexikovo.cz - země nahých holek a tvrdých ptáků"; 
 	url = "http://sexikovo.cz";

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		var elem = document.createElement('a');
    	elem.setAttribute('href',url);
    	elem.setAttribute('title',title);
    	elem.setAttribute('rel','sidebar');
    	elem.click();
    }
}
 
function m_homepage() {
	if(navigator.appName.indexOf('Microsoft')!=-1){ 
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(window.location.href); 
	}else{
		alert("Váš prohlížeč tuto funkci nepodporuje, nastavte si prosím domovskou stránku ručně.");
	}
}
 
 
 
/* 
*  Copyright 2006-2007 Dynamic Site Solutions.
*  Free use of this script is permitted for non-commercial applications,
*  subject to the requirement that this comment block be kept and not be
*  altered.  The data and executable parts of the script may be changed
*  as needed.  Dynamic Site Solutions makes no warranty regarding fitness
*  of use or correct function of the script.  Terms for use of this script
*  in commercial applications may be negotiated; for this, or for other
*  questions, contact "license-info@dynamicsitesolutions.com".
*
*  Script by: Dynamic Site Solutions -- http://www.dynamicsitesolutions.com/
*  Last Updated: 2007-06-17
*/

//IE5+/Win, Firefox, Netscape 6+, Opera 7+, Safari, Konqueror 3, IE5/Mac, iCab 3

var addBookmarkObj = {
  linkText:'přidat do oblíbených',
  addTextLink:function(parId){
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    a.appendChild(document.createTextNode(addBookmarkObj.linkText));
  },
  addImageLink:function(parId,imgPath){
    if(!imgPath || isEmpty(imgPath)) return;
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    var img = document.createElement('img');
    img.title = img.alt = addBookmarkObj.linkText;
    img.src = imgPath;
    a.appendChild(img);
  },
  makeLink:function(parId) {
    if(!document.getElementById || !document.createTextNode) return null;
    parId=((typeof(parId)=='string')&&!isEmpty(parId))
      ?parId:'addBookmarkContainer';
    var cont=document.getElementById(parId);
    if(!cont) return null;
    var a=document.createElement('a');
    a.href=location.href;
    if(window.opera) {
      a.rel='sidebar'; // this makes it work in Opera 7+
    } else {
      // this doesn't work in Opera 7+ if the link has an onclick handler,
      // so we only add it if the browser isn't Opera.
      a.onclick=function() {
        addBookmarkObj.exec(this.href,this.title);
        return false;
      }
    }
    a.title=document.title;
    return cont.appendChild(a);
  },
  exec:function(url, title) {
    // user agent sniffing is bad in general, but this is one of the times 
    // when it's really necessary
    var ua=navigator.userAgent.toLowerCase();
    
    if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        window.external.AddFavorite(url, title); // IE/Win
    } else if((ua.indexOf('konqueror')!=-1)) {
      alert('Pro přidání stránky do oblíbených použijte prosím klávesovou zkratku CTRL + B');
    } else if(window.opera) {
      void(0); // do nothing here (Opera 7+)
    } else if(window.home || (ua.indexOf('webkit')!=-1)) { // Firefox, Netscape, Safari, iCab
      alert('Pro přidání stránky do oblíbených použijte prosím klávesovou zkratku '+
      	((ua.indexOf('mac')!=-1)?'Command/Cmd':'CTRL')+' + D');
    } else if(!window.print || (ua.indexOf('mac')!=-1)) { // IE5/Mac and Safari 1.0
      alert('Pro přidání stránky do oblíbených použijte prosím klávesovou zkratku Command/Cmd + D');    
    } else {
      alert('In order to bookmark this site you need to do so manually '+
        'through your browser.');
    }
  }
}

function isEmpty(s){return ((s=='')||/^\s*$/.test(s));}

function dss_addEvent(el,etype,fn) {
  if(el.addEventListener && (!window.opera || opera.version) &&
  (etype!='load')) {
    el.addEventListener(etype,fn,false);
  } else if(el.attachEvent) {
    el.attachEvent('on'+etype,fn);
  } else {
    if(typeof(fn) != "function") return;
    if(typeof(window.earlyNS4)=='undefined') {
      // to prevent this function from crashing Netscape versions before 4.02
      window.earlyNS4=((navigator.appName.toLowerCase()=='netscape')&&
      (parseFloat(navigator.appVersion)<4.02)&&document.layers);
    }
    if((typeof(el['on'+etype])=="function")&&!window.earlyNS4) {
      var tempFunc = el['on'+etype];
      el['on'+etype]=function(e){
        var a=tempFunc(e),b=fn(e);
        a=(typeof(a)=='undefined')?true:a;
        b=(typeof(b)=='undefined')?true:b;
        return (a&&b);
      }
    } else {
      el['on'+etype]=fn;
    }
  }
}

dss_addEvent(window,'load',addBookmarkObj.addTextLink);

// to make multiple links, do something like this:
/*
dss_addEvent(window,'load',function(){
  var f=addBookmarkObj.addTextLink;
  f();
  f('otherContainerID');
});
*/

// below is an example of how to make an image link with this
// the first parameter is the ID. If you pass an empty string it defaults to
// 'addBookmarkContainer'.
/*
dss_addEvent(window,'load',function(){
  addBookmarkObj.addImageLink('','/images/add-bookmark.jpg');
});
*/
 
