// BROWSER SNIFFER (Sniff out the good and bad browsers)
function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2 = (this.ns && (this.major == 2));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4b = (this.ns && (this.minor < 4.04));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ie   = (agent.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));
    this.op3 = (agent.indexOf("opera") != -1);
    this.win   = (agent.indexOf("win")!=-1);
    this.mac   = (agent.indexOf("mac")!=-1);
    this.unix  = (agent.indexOf("x11")!=-1);
}

var is = new Is();

function onerror() { document.location.href = "javascript:"; }

// DOCUMENT OBJECT SWITCH (Used for building cross_browser functions)
if(is.ns4) {
    doc = "document";
    sty = "";
    htm = ".document"
} else if(is.ie4) {
    doc = "document.all";
    sty = ".style";
    htm = ""
}

//DIV TOGGLE (hides the old one and makes the new one visible)
var old_DIV = "";

function toggleDIV(selection) {
	if (old_DIV != "")
	{
	    var old_DIV_obj = eval(doc + "." + old_DIV + sty);
		old_DIV_obj.visibility = "hidden";
	}

    var new_DIV_obj = eval(doc + "." + selection + sty);
    new_DIV_obj.visibility = "visible";

    old_DIV = selection;
}

function hideDIV(selection) {
	if (selection != "")
	{
		var DIV_obj = eval(doc + "." + selection + sty);
		DIV_obj.visibility = "hidden";
	}
	else {
		if (old_DIV != "")
		{
			var old_DIV_obj = eval(doc + "." + old_DIV + sty);
			old_DIV_obj.visibility = "hidden";
		}
	}
	
}

function getMotorMinute() {
	var fileName = getFileName();
	motorminute = new Image();
    motorminute.src = "../pics/" + fileName;
}

//For the Mr Know It All
//gets the date of the latest Saturday
function getKnowItAll(weeksToGoBack){
	var FebDays = 28;
	var thisDate = new Date();
	var thisMonth = thisDate.getMonth();
	var thisDay = thisDate.getDate();
	var thisDayOfWeek = thisDate.getDay();
	var thisYear = thisDate.getYear();
	(thisYear/4 == parseInt(thisYear/4)) ? FebDays = 29 : FebDays = 28;  //Checks for a leap year.
	var monthDaysArray = new Array(31,FebDays,31,30,31,30,31,31,30,31,30,31); //Make a max days in month array.
	
	if(thisDayOfWeek < "6"){
		latestSaturday = thisDay - 1 - thisDayOfWeek - (7 * weeksToGoBack);
		if(latestSaturday < 1){				//If that day is in the previous month
			thisMonth = thisMonth - 1;		//bump the month back one.
			if(thisMonth < 0) thisMonth = 11;		//If the month before was last year set the month to December.
			latestSaturday = monthDaysArray(thisMonth) - latestSaturday; //Set back right number of days in that month.
		}
	}
	else{
		latestSaturday = thisDay - (7 * weeksToGoBack);
	}

	thisMonth = thisMonth + 1;
	(thisMonth<10) ? thisMonth = "0" + String(thisMonth) : thisMonth = String(thisMonth);
	(latestSaturday<10) ? latestSaturday = "0" + String(latestSaturday) : latestSaturday = String(latestSaturday);
	return thisMonth + "-" + latestSaturday + ".gif";
}


function getFileName(findDayOfWeek, LookDir,JustShowToday){
//findDayOfWeek is the day of the week to base the file name upon. Sun=0,Mon=1,Tues=2...Sat=6
//LookDir is either 0 or 1. 0 means look Backwards to find the day while 1 means to look forward
//JustShowToday needs to be 1 to return today's (or if today is weekend then show Friday)
	var FebDays = 28;
	var thisDate = new Date();
	var thisMonth = thisDate.getMonth();
	var thisDay = thisDate.getDate();
	var thisDayOfWeek = thisDate.getDay();
	var thisYear = thisDate.getYear();
	(thisYear/4 == parseInt(thisYear/4)) ? FebDays = 29 : FebDays = 28;  //Checks for a leap year.
	var monthDaysArray = new Array(31,FebDays,31,30,31,30,31,31,30,31,30,31); //Make a max days in month array.
	var daysToMove = 0;
	var findDay = thisDay;
	var findMonth = thisMonth;

	if ((JustShowToday == 1) && ((thisDayOfWeek==6)||(thisDayOfWeek==0))){
		findDayOfWeek = 5;
		LookDir = 0;
	}

	if (LookDir % 2 == 0) {   //looking backwards
		daysToMove = 7-findDayOfWeek+thisDayOfWeek;
		if (daysToMove > 7) daysToMove = daysToMove - 7;
		daysToMove = daysToMove * (-1);
	}
	else {  //looking forward
		daysToMove = 7 - thisDayOfWeek + findDayOfWeek;
		if (daysToMove > 7) daysToMove = daysToMove - 7;
	}

	findDay = thisDay + daysToMove;

	if (findDay < 1) {  //happens if going back the num of days goes into the prev month
		findMonth = thisMonth - 1;
		if (findMonth < 0) findMonth = 11;
		findDay = thisDay + monthDaysArray[findMonth] + daysToMove;  //daysToMove is negative
	}
	else if (findDay > monthDaysArray[thisMonth]) {   //happens if going forward moves into the next month
		findMonth = findMonth + 1;
		if (findMonth > 11) findMonth = 0;
		findDay = thisDay - monthDaysArray[thisMonth] + daysToMove;  //daysToMove is positive
	}

	if (JustShowToday == 1 && thisDayOfWeek != 6 && thisDayOfWeek != 0){
		findMonth = thisMonth;
		findDay = thisDay;
	}

	findMonth = findMonth + 1;  //done for display purposes. javascript months are 0 based.
	(findMonth<10) ? findMonth = "0" + String(findMonth) : findMonth = String(findMonth);
	(findDay<10) ? findDay = "0" + String(findDay) : findDay = String(findDay);
//	return String(findYear) + findMonth + findDay;
	return findMonth + "-" + findDay;
}

