
function popUpWin(thisUrl, thisName, theseParams) {
  remote = open(thisUrl, thisName, theseParams);
}
var remote = null;
function help(f, n, w, h, t) {
  remote = window.open("/helppopup.htm?tab=" + t + "&file=" + f, n, 'width=' + w + ',height=' + h + ',resizable=yes,scrollbars=yes,status=yes');
  if (window.focus) {
    remote.focus()
  }
  if (remote != null) {
    if (remote.opener == null) remote.opener = self;
    window.name = 'store';
  }
}
function change_parent(url) {
  parent.opener.location = url;
  parent.window.close();
}
function forgotPassword(thisUrl, thisName, theseParams) {
  remote = open(thisUrl, thisName, theseParams);
}

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";
  }





function CountdownClock( self ) {
  this.self= self;

  this.load= function () {
    // HTML
    this.div= document.getElementById( this.divId );
    this.div.style.display= "none";
    // DATE & TIME
    if( typeof this.start == "undefined" || typeof this.end == "undefined" ) return;
    if( ! this.start.length || ! this.end.length ) return;
    this.startDate= this.makeAMorePerfectDate(this.start);
    this.endDate= this.makeAMorePerfectDate(this.end);
    this.startTime= this.startDate.getTime();
    this.endTime= this.endDate.getTime();
    this.time= Math.floor( (this.endTime - this.startTime)/1000 );
    if( isNaN(this.time) ) {
      return;
    }
    if( this.time < 0 ) return;
    // INTERVAL
    this.div.style.display="block";
    this.i= setInterval( this.self + ".animate()", 1000 );
  }

  this.makeAMorePerfectDate= function (date) {
    // Fix for IE, which doesn't like GMT-7:00, so replace with MST
    return new Date( date.replace( /(GMT[\-| ]\d+:\d+)/, "MST" ) );
  }

  this.animate= function () {
    this.time -= 1;
    if( this.time < 1 ) clearInterval( this.i );
    this.getTimeArr();
    this.div.innerHTML= this.prefix + "<table><tr><td>" + this.timeArr.join("</td><td>") + "</td></tr></table>";
  }
  
  this.getTimeArr= function () {
    this.timeArr= new Array();
    this.timeArr.push( this.getAllHours() + "<br />Hr." );
    this.timeArr.push( this.getMinutes() + "<br />Min." );
    this.timeArr.push( this.getSeconds() + "<br />Sec." );
  }

  this.getDays= function () {
    return Math.floor( this.time / (24*60*60) );
  }
  this.getAllHours= function () {
    return Math.floor( this.time / (60*60) );
  }
  this.getHours= function () {
    return Math.floor( ( this.time % (24*60*60) ) / (60*60) );
  }
  this.getMinutes= function () {
    return this.format( ( this.time % (60*60) ) / 60 );
  }
  this.getSeconds= function () {
    return this.format( this.time % 60 );
  }
  this.format= function (n) {
    n= Math.floor(n);
    return n>=10 ? n : "0" + n.toString();
  }

}




// Current Date Time for 'Madness' countdown clock
function manualDateTimeParse(d) {
  return d.replace( /(\w+) (\w+) (\d+) (\d+:\d+:\d+) (\w+[\-| ]?)(\d+:\d+) (\d+)/, "$2 $3, $7 $4" );
}

/*
 * 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(strCurDate) {
	// Current date/time values (at load up)
	var objCurDate  = new Date(strCurDate);
  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 */

/*
 * 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 */


