<!--

// *******************************************************************************
// The following code implements the onload() event for the day counter images
// for the Free John Thoburn Web site
//
// The sub functions are:
//		1) isDigit()
//		2) makeNumeric()
//		3) stringToInteger()
//		4) integerToString()
//
// The main function is:
//		1) yaImgChange()
//
// *******************************************************************************



// SUB FUNCTIONS



    // This function tests a string to see if it is equal to a numeric character
    function isDigit(strNumber)
	{
    	if ((strNumber == "0")	||(strNumber == "1")||(strNumber == "2")||(strNumber == "3")
								||(strNumber == "4")||(strNumber == "5")||(strNumber == "6")
								||(strNumber == "7")||(strNumber == "8")||(strNumber == "9"))
    	return true
		else return false
    }


    // This function converts any string into a new string containing only numeric characters (0-9)
    //    Precondition:    argument, strSSN, must be a string of characters
    //						(intLimit haults the process after a certain number of digits)
    //    Postcondition: returns a new string, strTempbSSN, which contains only numeric chars.
    function makeNumeric(strSSN, intLimit)
    {
		var strTempSSN = ""	// This is a temporary variable
		var strTempbSSN = ""	// This stores the new string
		var intCount = 0

		// This loop iterates through the old string
		for (var i = 0; i < strSSN.length; i++)
    	{
			next = strSSN.charAt(i) // Read a character
			if ((isDigit(next)) && (intCount < intLimit))             // If the character is a number, store it in the new string
			{
			strTempSSN = strTempbSSN
			strTempbSSN = strTempSSN + next
			intCount++
			}
    	} 
		return strTempbSSN
    }


    // This function converts a string  made up of numeric characters (0-9) into a integer
    //    Precondition:   argument, strnumber, must be a string of numeric charagers
    //    Postcondition: returns a the numeric value of the string
    function stringToInteger(strNumber)
    {
		var intNumber = 0  // Stores the number to be returned
		var intDigit = 1   // Stores the current digit power (1,10,100,1000,...)
		var intCount = strNumber.length - 1
		// This loop iterates through the string and adds the numbers
		for (var i = intCount; i >= 0; i--)
		{
			next = strNumber.charAt(i) // Read a character
			if (next == "0") intNext = 0
			else if (next == "1") intNext = 1 * intDigit
			else if (next == "2") intNext = 2 * intDigit
			else if (next == "3") intNext = 3 * intDigit
			else if (next == "4") intNext = 4 * intDigit
			else if (next == "5") intNext = 5 * intDigit
			else if (next == "6") intNext = 6 * intDigit
			else if (next == "7") intNext = 7 * intDigit
			else if (next == "8") intNext = 8 * intDigit
			else if (next == "9") intNext = 9 * intDigit
			intNumber = intNumber + intNext
			intDigit = intDigit * 10
		}
		return intNumber
	}


    // This function converts an integer into a string  made up of numeric characters (0-9)
    function integerToString(intNumber)
    {
		if (intNumber == 0) intNumber = ""
		return intNumber
    }



// MAIN FUNCTIONS


	// This function calls the above sub-functions in order to calculate the number of days
	// and update the document images accordingly.
	function yaImgChange()
	{
		var intPrevious = 12							// February's Day Count
				
		today = new Date()								// Get the date
				
		var strDate = today.toString()
		var strTemp = ""								// Temporary variable
		var strCount = ""								// Stores the count of days
		var intDate = 0
		var intTens = 0
		var intOnes = 0
				
		strTemp = makeNumeric(strDate, 2)				// Cut out all but the days of the month
		intDate = stringToInteger(strTemp)
				
		intDate = intDate + intPrevious					// Add previous month's days to current month's days

		// next three lines convert the integer to a valid string
		strCount = integerToString(intDate)
		document.forms[0].hiddenString.value = strCount
		var strCount = document.forms[0].hiddenString.value

		// Get the tens and ones digits
		intTens = strCount.charAt(0)					// Read first digit
		intOnes = strCount.charAt(1)					// Read second digit


		// update the tens digit image
		if (intTens == 0) imgSrc ='images/counter/counter_01.gif'
		else if (intTens == 1) imgSrc ='images/counter/counter_02.gif'
		else if (intTens == 2) imgSrc ='images/counter/counter_03.gif'
		else if (intTens == 3) imgSrc ='images/counter/counter_04.gif'
		else if (intTens == 4) imgSrc ='images/counter/counter_05.gif'
		else if (intTens == 5) imgSrc ='images/counter/counter_06.gif'
		else if (intTens == 6) imgSrc ='images/counter/counter_07.gif'
		else if (intTens == 7) imgSrc ='images/counter/counter_08.gif'
		else if (intTens == 8) imgSrc ='images/counter/counter_09.gif'
		else if (intTens == 9) imgSrc ='images/counter/counter_10.gif'
		document.digit10.src = imgSrc;	

		// update the ones digit image
		if (intOnes == 0) imgSrc ='images/counter/counter_01.gif'
		else if (intOnes == 1) imgSrc ='images/counter/counter_02.gif'
		else if (intOnes == 2) imgSrc ='images/counter/counter_03.gif'
		else if (intOnes == 3) imgSrc ='images/counter/counter_04.gif'
		else if (intOnes == 4) imgSrc ='images/counter/counter_05.gif'
		else if (intOnes == 5) imgSrc ='images/counter/counter_06.gif'
		else if (intOnes == 6) imgSrc ='images/counter/counter_07.gif'
		else if (intOnes == 7) imgSrc ='images/counter/counter_08.gif'
		else if (intOnes == 8) imgSrc ='images/counter/counter_09.gif'
		else if (intOnes == 9) imgSrc ='images/counter/counter_10.gif'
		document.digit1.src = imgSrc;

		document.counter_text.src = 'images/counter/counter_11.gif'
	}


// **********************************************************************
// End of onload() event procedures for image-based counter
// **********************************************************************



-->