
/*
 * Home page javascript
 * Mixture of open source and internal logic. Free free to use.
 */
var d = document, n = navigator;
var agent = n.userAgent.toLowerCase();
var mX, mY;

//Browser sniff obj
// Usage: if (sniff.bw.ns){
//        if (sniff.os.mac){
// etc.

var sniff = {
    bw: {
        ns:d.layers,
        ie4:agent.indexOf("msie 4.") != -1,
        ie5:agent.indexOf("msie 5.") != -1,
        ie50:agent.indexOf("msie 5.0") != -1,
        ie55:agent.indexOf("msie 5.5") != -1,
        ie6:agent.indexOf("msie 6.") != -1,
        ie:d.all && n.appName.indexOf("Microsoft") != -1,
        dom:d.getElementById,
        safari:d.getElementById && agent.indexOf("safari") != -1,
        ns6:d.getElementById && agent.indexOf("gecko") != -1 && agent.indexOf("safari") < 0,
        opera:window.opera && window.print
    },
    os: {
        win:agent.indexOf("win") != -1,
        mac:agent.indexOf("mac") != -1
    }
};

/*  
Rewrite mailto URLS
*/      
//addr = 'tberes_at_swdesignbuild_dot_com';
function rewriteAddress(addr, subj){
    var re= /_at_/gi;
    addr = addr.replace(re,'@');
    var re= /_dot_/gi;
    addr = addr.replace(re,'.');
    
    if (!subj){
    	subj = "Scoreboard Pro Information Request";
    }
    var spaceRE = / /gi;
    subj	= subj.replace(spaceRE, '%20');
    
    var the_link="mai" + "lto" +":"+addr+"?subject="+subj;
    window.location=the_link;
}
/* ---------------------------------------
   author: Vincent Puglia, GrassBlade Software
   site:   http://members.aol.com/grassblad
 
   modified TEB redid sniffing
------------------------------------------- */
function bookIt(site, title)
{
	if (!site){
		site = window.location;
	}
	if (!title){
		title = "Scoreboard Pro";
	}

    if (sniff.bw.ie){
        window.external.AddFavorite(site, title);
    }
    else if( sniff.bw.ns6 ) {
        //Gecko (Netscape 6 etc.) - add to Sidebar
        window.sidebar.addPanel( title, site, '' );
    }
    else if( sniff.bw.opera ) {
        //Opera 6+ - add as sidebar panel to Hotlist TODO
        return true;
    }
    else if( sniff.bw.ns ) {
        //NS4 & Escape - tell them how to add a bookmark quickly (adds current page,
        //not target page)
        window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
    }
    else {
        //other browsers - tell them to add a bookmark (adds current page, not target page)
        window.alert( 'Please use your browser\'s bookmarking facility to create a bookmark' );
    }
    return true;
}   

function setCookie(name,value,days) {
    var cookie = name + "=" + value + ";";
    if (days) {
        var myDate=new Date();
        myDate.setTime(myDate.getTime()+(days*24*60*60*1000));
        cookie += " expires=" + myDate.toGMTString() + ";";
    }
    cookie += " path=/";
    document.cookie = cookie;
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(";");
    for(var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == " ") c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return "";
}
