/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    deleteCookie(name,path,domain);
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    //alert('name='+name+' value='+value+' expires='+expires+' path='+path);
}
/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


var _WEBROOT_URL_abs_='';

base=document.getElementsByTagName('base')         
if(base[0]){
 _WEBROOT_URL_abs_=base[0].href;           
} 


function showdiv(obj){
  setObjDisplayed(obj,getObjDisplayed(obj)?0:1);
  //if (!BrIs.IE) contentWindow.document.designMode = "on";
}



function nahled(url){

//return ;
open_window('url',_WEBROOT_URL_abs_+url,
            'name','preview',
            'width',300,
            'height',300,
            'screenX',100,
            'screenY',100,
            'top',100,
            'left',100,
            'resizable','yes',
            'status','0'
            );
return;
}


function getObjXY(strCurr)
{
var elmCurr = document.getElementById(strCurr);
var intX = 0;
var intY = 0;
do
{
intX += elmCurr.offsetLeft;
intY += elmCurr.offsetTop;
}
while ((elmCurr = elmCurr.offsetParent));
alert('objekt: ' + strCurr + '\nsouradnice X: ' + intX + '\nsouradnice Y: ' + intY);
}


function openNewWindow(sURL, sName, iWidth, iHeight, bResizable, bScrollbars){
    var iTop  = (screen.height - iHeight) / 2 ;
    var iLeft = (screen.width  - iWidth) / 2 ;

    var sOptions = "toolbar=no" ;
    sOptions += ",width=" + iWidth ;
    sOptions += ",height=" + iHeight ;
    sOptions += ",resizable="  + (bResizable  ? "yes" : "no") ;
    sOptions += ",scrollbars=" + (bScrollbars ? "yes" : "no") ;
    sOptions += ",left=" + iLeft ;
    sOptions += ",top=" + iTop ;

    var oWindow = window.open(sURL, sName, sOptions)
    oWindow.focus();
    return oWindow ;
}


function open_window(){
param = [];
dparam = [];
dialog=false;
url='about:blank';
nameWin='';

param[0]='toolbar=0';
param[1]='width=200';
param[2]='height=200';
param[3]='scrollbars=0';
param[4]='location=0';
param[5]='resizable=0';
param[6]='status=0';
param[7]='screenX=20';
param[8]='screenY=20';
param[9]='left=20';
param[10]='top=20';
param[11]='menubar=0';

dparam[0]='dialogWidth:200px';
dparam[1]='dialogHeight:200px';
dparam[2]='scroll:0';
dparam[3]='resizable:0';
dparam[4]='status:0';
dparam[5]='dialogLeft:20';
dparam[6]='dialogTop:20';
dparam[7]='help:0';



for(var i=0 ;i<arguments.length;i++){
 ar=arguments[i];//.toLowerCase();
 if(ar=='toolbar'){param[0]='toolbar='+arguments[i+1]}
 if(ar=='width'){param[1]='width='+arguments[i+1];dparam[0]='dialogWidth:'+arguments[i+1]+'px'; }
 if(ar=='height'){param[2]='height='+arguments[i+1];dparam[1]='dialogHeight:'+arguments[i+1]+'px';}
 if(ar=='scrollbars'){param[3]='scrollbars='+arguments[i+1];dparam[2]='scroll:'+arguments[i+1];}
 if(ar=='location'){param[4]='location='+arguments[i+1]}
 if(ar=='resizable'){param[5]='resizable='+arguments[i+1];dparam[3]='resizable:'+arguments[i+1];}
 if(ar=='status'){param[6]='status='+arguments[i+1];dparam[4]='status:'+arguments[i+1];}
 if(ar=='screenX'){param[7]='screenX='+arguments[i+1]}
 if(ar=='screenY'){param[8]='screenY='+arguments[i+1]}
 if(ar=='left'){param[9]='left='+arguments[i+1];dparam[5]='dialogLeft='+arguments[i+1];}
 if(ar=='top'){param[10]='top='+arguments[i+1];dparam[6]='dialogTop='+arguments[i+1];}
 if(ar=='menubar'){param[11]='menubar='+arguments[i+1]}
 if(ar=='url'){url=arguments[i+1]}
 if(ar=='name'){nameWin=arguments[i+1]}
 if(ar=='dialog'){dialog=true}
}
p=param.join(',');
if(!dialog)
openWin=window.open(url,nameWin,p);
else
openWin = showModalDialog(url,nameWin,dparam.join(';'));
}



