// misc js
function add_handler(elm,evT,fn,useCapture) {
    if(elm.addEventListener) {
        elm.addEventListener(evT, fn,useCapture);
        return true;
    } else if(elm.attachEvent) {
        var r = elm.attachEvent('on'+evT, fn)
        return r;
    } else {
        elm['on'+evT] = fn;
    }
}
function gelt(a) { return document.getElementById(a);}

function disp_date() {
    var d=new Date();
    var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var monthname=new Array('January','February', 'March',  'April' , 'May', 'June', 'July', 'August','September', 'October', 'November',  'December');
    var a=weekday[d.getDay()] + ", " +monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
    document.write(a);
}

function ie6hack() {
    if(document.all && document.getElementById) { // hack IE 
	var uls = document.getElementsByTagName("ul");
	var ols = document.getElementsByTagName("ul");
	ie6hack1(uls); ie6hack1(ols);
    }
}
function ie6hack1(uls) {
    for(var j=0; j<uls.length; j++) {
	var ul=uls[j]; var menu=0;
	var p=ul; while(p){if(p.className=="dropdown") {menu=1;break;}  p=p.parentNode;}
	if(menu) {
	    for(i=0; i<ul.childNodes.length; i++) {
		var n = ul.childNodes[i];
		if(n.nodeName.toLowerCase()=="li") {
		    n.onmouseover=function() { this.className+=" over";       }
		    n.onmouseout=function() { this.className=this.className.replace(" over", "");}
		}
	    }
	}
    }
}
add_handler(window,'load',ie6hack);

function bookmarkpage() {
    var t=document.title || 'Info', u=location.href;
    if(window.sidebar) { // firefox
        window.sidebar.addPanel(t,u,"");
    } else if(window.opera && window.print){ // opera
        var e = document.createElement('a');
        e.setAttribute('href',u);
        e.setAttribute('title',t);
        e.setAttribute('rel','sidebar');
        e.click();
    } else if(document.all) {// ie
        window.external.AddFavorite(u,t);
    }
    return false;
}

function emailpage() {
    var t=document.title || 'Info';
    var a = "mailto:?subject=Check out " + t;
    a += "&body=I thought you might be interested in the " + t;
    a += ". You can view it at " + location.href;
    location.href = a;
    return false;
}


function printpage() {
    window.print();
    return false;
}

// handle cookie 
var _reg_white=/^\s*|\s*$/g;
function trim(a){return a.replace(_reg_white,"");};

function get_cookie(n){
    var c = document.cookie || "";
    var d={};
    var a=c.split(";");
    for(var i=0;i<a.length;i++){
	var b=trim(a[i]).split("=");
	if(b[0]){d[b[0]]=b[1]?b[1]:"";}
    }  
    if(n){ return d[n]?d[n]:"";}
    return d;
};

function set_cookie(a,b,ps){  
    ps=ps||{};
    var off=ps.expires?ps.expires:30;
    var path=ps.path?ps.path: "/";
    var tm = new Date();
    tm.setTime(tm.getTime() + parseInt(off*(24*1000*60*60)));
    b=escape(b);
    var c=a + "=" + b+ "; path="+path+"; expires=" + tm.toGMTString();
    document.cookie = c;
};
function delete_cookie(n){  
    if(get_cookie(n)){
	document.cookie = n + "=" + "; path=/; expires=Saturday, 01-Jan-2000 00:00:00 GMT";
    }
};

function gen_name() {
    var a=(new Date().getTime());
    return 'A'+  a.toString(16);
}

