/* Javascript by Daniel Cohen Gindi (c) danielgindi@gmail.com 054-5655765 */
/* Version: 2009-04-20 */

function $find(n) { return document.getElementById ? document.getElementById(n) : (document.layers ? document.layers[n] : document.all[n]); }
function $offset(e) { if (e.pageX) return [e.pageLeft, e.pageTop]; else { var l = 0, t = 0; if (e.offsetParent) { do { l += e.offsetLeft; t += e.offsetTop; } while (e = e.offsetParent); } return [l, t]; }; }
function $height(e) {
    if (e) {
        if ($ver.ns4) ret = e.clip.height;
        else {
            var ret =
	        ((e.clip && e.clip.bottom) ? (e.clip.bottom - e.clip.top) : ((e.document && e.document.height) ? e.document.height : null)) ||
	        e.style.height || e.clientHeight || e.height || e.offsetHeight || e.style.pixelHeight ||
	        e.parentNode.style.height || e.parentNode.clientHeight || e.parentNode.height;
        }
    }
    if (ret) return parseInt(ret); else return null;
}
function $width(e) {
    if (e) {
        if ($ver.ns4) ret = e.clip.width;
        else {
            var ret =
	        ((e.clip && e.clip.right) ? (e.clip.right - e.clip.left) : ((e.document && e.document.width) ? e.document.width : null)) ||
	        e.style.width || e.clientWidth || e.width || e.offsetWidth ||
	        e.parentNode.style.width || e.parentNode.clientWidth || e.parentNode.width;
        }
    }
    if (ret) return parseInt(ret); else return null;
}
function getWindowClientHeight() { return ((document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : ((document.body && document.body.clientHeight) ? document.body.clientHeight : window.innerHeight)); }
function getWindowClientWidth() { return ((document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : ((document.body && document.body.clientWidth) ? document.body.clientWidth : window.innerWidth)); }
function getPageYOffset(e) { return window.pageYOffset || (document.documentElement ? (document.documentElement.scrollTop || document.body.scrollTop) : null);}
$ver = {
    w3c: ((document.getElementById) ? true : false),
    ns4: ((document.layers) ? true : false),
    ie: (navigator.appVersion.indexOf("MSIE") >= 0) ? true : false,
    ie4: (document.all && !this.w3c) ? true : false,
    ie5: (document.all && this.w3c) ? true : false,
    ie6: (document.getElementById && navigator.appVersion.indexOf("MSIE 6.0") >= 0) ? true : false,
    ie7: (document.getElementById && navigator.appVersion.indexOf("MSIE 7.0") >= 0) ? true : false,
    ns6: (document.getElementById && navigator.appName.indexOf("Netscape") >= 0) ? true : false,
    chrome: (document.getElementById && navigator.appVersion.indexOf("Chrome") >= 0) ? true : false
};
function registerEvent(element, event, ev_func, capture) {
    if (element == null) return;
    if (element.addEventListener) element.addEventListener(event, ev_func, capture ? true : false);
    else if (element.attachEvent) element.attachEvent('on' + event, ev_func);
    return ev_func;
}
function unregisterEvent(element, event, ev_func, capture) {
    if (element == null) return;
    if (element.removeEventListener) element.removeEventListener(event, ev_func, capture ? true : false);
    else if (element.detachEvent) element.detachEvent('on' + event, ev_func);
}
function escapeJsString(str) {
    if (str === undefined || str === null) return '';
    else return str.replace(/\'/, "\\\'").replace(/\"/, "\\\"").replace(/\\/, "\\\\").replace(/\r/, "\\r").replace(/\n/, "\\n");
}
function winPopup(URL, width, height, wndName, forceReload) {
    if (wndName == undefined || wndName == null) wndName = "";
    var newWnd = window.open("", wndName, config = "height=" + height + ",width=" + width + ",resizable=no,toolbars=no,address=no,status=no,menubar=no,location=no,toolbar=no,scrollbars=no")
    if (forceReload == true) {
        newWnd.document.close();
        newWnd.document.open();
    }
    newWnd.document.location = URL;
    newWnd.window.focus();
    return newWnd;
}
function saveCookie(id, value, expires) {
    if (expires) {
        var date = new Date();
        date.setTime(date.getTime() + (parseInt(expires, 10) * (24*60*60*1000)));
        expires = date.toUTCString();
    }
    else expires = null;
    document.cookie = id + '=' + escape(value) + '; path=/' + ((expires == null) ? '' : '; expires=' + expires);
}
function readCookie(id) {
    var dc = document.cookie;
    id = id + '=';

    if (dc.length > 0) {
        begin = dc.indexOf(id);
        if (begin != -1) {
            begin += id.length;
            end = dc.indexOf(';', begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        }
    }
    return null;
}
function simulateContainedAnchorClick(item, level){
	for (var i=0; i<level; i++){
		if (i<level && !item.firstChild) return;
		else if (i==level && !item.href) return;
		if (i<level) item=item.firstChild;
	}
	if (item.href) {
		if (item.target && item.target.length>0) window.open(item.href, item.target);
		else document.location = item.href; 
		return false;
	};
}