function switchOn(i) {
  document.getElementById("tdNavText"+i).className = "navtexton";
  document.getElementById("aNavText"+i).className = "navtexton";
  document.getElementById("gtNavText"+i).className = "navtexton";
  }
function switchOff(i) {
  document.getElementById("tdNavText"+i).className = "navtextoff";
  document.getElementById("aNavText"+i).className = "navtextoff";
  document.getElementById("gtNavText"+i).className = "navtextoff";
  }
function switchOnSearch(i) {
  document.getElementById("tdNavTextSearch"+i).className = "navtexton";
  document.getElementById("aNavTextSearch"+i).className = "navtexton";
  document.getElementById("gtNavTextSearch"+i).className = "navtexton";
  }
function switchOffSearch(i) {
  document.getElementById("tdNavTextSearch"+i).className = "navtextoff";
  document.getElementById("aNavTextSearch"+i).className = "navtextoff";
  document.getElementById("gtNavTextSearch"+i).className = "navtextoff";
  }

/*START 650 ExternalPartner *
 *
 * COUNTDOWN Core JavaScript
 * (c) 2006 VCommerce Inc.
 *
 * Author: Josh Pacheco <jpacheco@vcommerce.com>
 * Notes:  'Kick off' code for the countdown is located in module 650.
 */

// @name: startCountDownOpps
// @desc: Kicks off count down operations
function startCountDownOpps() {
	if (!document.getElementById || !document.createElement('test')) {
		// User is running an older browser
		return;
	} else if (!document.getElementById(strTargetDivId)) {
		// User has removed or renamed the div without matching

        // took out so page can be rendered without a div
        //alert('Please be sure to create a div with an id of: "' + strTargetDivId + '" somewhere in the page.');
		return;
	} else {
		// Pull target div
		objTimeDiv           = document.getElementById(strTargetDivId);
        objTimeDiv.innerHTML = "";
        objTimeDiv.className = strTimeDivClass;

        if (strSalePrefix) {
            // Append table to show text above countdown
            objTimeDiv  = buildCommonTable(objTimeDiv,strSalePrefix);
        }

        // Append table into target div, set core attributes if any
        objTimeDiv  = buildTimeTable(objTimeDiv);

        if (strSaleSuffux) {
            // Apend table to show text below countdown
            objTimeDiv  = buildCommonTable(objTimeDiv,strSaleSuffux);
        }


        // Calculate results of countdown for display
		calcResults();
	}
}

// Pointer used to hold timeout resource when started
intTimeoutId = 0;

// @name: calcResults
// @desc: Calculates differences in time
function calcResults() {
	// Calc difference of target date and current date, in milliseconds
	var intDiffStamp = intEndstamp - intCurstamp

	if (intCurstamp < intStartstamp) { // Countdown has not started yet
		// Clear time div untill countdown starts.
		objTimeDiv.innerHTML = '';
	} else if (intDiffStamp > 1) { // Countdown is active
		// Pull ammount of time left into a date object
		var objTimeLeft  = new Date(intEndstamp + intDiffStamp);

		// Create a collection of count down values
		var arrCountDown = new Array();
		// Calculate number of days left
		arrCountDown['dayfield']    = Math.round(intDiffStamp / intOneDay);
		// Hours left

		arrCountDown['hourfield'] = objTimeLeft.getHours();

		if (bolShowOverHours) {
			// Calc higher hours since a day intiger has been flag to not be displayed
			arrCountDown['hourfield'] += (arrCountDown['dayfield'] > 0) ? (24 * arrCountDown['dayfield']) : 0;
		}

		// Minutes left
		arrCountDown['minutefield'] = objTimeLeft.getMinutes();
		// Seconds left
		arrCountDown['secondfield'] = objTimeLeft.getSeconds();

		// Populate time table with countdown values
		populateCountDown(arrCountDown)

		// Add 1000 milliseconds (1 second) to current time stamp
		intCurstamp += 1000;

		// Recurse this function every 1000 milliseconds (1 second)
		intTimeoutId = setTimeout(function() { calcResults() }, 1000);
	} else { // Countdown is finished
		// Remove Countdown
        removeCountDown();
        if (intTimeoutId) {
			// Kill auto timeout if running
			clearTimeout(intTimeoutId);
		}
	}
}

// @name: populateTimeUp
// @desc: Populates time table with a times up message when countdown is complete
function populateTimeUp() {
	if (objTimeTable) {
		// Craeat a new row and cell, set any attributes
		var objRow  = objTimeTable.insertRow(0);
		var objCell = objRow.insertCell(0);
		objCell.className = 'timesup';

		// Populate cell with time up message
		objCell.innerHTML = strTimesUpMsg;
	}
}

// @name:  populateCountDown
// @param: arrCountDown    [array] collection of countdown values
// @desc:  Populates time table current countdown values
function populateCountDown(arrCountDown) {
	// Loop through collection
	for (var flgHash in arrCountDown) {
		if (arrFields[flgHash]) {
			// Pull coorisponding cell for current countdown data
			var objCell       = document.getElementById(flgHash);

			// Clear out any prior contents of cell
			objCell.innerHTML = '';

			// Padd a zero in front of minutes and seconds if the go to single digit
			var strZpad = '';
			if (arrCountDown[flgHash] < 10 && (flgHash == 'minutefield' || flgHash == 'secondfield')) {
				// Javascript has not sprintf method.  This hack solves the problem
				var strZpad = '0';
			}

			// Assign value of countdown data to cell and add a space
			objCell.innerHTML += "<span style='font-size: 1.1em'>"+ strZpad + arrCountDown[flgHash] +"</span>";
			objCell.innerHTML += "&nbsp;<br>";

			if (arrLabels[flgHash]) { // A label has been set for this countdown value
				// Append label to value in cell
				objCell.innerHTML += arrLabels[flgHash];

				//if (arrCountDown[flgHash] != 1) {
					// Pluralize label if value makes sense
					//objCell.innerHTML += 's';
				//}
			}
		}
	}
}

// @name:  buildTimeTable
// @param: objDiv    [object] countdown div object
// @desc:  Populates time table current countdown values
function buildTimeTable(objDiv) {
	// Create an instance of a table and set attributes as needed
	objTimeTable           = document.createElement('table');
	objTimeTable.border    = 0;
	objTimeTable.id        = 'time_table';
	objTimeTable.className = strTimeTableClass;

    // Add one row to this table
	var objRow = objTimeTable.insertRow(0);

	// Loop through user provided array of field
	var intCellCount = 0;
	for (var flgHash in arrFields) {
		// Add a new cell for each field to table and set attributes as needed
		var objCell       = objRow.insertCell(intCellCount);
		objCell.id        = flgHash;
		objCell.className = flgHash;
        objCell.width     = '33%';
        objCell.align     = 'center';
        intCellCount++;
	}

	// Append instance of table to countdown div
	objDiv.appendChild(objTimeTable);

	// Return countdown div back
	return objDiv;
}

// @name:  Build Common Table
// @param: objDiv      [object] countdown div object
// @param: strContents [string] contents of the table
// @desc:  Populates the name of the sale
arrCommonCount = new Array();
intCommonCount = 1;
function buildCommonTable(objDiv,strContents) {
    arrCommonCount[intCommonCount] = true;

    // Create an instance of a table and set attributes as needed
	objTbl           = document.createElement('table');
	objTbl.border    = 0;
	objTbl.id        = 'common_tables' + intCommonCount;
    intCommonCount++;
    objTbl.className = 'countdown_common_table';

    // Add one row to this table
	var objRow = objTbl.insertRow(0);

	// Add a new cell for each field to table and set attributes as needed
	var objCell       = objRow.insertCell(0);
    objCell.align     = 'center';
    objCell.className = '';
    objCell.innerHTML = strContents;

    // Append instance of table to countdown div
	objDiv.appendChild(objTbl);

	// Return countdown div back
	return objDiv;
}

// @name:  Remove Common Tables
// @desc:  Removes any common tables
function removeCountDown() {
    objTimeDiv.innerHTML = '';
}

// @name:  Verify Settings
// @desc:  Debug function used to verify user config values are set properly
function verifySettings() {
	if (isNaN(intStartstamp) || intStartstamp < intOneDay || !intStartstamp) {
		alert('Start Time evaluates to an invalid time stamp [' + intStartstamp + ']');
		bolConfigTest = false;
		return;
	}

	if (isNaN(intEndstamp) || intEndstamp < intOneDay || !intEndstamp) {
		alert('End Time evaluates to an invalid time stamp [' + intEndstamp + ']');
		bolConfigTest = false;
		return;
	}

	if (!strTargetDivId) {
		alert('Target div variable requires a name.');
		bolConfigTest = false;
		return;
	}

	if (!strTimesUpMsg) {
		//alert('No end message string has been supplied.');
		//bolConfigTest = false;
		//return;
	}

	if (arrFields.length < 0) {
		alert('At least one "Field of display" must be set in array.');
		bolConfigTest = false;
		return;
	}

	if (!strTimeDivClass) {
		alert('No div class name has been set');
		bolConfigTest = false;
		return;
	}
}

// @name:  Set Time Range Globals
// @desc:  Function used to encapsulate final global variable settings used in script
function setTimeRangeGlobals() {
	// Current date/time values (at load up)
	var objCurDate  = new Date();
	intCurstamp = Date.parse(objCurDate);

	// Total number of milliseconds in one day
	intOneDay = 1 * 24 * 60 * 60 * 1000;
	// Convert string data type of timestamps to numeric
	intStartstamp   = parseInt(intStartstamp); // User set start

	// Test that an end time stamp state
	if (intEndstamp < intOneDay || !intEndstamp) {
		// No end time stamp provided, set a default
		var intDuration = intOneDay * 2; // Default to 2 days
		intEndstamp = intStartstamp + intDuration;
	} else {
		// User provided an end timestamp, convert to numeric (to be safe)
		intEndstamp     = parseInt(intEndstamp); // User set end
	}
}

// @name:  Set Time Display Arrays
// @desc:  Function used to encapsulate final global array settings used in script
function setTimeDisplayArrays() {
	if (bolShowOverHours) {
		// Hours are set to show higher then 24 with no day
		arrFields['dayfield'] = false;
	}

	// Label values mapped to 'field' display cells
	arrLabels = new Array();
	arrLabels['dayfield']    = 'Day';
	arrLabels['hourfield']   = 'Hr.';
	arrLabels['minutefield'] = 'Min.';
	arrLabels['secondfield'] = 'Sec.';
}

// @name:  Set CSS Globals
// @desc:  Function used to encapsulate final global variable names for CSS
function setCSSGlobals() {
	// NOTE: The hash of each pair in 'arrFields' or 'arrLabels'
	//       corresponds to a class call for each of the individual
	//       cells that each time unit reside in.

	// Class names for div and table
	// (change to whatever you want to match a given style sheet)
	strTimeDivClass   = 'timediv';
	strTimeTableClass = 'timetable';
}

function convertTextDate(strDate) {
    objDate = new Date(strDate);
    return Date.parse(objDate);
}
/*END 650 ExternalPartner */

/*START 652 Daily Winner *
 *
 * Daily Winner Grid Core JavaScript
 * (c) 2006 VCommerce Inc.
 *
 * Author: Josh Pacheco <jpacheco@vcommerce.com>
 * Notes:  Core data structure for this located in 652-DailyWinner.jsp
 */

// @name: Set Daily Winner Stylees
// @desc: Loops through table and sets cell properties based on state
function setDailyWinnerStyles() {
    // Loop through 'table level' of array
    var intRows = 6;
    var intCols = 7;

    for (var y=0;y<intRows;y++) {
        var intY = y + 1;
        for (var x=0;x<intCols;x++) {
            var intX = x + 1;
            var objCell        = document.getElementById('c_' + intY + '_' + intX);
            var objCellContent = objCell.innerHTML;
            if (objCellContent.replace(/<[^>]*>/g,'').replace(/\s/g,'')) {
                objCell.style.backgroundColor = strFrontColor;
            }
        }
    }
}
/*END 652 Daily Winner */


