//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
// browser independent library code
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
var bIe=navigator.userAgent.indexOf("MSIE")!=-1 && document.all && !window.innerWidth;
var bMz=navigator.userAgent.indexOf("Gecko")!=-1 && document.getElementById && !document.all;
var bOp=navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById ? 1:0;
var bKn=navigator.userAgent.indexOf("Konqueror")!=-1 && document.getElementById && document.body.offsetWidth ? 1:0;
var bNs=navigator.userAgent.indexOf("Opera")==-1 && document.getElementById && !document.all;
var bOp6=bOp && document.body.offsetWidth ? 1:0;
var bNs4=document.layers ? 1:0;

var dlg=new Object(),timerclose=0;
function dlgCheckFocus2() 
{
    if (dlg.win && !dlg.win.closed)
        dlg.win.focus();
}

function dlgCheckFocus() 
{
    setTimeout("dlgCheckFocus2()",50);
}

function dlgCheckClose() 
{
    if (!dlg.win || dlg.win.closed) 
    {
        window.onfocus='';
        window.onclose='';
        dlg.win=0;
        if (timerclose)
            clearTimeout(timerclose);
        timerclose=0;
    }
}

function dlgClose() 
{
    if (dlg.win && !dlg.win.closed) 
    {
        dlg.win.close();
        dlgCheckClose();
    }
}

function openDialog(url,execfn,width,height,userval) 
{
    var attr,left,top;
    if (dlg.win && !dlg.win.closed) 
    {

        dlgCheck();
        return;
    }
    dlg.dstitem=0;
    dlg.execfn=0;
    dlg.userval=userval;
    if (execfn.value)
        dlg.dstitem=execfn;
    else
        dlg.execfn=execfn;

    if (!bIe) 
    {
        left=window.screenX+((window.outerWidth-width)/2);
        top =window.screenY+((window.outerHeight-height)/2);
        attr="screenX="+left+",screenY="+top;
    }
    else 
    {
        left=(screen.width-width)/2;
        top =(screen.height-height)/2;
        attr="left="+left+",top="+top;
    }

    attr+=",scrollbars=1,resizable=yes,width="+width+",height="+height;
    dlg.win=window.open(url,'',attr)
    dlg.win.focus();
    
    window.onfocus=dlgCheckFocus;
    window.onclose=dlgCheckClose;
    timerclose=setInterval("dlgCheckClose()",100);
}

var xmlHttp;
var xmlDOM;

function GetXmlHttpObject(handler)
{ 
    var objXmlHttp = null;

    if (bOp)
    {
        alert("This example doesn't work in Opera") ;
        return; 
    }

    if (bIe)
    { 
        var strName = "Msxml2.XMLHTTP";
    
        if (bIe)
        {
            strName = "Microsoft.XMLHTTP";
        } 

        try
        { 
            objXmlHttp = new ActiveXObject(strName);
            objXmlHttp.onreadystatechange = handler; 
            return objXmlHttp;
        }        
        catch(e)
        { 
            alert("Error. Scripting for ActiveX might be disabled"); 
            return; 
        } 
    } 
    else {

        if (bMz)
        {
            objXmlHttp = new XMLHttpRequest();
            objXmlHttp.onload = handler;
            objXmlHttp.onerror = handler; 
            return objXmlHttp;
        }
    }
} 

// Create DOM object from WebService call result
function GetXmlDOMObject(result)
{
    var objXML=null;
    
    if (bIe)
    { 
        //now load XML into dom 
        objXML = new ActiveXObject("Microsoft.XMLDOM");
        objXML.async = false;
        objXML.loadXML(result);
        return objXML;
    }
}

function HttpObjectResult()
{
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    { 
        // check if there is no general connection error
        if (xmlHttp.status == 12007)
        {
            alert("Network errror: Connection to Xerox Password Management server failed.");
            window.close();
        }
        else
        {
            return(true);
        }
    }

    return(false);
}

function getElement(a) 
{
    return(bIe ? document.all[a]:bNs4 ? document.layers[a]:document.getElementById(a));
}

function getElementInFrame(frame,id)
{
    if (bIe)
        return(window.parent.frames(frame).HitList.document.getElementById(id));
}

// parse string into array.
// Str - input string
// Separator - character separators
function parseStringToArray(Str,Separator)
{
    var arr        = new Array(0);
    var startIndex = 0;

    for (var i = 0; i < Str.length; i++)
    {
        if (Str.charAt(i) == Separator) 
        {
            arr.push(Str.substring(startIndex,i));    

            startIndex = i + 1;
        }
    }

    // add last item (it can be whole string too)
    arr.push(Str.substring(startIndex,i));    

    return (arr);
}

/**
 * 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)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * 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";
    }
}

