/**********************************************************************
Element Swap

BY: Tim Giegel - Dick's Sporting Goods & Golf Galaxy
CREATED: 08-17-09
DESC: 
	- Displays elements based on a time frame verses manualy changing elements out.
	- This function degrades to non js browsers by not running.  !!Keep degraded elements in mind!!

UPDATED ON: 12-02-09
UPDATED BY: TMG
UPDATE: 
	- Updated js file name  
	- Added support for swap to be a time range - new function name
***********************************************************************/


/***********************************************************************
localTime()

- just call and it will return local EST time
***********************************************************************/
function localTime() {
    //current location
    d = new Date();
    // convert to msec, add local offset, and get UTC in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
    //use -5 to offset to EST
    nd = new Date(utc + (3600000*-5));
    // return time
    return (nd);
}
/***********************************************************************
elementSwap(str:on,[str:off],str:wrapperId,str:swapHtml)

- Will swap out the inner HTML of the "swapDivID" for the "swapHtml" on the "onDate" and will end (optionaly) on the offDate
- Date Format: mm-dd-yyyy-00:00:00
- swap if current time is (between on and off) or (equals on time) or (less then off time)
***********************************************************************/
function elementSwap(on,off,wrapperId,swapHtml) {
 	//current time
 	var now = localTime();
 	
 	//setup "on" time
 	var onYear = on.substring(6,10);
 	var onMonth = on.substring(0,2);
 	var onDay = on.substring(3,5);
 	var onHr = on.substring(11,13);
 	var onMin = on.substring(14,16);
 	var onSec = on.substring(17,19);
 	var onTime = new Date(onYear,onMonth-1,onDay,onHr,onMin,onSec);
 	
 	//setup "off" time
 	if(!off){var offTime = 0;} /*if off date is not set, set to 0*/
	else {
 		var offYear = off.substring(6,10);
 		var offMonth = off.substring(0,2);
 		var offDay = off.substring(3,5);
 		var offHr = off.substring(11,13);
 		var offMin = off.substring(14,16);
 		var offSec = off.substring(17,19);
 		var offTime = new Date(offYear,offMonth-1,offDay,offHr,offMin,offSec);		
	}
	
	/*TESTING
	document.write("<p>----start variables----</p>");
	document.write("now: "+now);
	document.write("<br>on: "+onTime);
	document.write("<br>off: "+offTime);
	document.write("<p>----end variables----</p>");
	*/
	
	//swap out html based on dates
	if(now >= onTime){
		//if offTime is 0 it was not set and element will swap forever
		if (now < offTime || offTime == 0){
			document.getElementById(wrapperId).innerHTML = swapHtml;
		}
	}
	
}