function browserSniffer() {
    if(document.all && !document.getElementById) {
        return "ie4";
    }
    else if(document.layers) {
        return "ns4";
    }
    else if(document.all && document.getElementById) {
        return "ie5";
    }
    else if(document.getElementById && !document.all) {
        return "ns6";
    }
    else {
        return "";
    }
}

function movein(element,div) {
    var menuText;
    if(element) {
        menuText = '<TABLE onMouseLeave="moveout(' + element.id + ',' + div.id + ');" cellspacing=1 callpadding=0 border=0 ' +
                   'style="COLOR: white; BACKGROUND-COLOR: #999999"><TR><TD name=dude class=menuTD ' +
                   'onMouseOver="menuMoveIn(this);" onMouseOut="menuMoveOut(this);"><SPAN class=normal>' +
                   'Michigan Sweatshirt</SPAN></TD></TR><TR><TD class=menuTD onMouseOver="menuMoveIn(this);"' +
                   'onMouseOut="menuMoveOut(this);"><SPAN class=normal>Michigan T-Shirt</SPAN></TD></TR><TR>' +
                   '<TD class=menuTD onMouseOver="menuMoveIn(this);" onMouseOut="menuMoveOut(this);">' +
                   '<SPAN class=normal>Michigan Baseball Cap</SPAN></TD></TR><TR><TD class=menuTD ' +
                   'onMouseOver="menuMoveIn(this);" onMouseOut="menuMoveOut(this);"><SPAN class=normal>U of ' +
                   'M Playing Cards</SPAN></TD></TR><TR><TD class=menuTD onMouseOver="menuMoveIn(this);" ' +
                   'onMouseOut="menuMoveOut(this);"><SPAN class=normal>MSU Dart Board</SPAN></TD></TR><TR>' +
                   '<TD class=menuTD onMouseOver="menuMoveIn(this);" onMouseOut="menuMoveOut(this);">' +
                   '<SPAN class=normal>Occasionally Jelly</SPAN></TD></TR><TR><TD class=menuTD ' +
                   'onMouseOver="menuMoveIn(this);" onMouseOut="menuMoveOut(this);"><SPAN class=normal>' +
                   'Holiday Gift Basket</SPAN></TD></TR></TABLE>'
                   
        element.style.cursor = 'hand';
        element.style.backgroundColor = '#fffebc';
        element.style.borderRight='#999999 1px solid';
        element.style.borderTop='#999999 1px solid';
        element.style.borderLeft='#999999 1px solid';
        element.style.borderBottom='#999999 1px solid';
        div.style.position ='absolute';
        div.style.left = element.offsetLeft;
        div.style.top = element.offsetTop + element.offsetHeight + 71;
        div.innerHTML = menuText;
    }
    return true;
}
   
function moveout(element,div) {
    window.setTimeout("menuClear(" + element.id + "," + div.id + ");", 500);
    return true;
}

function menuClear(element,div) {
    div.innerHTML = '';
    menuItemClear(element);    
    return true;
}

function menuItemClear(element){
    if (element) {
        element.style.cursor='';
        element.style.backgroundColor='White'
        element.style.borderRight='white 1px solid';
        element.style.borderTop='white 1px solid';
        element.style.borderLeft='white 1px solid';
        element.style.borderBottom='white 1px solid';
    }
    return true;
}

function menuMoveIn(element) {
    var menuText;
    if(element) {
        element.style.cursor='hand';
        element.style.backgroundColor='#fffebc';
    }
    return true;
}

function menuMoveOut(element) {
    if (element) {
        element.style.cursor='';
        element.style.backgroundColor='White';
    }
    return true;
}

function getExpDate(days, hours, minutes) {
    var expDate = new Date;
    
    if(typeof days == "number" && typeof hours == "number" && typeof minutes == "number") {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        
        return expDate.toGMTString();
    }
}

function getCookieVal(offset) {
    var endString = document.cookie.indexOf(";",offset);
    
    if(endString == -1) {
        endString = document.cookie.length;
    }
    
    return unescape(document.cookie.substring(offset,endString));
}

function getCookie(name) {
    var arg = name + "=";
    var argLen = arg.length;
    var cookieLen = document.cookie.length;
    var i = 0;
    
    while(i < cookieLen) {
        var j = i + argLen;
        
        if(document.cookie.substring(i,j) == arg) {
            return getCookieVal(j);
        }
        
        i = document.cookie.indexOf(" ",i) + 1;
        
        if(i == 0) break;
    }
    
    return "";
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

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";
    }
}

var isCSS, isW3C, isIE4, isNN4, isIECSS;

function initDHTMLAPI() {
    if(document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
    }
}

function seekLayer(doc, name) {
    var theObj;
    
    for(var i=0; i<doc.layers.length; i++) {
        if(doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        
        if(doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

function getRawObject(obj) {
    var theObj;
    
    if(typeof obj == "string") {
        if(isW3C) {
            theObj = document.getElementById(obj);
        }
        else if (isIE4) {
            theObj = document.all(obj);
        }
        else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    }
    else {
        theObj = obj;
    }
    return theObj;
}

function getObject(obj) {
    var theObj = getRawObject(obj);
    
    if(theObj && isCSS) {
        theObj = theObj.style;
    }
    
    return theObj;
}

function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    
    if(theObj) {
        if(isCSS) {
            var units = (typeof theObj.left == "string") ? "px" : 0;
            
            theObj.left = x + units;
            theObj.top = y + units;
        }
        else if (isNN4) {
            theObj.moveTo(x,y);
        }
    }
}

function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    
    if(theObj) {
        if(isCSS) {
            var units = (typeof theObj.left == "string") ? "px" : 0;
            
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        }
        else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    
    if(theObj) {
        theObj.zIndex = zOrder;
    }
}

function setBGColor(obj, color) {
    var theObj = getObject(obj);
    
    if (theObj) {
        if (isNN4) {
            theObj.bgColor = color;
        }
        else if(isCSS) {
            theObj.backgroundColor = color;
        }
    }
}

function show(obj) {
    var theObj = getObject(obj);
    
    if(theObj) {
        theObj.visibility = "visible";
    }
}

function hide(obj) {
    var theObj = getObject(obj);
    
    if(theObj) {
        theObj.visibility = "hidden";
    }
}

function getObjectLeft(obj) {
    var elem = getRawObject(obj);
    var result = 0;
    
    if(document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } 
    else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    }
    else if (elem.style) {
        result = elem.style.left;
    }
    else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

function getObjectTop(obj) {
    var elem = getRawObject(obj);
    var result = 0;
    
    if(document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } 
    else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    }
    else if (elem.style) {
        result = elem.style.top;
    }
    else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}

function getObjectWidth(obj) {
    var elem = getRawObject(obj);
    var result = 0;
    
    if(elem.offsetWidth) {
        result = elem.offsetWidth;
    }
    else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    }
    else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

function getObjectHeight(obj) {
    var elem = getRawObject(obj);
    var result = 0;
    
    if(elem.offsetHeight) {
        result = elem.offsetHeight;
    }
    else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    }
    else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

function getInsideWindowWidth() {
    if(window.innerWidth) {
        return window.innerWidth;
    }
    else if (isIE6CSS) {
        return document.body.parentElement.clientWidth;
    }
    else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}

function getInsideWindowHeight() {
    if(window.innerHeight) {
        return window.innerHeight;
    }
    else if (isIE6CSS) {
        return document.body.parentElement.clientHeight;
    }
    else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}

function getFirstDay(theYear, theMonth) {
    var firstDate = new Date (theYear,theMonth,1);
    
    return firstDate.getDay();
}

function getMonthLen(theYear,theMonth) {
    var nextMonth = new Date (theYear, theMonth + 1, 1);
    
    nextMonth.setHours(nextMonth.getHours() - 3);
    return nextMonth.getDate();
}

function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    
    while(offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    
    if(navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left: offsetLeft, top: offsetTop};
}

function showCalendar(evt, topOffSet, widthOffSet) {
    evt = (evt) ? evt : event;
    
    if(evt) {
        if(document.getElementById("calendar").style.visibility != "visible") {
            var elem = (evt.target) ? evt.target : evt.srcElement;
            var position = getElementPosition(elem.id);
            
            shiftTo("calendar", position.left + elem.offsetWidth + widthOffSet, position.top - topOffSet);
            
            show("calendar");
        }
        else {
            hide("calendar");
        }
    }
    return false;
}

function populateTable(form) {
    var theMonth = form.chooseMonth.selectedIndex;
    var theYear = parseInt(form.chooseYear.options[form.chooseYear.selectedIndex].text);
    var firstDay = getFirstDay(theYear, theMonth);
    var howMany = getMonthLen(theYear, theMonth);
    var today = new Date();     
    var dayCounter = 1;
    var THeader = document.getElementById("tableHeader");
    var TBody = document.getElementById("tableBody");
    var newR, newC, dateNum;
    var done =  false;
    var classText;
    
    THeader.innerHTML = form.chooseMonth.options[theMonth].text + " " + theYear;
    
    while (TBody.rows.length > 0) {
        TBody.deleteRow(0);
    }
  
    while (!done) {
        newR = TBody.insertRow(TBody.rows.length);
       
        if(newR) {
            for(var i = 0; i < 7; i++) {
                newC = newR.insertCell(newR.cells.length);
                
                if(TBody.rows.length == 1 && i < firstDay) {
                    newC.innerHTML = "&nbsp;";
                    continue;
                }
                
                if(dayCounter == howMany) {
                    done = true;
                }
                
                if(dayCounter <= howMany) {
                    if(today.getFullYear() == theYear && today.getMonth() == form.chooseMonth.selectedIndex && today.getDate() == dayCounter) {
                        newC.id = "today";
                        classText = "style='COLOR: red; FONT-WEIGHT: bold'";
                    }
                    else {
                        classText = "";
                    }
                    
                    newC.innerHTML = "<A class='EmailA' href='#' " + classText + " onClick='chooseDate(" + dayCounter + "," + theMonth + "," + theYear + "); return false;'>" + dayCounter + "</A>";
                    dayCounter++;
                }
                else {
                    newC.innerHTML = "&nbsp;";
                }
            }
        }
        else {
            done = true;
        }   
    }
}

function fillYears() {
    var today = new Date();
    var thisYear = today.getFullYear();
    var yearChooser = document.dateChooser.chooseYear;
    
    for(var i=thisYear - 1; i<thisYear + 5; i++) {
        yearChooser.options[yearChooser.options.length] = new Option(i, i);
    }
    
    yearChooser.selectedIndex = 1;
    
    setCurrMonth(today);
}

function setCurrMonth(today) {
    document.dateChooser.chooseMonth.selectedIndex = today.getMonth();
}