//global vars
var bFreeGift=false;
var firstLook=true;

//*************************************************************************************************
//START: Date Display & Progress Bar

var iGrowTo=0;
var iCurr=0;

function funcProg(inPerc){
	document.getElementById("progBarWait").style.display="none";
	document.getElementById("progBarContain").style.display="block";
	var objBarComplete = document.getElementById("progBarComplete");
	objBarComplete.style.display="block";
	objBarComplete.style.backgroundColor="#ff6600";//make it POP (PCH Orange). (#00cc00 bright green)
	var containerW=140;//width of the container div
	iGrowTo=parseInt(containerW*inPerc)//percent in px of the amount to grow
	funcGrow();
}

function funcGrow(){
	var objBarComplete = document.getElementById("progBarComplete");
	var inc=1;
	var speed=1;
	iCurr=iCurr+inc;
	objBarComplete.style.width=iCurr+"px";
	
	if(iCurr<iGrowTo){
		setTimeout(funcGrow,speed);//recurse...
	}else{
		objBarComplete.style.backgroundColor="#cccccc";//make it subtle
	}
}

function funcLoad_DateNProg(inPerc){
	getCalendarDate();
	funcProg(inPerc)//start the progress bar and set the % complete (1=100%, .5=50%, etc)
}

function getCalendarDate(){
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   
   var days = new Array(7);
   days[0]= "Sunday";
   days[1]= "Monday";
   days[2]= "Tuesday";
   days[3]= "Wednesday";
   days[4]= "Thursday";
   days[5]= "Friday";
   days[6]= "Saturday";
   
   var now         = new Date(SERVER_DATE);
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dayNumber = now.getDay();
   var dayName = days[dayNumber];
   
   var dateString = dayName + ', ' + monthname +' ' + monthday + ', ' + year;
   document.getElementById("displayDate").innerHTML=dateString;
}

//END: Date Display & Progress Bar
//*************************************************************************************************


//*************************************************************************************************
//START: Flash scripts

function getFlashVersion() {
	var dontKnow = false;
	var agent = navigator.userAgent.toLowerCase();

	// NS3+ and Opera3+ (support plugin array):  check for Flash plugin in plugin array
	if(navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if(typeof flashPlugin == 'object') {		 			
			if(flashPlugin.description.indexOf('10.') != -1) flashVersion = 10;
			else if(flashPlugin.description.indexOf('9.') != -1) flashVersion = 9;
			else if(flashPlugin.description.indexOf('8.') != -1) flashVersion = 8;
			else if(flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
			else if(flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if(flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if(flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if(flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
	}

	// IE4+ on Win32:  attempt to create an ActiveX object using VBScript
	else if(agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.10") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('flashVersion = 10 \n');		 			
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.9") end if \n');
		document.write('if flashVersion < 10 and IsObject(obFlash) then \n');
		document.write('flashVersion = 9 \n');		 					 			
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.8") end if \n');
		document.write('if flashVersion < 9 and IsObject(obFlash) then \n');
		document.write('flashVersion = 8 \n');		 					 			
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") end if \n');
		document.write('if flashVersion < 8 and IsObject(obFlash) then \n');
		document.write('flashVersion = 7 \n');		 			
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
		document.write('flashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
		document.write('flashVersion = 5 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
		document.write('if flashVersion < 5 and IsObject(obFlash) then \n');
		document.write('flashVersion = 4 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
		document.write('if flashVersion < 4 and IsObject(obFlash) then \n');
		document.write('flashVersion = 3 \n');
		document.write('end if');
		document.write('</scr' + 'ipt\> \n');
	}

	// WebTV 2.5 supports flash 3
	else if(agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if(agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = -1;
		dontKnow = true;
	}

	return flashVersion;
}
		
var flashVersion = getFlashVersion();

function flashOrAltImage(flashUrl,imageUrl,width,height,params, flashvars){ 
	if(flashVersion >= 6){
		fWriteFlash(flashUrl, width, height, false, flashvars);
	}else{
		document.write('<img src="' + imageUrl +'" width="' + width +'" height="' + height +'" border="0">');
	}
}	

function flashOrHTMLPrizeAmount(flashUrl,width,height){ 
	if(flashVersion >= 8){
		var flashvars = "prize=" + document.forms[0].prizeAmount.value;
		fWriteFlash(flashUrl, width, height, false, flashvars);
	}else{
		document.write('<div style="font-size:80px">' + document.forms[0].prizeAmount.value + '</div>');
	}
}	

function flashORHTMLHeader(flashUrl,width,height,params, flashvars){ 
	if(flashVersion >= 6){
		if(flashvars){					
			//get the info from the hidden fields...
			flashvars = "fn=" + document.getElementById("fName").value + "&ln=" + document.getElementById("lName").value;
		}
		fWriteFlash(flashUrl, width, height, params, flashvars);
	}else{
		document.write('<div style="font-size:80px;text-align:center;">' + document.getElementById("fn") + ' ' + document.getElementById("ln") + '</div>');
	}
}	

function fWriteFlash(flashUrl, width, height, params, flashvars){
	var parameters = (params)?getProfileData():"";
	parameters = (flashvars)?flashvars:"";

	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ');
	document.write('height="' + height +'" width="' + width + '">');
	document.write('<param name="movie" value="' + flashUrl + '">');
	document.write('<param name="flashvars" value="' + parameters + '">');
	document.write('<param name="wmode" value="transparent"><param name="quality" value="best"><param name="play" value="true"><param name="AllowScriptAccess" value="always">');
	document.write('<embed wmode="transparent" pluginspage="https://www.macromedia.com/go/getflashplayer" ');
	document.write('src="' + flashUrl + '" type="application/x-shockwave-flash" flashvars="' + parameters  + '" ');
	document.write('height="' + height +'" width="' + width + '" quality="best" AllowScriptAccess="always" play="true"></embed></object>');
}

//END: Flash scripts
//*************************************************************************************************

//*************************************************************************************************
//START: Ordering Validation & Devicies

var counter = 0;
function check(box, duplicate){	
	if (box.checked) counter++;
	else counter--;
	if (counter > 3){
		box.checked = false;
		counter--;
		alert ("You may order up to three items only.\nPlease review your selections.");
	}
	if (arguments.length == 2) document.frmOrder[duplicate].checked = box.checked;

	if(!document.getElementById("freegiftBottom")) return;
	
	if(!bFreeGift){
		if (firstLook){
			if (counter>0){
				document.getElementById("freegiftNoOrder").style.display="none";
				document.getElementById("freegiftBottom").style.display="block";
				document.getElementById("merchLegalCopy").style.display="block";
				document.getElementById("continue").style.display="block";
				
			}else{
				document.getElementById("freegiftNoOrder").style.display="block";
				document.getElementById("freegiftBottom").style.display="none";
				document.getElementById("merchLegalCopy").style.display="none";			
				document.getElementById("continue").style.display="none";
			}
		}
	}
}

//END: Ordering Validation & Devicies
//*************************************************************************************************

//*************************************************************************************************
//START: Popup functions

function popup(url, w, h){	
	var left = (screen.width - w) / 2;
	var top = (screen.height - h) / 2;
	features = 'width='+w+',height='+h+',top='+top+',left='+left+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no';
	newwindow=window.open(url,'newwin',features);
	newwindow.window.focus();
}

function popupScroll(url, w, h){	
	var left = (screen.width - w) / 2;
	var top = (screen.height - h) / 2;
	features = 'width='+w+',height='+h+',top='+top+',left='+left+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
	newwindow=window.open(url,'newwin',features);
	newwindow.window.focus();
}

function openit(sURL,w,h){
	newwindow=window.open(sURL,"newwin","scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=yes,status=no,width="+w+",height="+h+"");
	newwindow.window.focus();
}

function openit2(sURL,w,h){
	newwindow=window.open(sURL,"nextwin","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=yes,status=no,width="+w+",height="+h+"");
	newwindow.window.focus();
}

//END: Popup functions
//*************************************************************************************************

//*************************************************************************************************
//START: String Manipulation functions

function capitalize(string){
//capitalizes all words in a string	
	if (!string) return "";
	tmp = "";
	string = string.split(/\s+/); // split on any white space
	for (i=0; i<string.length; i++){
		tmp += ((i==0)?"":" ") + string[i].charAt(0).toUpperCase() + string[i].substring(1).toLowerCase();
	}
	return tmp;
}

function Trim(str){
//string editing function that trims any leading and trailing whitespace	
	return RTrim(LTrim(str));
}

function LTrim(str){
//string editing function that trims any leading whitespace	
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) {
	var j=0, i = s.length;
	while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
		j++;
	s = s.substring(j, i);
	}
	return s;
}

function RTrim(str){
//string editing function that trims any trailing whitespace
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
	var i = s.length - 1;       // Get length of string
	while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		i--;
	s = s.substring(0, i+1);
	}
	return s;
}

//END: String Manipulation functions
//*************************************************************************************************

//*************************************************************************************************
//START: "get functions" return value of HTML form fields/querystring

function getOption(pulldown){
// retrieve the value from a pulldown menu	
	return pulldown.options[pulldown.options.selectedIndex].value;
}

function getRadio(radio){
// retrieve the value associated with a radio button group
	for (i=0; i<radio.length; i++){
		if (radio[i].checked) return radio[i].value;
	}
	return "";
}

function getCheck(check){
// retrieve the value(s) associated with a check box (group)
	if (check.length == undefined) return check.value;
	values = [];
	for (i=0; i<check.length; i++){
		if (check[i].checked) values[values.length] = check[i].value;
	}
	return values;
}

function getURLValue(variable){
// parse a variable from the query string	
	queryString = document.location.search.substring(1);
	if (queryString == "") return "";
	pairs = queryString.split("&");
	for (i=0; i<pairs.length; i++){
		if (pairs[i].split("=")[0].toLowerCase() == variable.toLowerCase()) return unescape(pairs[i].split("=")[1]);
	}
	return "";
}

//END: "get functions" return value of HTML form fields/querystring
//*************************************************************************************************