var browser = 0;

if (navigator.appName.indexOf("Explorer") != -1)
    browser = 1;
else
    browser = 0;

function ViewPort()
{
    var w;
    var h;
    
    if (browser == 1)
    {
        w = screen.availWidth;
        h = screen.availHeight;
    }
    else
    {
        w = window.innerWidth;
        h = window.innerHeight;
    }
    
    this.getWidth = function() { return(w); }
    this.getHeight = function() { return(h); }
    
    this.getPixelWidth = function() { return(this.getWidth() + "px"); }
    this.getPixelHeight = function() { return(this.getHeight() + "px"); }
}

function htmlSpecialChars(str)
{
    return(String(str).replace(/&/, '&amp;').replace(/"/, '&quot;').replace(/'/, '&#039;').replace(/</, '&lt;').replace(/>/, '&gt;').replace(/ä/, '&auml;').replace(/ö/, '&ouml;').replace(/ü/, '&uuml;').replace(/Ä/, '&Auml;').replace(/Ö/, '&Ouml;').replace(/Ü/, '&Uuml;'));
}

function createAttrib(doc, attr_name, attr_value, elem)
{
    var attrib = doc.createAttribute(attr_name);
    attrib.nodeValue = attr_value;
    if ((elem != undefined) && (elem != null))
        elem.setAttributeNode(attrib);
}

function changeAttribute(node, attr_name, attr_value)
{
    var attr = node.getAttributeNode(attr_name);
    attr.nodeValue = attr_value;
    node.setAttributeNode(attr, attr_name);
}

function getProperties(obj)
{
    var pos = self.location.href.lastIndexOf('/');
    var hr = self.location.href.substr(0, (pos + 1));
    var win = window.open((hr + 'javascript/js/getProperties.html'), '', 'dependent=yes,location=no,menubar=no,resizable=yes,status=yes,toolbar=no,scrollbars=yes');
    win.title = 'getProperties';
    if (browser == 1) // Explorer
    {
        while (win.isLoaded != true) {}
        win.getProperties(obj);
    }
    else
        win.onload = function() { win.getProperties(obj); }
}

function getProperties_simple(obj)
{
    var val;
    
    for (var prop in obj)
    {
        try
        {
            val = obj[prop];
        }
        catch (e)
        {
            val = '{READ_ONLY}';
        }
        
        if (!confirm('('+typeof(prop)+') '+prop+' = '+val))
            break;
    }
}

function getStyle(stylesheet, stylename, doc)
{
    if (doc == null)
        doc = document;
    
    for (var i = 0; i < doc.styleSheets.length; i++)
    {
        if (doc.styleSheets[i].href.substr(doc.styleSheets[i].href.length - stylesheet.length) == stylesheet)
        {
            for (var j = 0; j < doc.styleSheets[i].cssRules.length; j++)
            {
                if (doc.styleSheets[i].cssRules[j].selectorText == stylename)
                    return(doc.styleSheets[i].cssRules[j].style);
            }
        }
    }
    
    return(null);
}

function wait(msecs)
{
    var now0 = new Date().getTime();
    var now1;
    do
    {
        now1 = new Date().getTime();
    }
    while ((now1 - now0) < msecs);
}

function setCookie(cookie_name, cookie_value, expires)
{
    var cookie_text = (cookie_name + "=" + cookie_value);
    if (expires != null)
        cookie_text += ("; expires=" + expires.toGMTString());
    document.cookie = cookie_text;
}

function deleteCookie(cookie_name)
{
    var cookie_date = new Date();
    cookie_date.setTime(cookie_date.getTime() - 1);
    
    setCookie(cookie_name, "", cookie_date);
}
