

var isIE = document.all;
var isNN =! document.all && document.getElementById;
var isN4 = document.layers;

function getById(id) {
    var elem = null;
    if (document.getElementById) {
        elem = document.getElementById(id);
    } else if (document.all) {
        elem = document.all[id];
        if (!elem) {
            elem = eval('document.all.' + id);
        }
    } else if (document.layers) {
        elem = getObjNN4(document, id);
    }

    if (!elem) {
        elem = document.getElementById(id);
    }                   
    return elem;  
}

function getObjNN4(obj,name) {
    var x = obj.layers;
    var foundLayer;
    for (var i=0;i<x.length;i++) {
        if (x[i].id == name) {
            foundLayer = x[i];
        } else if (x[i].layers.length) {
            var tmp = getObjNN4(x[i],name);
            if (tmp) {
                foundLayer = tmp;
            }
        }
    }
    return foundLayer;
}


function getInnerHtml(element) {
    if (element.innerHTML != null) {
        return element.innerHTML;
    } else if (document.layers) {
        return element.document.read();
    }
}

function setInnerHtml(element, html) {
    if (element.innerHTML != null) {
        element.innerHTML = '';
        element.innerHTML = html;
    } else if (document.layers) {
        element.document.open();
        element.document.write(html);
        element.document.close();
    } else {
        element.innerHtml = '';
        element.innerHtml = html;
    }

    if (element.refresh) {
        element.refresh();
    }
    if (element.document && element.document.refresh) {
        element.document.refresh();
    }
}

function setVisible(element, vis) {
    if (isIE || isNN) {
        if (vis) {
            element.style.visibility = "visible";
        } else {
            element.style.visibility = "hidden";
        }
    } else if (isN4) {
        if (vis) {
            element.style.visibility = "show";
        } else {
            element.style.visibility = "hide";
        }
    } else {
        if (vis) {
            element.style.visibility = "visible";
        } else {
            element.style.visibility = "hidden";
        }
    }
}

function isVisible(element) {
    if (isIE || isNN) {
        return element.style.visibility == "visible";
    } else if (isN4) {
        return element.style.visibility == "show";
    } else {
        return element.style.visibility == "visible";
    }
}

function escape(str) {
    return str;
}

function getX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }
    return curleft;
}

function getY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
/*
        while (obj.parent && obj.parent != top) {
            curtop += obj.parent.offsetTop;
            obj = obj.parent;
        }
*/
    } else if (obj.y) {
        curtop += obj.y;
    }
    return curtop;
}



function setX(obj, x) {
    if (obj.style) {
        obj.style.left = x + 'px';
    } else if (obj.left) {
        obj.left = x + 'px';
    } else if (obj.x) {
        obj.x = x;
    }
}


function setY(obj, y) {
    if (obj.style.top) {
        obj.style.top = y + 'px';
    } else if (obj.top) {
        obj.top = y + 'px';
    } else if (obj.y) {
        obj.y = y;
    }
}


function getWidth(obj) {
    if (obj.clip && obj.clip.width) {
        return obj.clip.width;
    }
    if (obj.offsetWidth) {
        return obj.offsetWidth;
    }
    if (obj.width) {
        return obj.width;
    }
    if (obj.w) {
        return obj.w;
    }
    if (obj.style && obj.style.width) {
        return obj.style.width;
    }
    if (obj.style && obj.style.pixelWidth) {
        return obj.style.pixelWidth;
    }
    return -1;
}

function getHeight(obj) {
    if (obj.clip && obj.clip.height) {
        return obj.clip.height;
    }
    if (obj.offsetHeight) {
        return obj.offsetHeight;
    }
    if (obj.height) {
        return obj.height;
    }
    if (obj.h) {
        return obj.h;
    }
    if (obj.style && obj.style.height) {
        return obj.style.height;
    }
    if (obj.style && obj.style.pixelHeight) {
        return obj.style.pixelHeight;
    }
    return -1;
}





function setHeight(obj, h) {
    if (obj.clip && obj.clip.height) {
        obj.clip.height = h + "px";
        return;
    }
    if (obj.style && obj.style.height) {
        obj.style.height = h + "px";
        return;
    }
    if (obj.style && obj.style.pixelHeight) {
        obj.style.pixelHeight = h + "px";
        return;
    }
    if (obj.offsetHeight) {
        obj.offsetHeight = h;
        return;
    }
    if (obj.height) {
        obj.height = h;
        return;
    }
    if (obj.h) {
        obj.h = h;
        return;
    }
}

function setWidth(obj, w) {
    if (obj.clip && obj.clip.width) {
        obj.clip.width = w + "px";
        return;
    }
    if (obj.style && obj.style.width) {
        obj.style.width = w + "px";
        return;
    }
    if (obj.style && obj.style.pixelWidth) {
        obj.style.pixelWidth = w + "px";
        return;
    }
    if (obj.offsetWidth) {
        obj.offsetWidth = w;
        return;
    }
    if (obj.width) {
        obj.width = w;
        return;
    }
    if (obj.w) {
        obj.w = w;
        return;
    }
}




function getFlashML(url, width, height) {
    var ml = '';
    ml += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
    ml += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ';
    ml += 'width="' + width + '" height="' + height + '" id="' + url + '" align="middle">';
    ml += '<param name="allowScriptAccess" value="sameDomain" />';
    ml += '<param name="movie" value="' + url + '" />';
    ml += '<param name="quality" value="high" />';
    ml += '<param name="bgcolor" value="#ffffff" />';
    ml += '<embed src="' + url + '" quality="high" bgcolor="#ffffff" width="' + width + '" ';
    ml += 'height="' + height + '" name="' + url + '" align="middle" allowScriptAccess="sameDomain" ';
    ml += 'type="application/x-shockwave-flash" ';
    ml += 'pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    ml += '</object>';
    return ml;
}



function sterilize(e, clickonly) {
    if (!e) {
        return;
    }
    if (e.ondblclick) {
        e.ondblclick = null;
    }
    if (e.onclick) {
        e.onclick = null;
    }
    if (!clickonly) {
        if (e.onmouseover) {
            e.onmouseover = null;
        }
        if (e.onmouseout) {
            e.onmouseout = null;
        }
        if (e.onmousedown) {
            e.onmousedown = null;
        }
        if (e.onmouseup) {
            e.onmouseup = null;
        }
        if (e.onmouseenter) {
            e.onmouseenter = null;
        }
        if (e.onmouseleave) {
            e.onmouseleave = null;
        }
        if (e.onmousemove) {
            e.onmousemove = null;
        }
        if (e.onselectstart) {
            e.onselectstart = null;
        }
        if (e.oncontextmenu) {
            e.oncontextmenu = null;
        }
        if (e.onkeypress) {
            e.onkeypress = null;
        }
        if (e.onkeydown) {
            e.onkeydown = null;
        }
        if (e.onkeyup) {
            e.onkeyup = null;
        }
        if (e.onchange) {
            e.onchange = null;
        }
        if (e.onreset) {
            e.onreset = null;
        }
        if (e.onselect) {
            e.onselect = null;
        }
        if (e.onsubmit) {
            e.onsubmit = null;
        }
        if (e.onblur) {
            e.onblur = null;
        }
        if (e.onfocus) {
            e.onfocus = null;
        }
        if (e.onload) {
            e.onload = null;
        }
        if (e.onresize) {
            e.onresize = null;
        }
        if (e.onscroll) {
            e.onscroll = null;
        }
        if (e.onunload) {
            e.onunload = null;
        }
        if (e.onabort) {
            e.onabort = null;
        }
        if (e.onerror) {
            e.onerror = null;
        }
        if (e.onsubtreemodified) {
            e.onsubtreemodified = null;
        }
    }
    if (!e.childNodes) {
        return;
    }
    for (var i = 0; i < e.childNodes.length; i++) {
        if (e.childNodes[i]) {
            sterilize(e.childNodes[i]);
        }
    }
}





/*
 * COOKIES
 *****************************************************************/

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return 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));
}


/*
   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)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

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






/*
 * This extremely lame function opens a popup window, at the specified
 * url, with the specified window name, the specified width, and height.
 */
function spawn(url, nameW, w, h) {
    if (navigator.appVersion.indexOf('4') != -1) {
        // Vars for centering the new window on Version 4 Browsers
        x4 = screen.width/2 - (w/2);
        y4 = screen.height/2 - (h/2);
        foo = window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=1,resizable=1,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + x4 + ',top=' + y4 + '');
    } else {
        foo = window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=1,resizable=1,menubar=0,toolbar=0,status=0,location=0,directories=0,left=150,top=150');
    }
    foo.focus();
}


