﻿// JScript File

// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;

// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

//var numTips = "09"; // Total number of flash tips you can pledge on.
//var currentTip = "Zip"; // First tip loaded
var flashTimer = 0;
var browserName = navigator.appName;
//var helpOpen = false;

// Handle all the FSCommand messages in a Flash movie.
//function flashTip_DoFSCommand(command, args)
//{
//	if(command == "incrimentScore")
//	{
//		addScore(args);
//	}
//	else if(command == "decrimentScore")
//	{
//		subtractScore(args);
//	}
//}

//// Hook for Internet Explorer.
//if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
//	document.write('<script language=\"VBScript\"\>\n');
//	document.write('On Error Resume Next\n');
//	document.write('Sub flashTip_FSCommand(ByVal command, ByVal args)\n');
//	document.write('	Call flashTip_DoFSCommand(command, args)\n');
//	document.write('End Sub\n');
//	document.write('<\/script\>\n');
//}

//function initTipValues(totalTips)
//{
//	// Initializes tipValues hidden field with tip number and false values
//	var tipValues = document.getElementById("tipValues");
//	
//	for(i = 0; i <= totalTips - 1; i++)
//	{
//		if(i != 0)
//		{
//			tipValues.value += ";";
//		}
//		
//		tipValues.value += "0" + (parseFloat(i) + 1).toString() + ",false";
//	}
//	
//	var mcHelp = window.document.scoreHelp;

//	if(mcHelp != null && InternetExplorer)
//	{
//		mcHelp.SetVariable("helpOpen", "false");
//	}
//	
//}

//function addScore(toAdd)
//{
//	// For setting hidden field values
//	var currentTipValue = currentTip + ",true";
//	var newTipValue = currentTip + ",false";
//	var tipOffset = document.getElementById("tipOffset");
//	var tipValues = document.getElementById("tipValues");
//	tipOffset.value = parseInt(tipOffset.value) - parseInt(toAdd);
//	tipValues.value = tipValues.value.replace(currentTipValue, newTipValue);
//	
//	// Used for changing HTML score. May not be needed
//	var scoreNode = window.document.getElementById("score");
//	var oldScore = scoreNode.firstChild.nodeValue;
//	var newScore = parseFloat(oldScore) + parseFloat(toAdd);
//	scoreNode.replaceChild(document.createTextNode(newScore.toString()), scoreNode.firstChild);
//}

//function subtractScore(toSubtract)
//{
//	// For setting hidden field values
//	var currentTipValue = currentTip + ",false";
//	var newTipValue = currentTip + ",true";
//	var tipOffset = document.getElementById("tipOffset");
//	var tipValues = document.getElementById("tipValues");
//	tipOffset.value = parseInt(tipOffset.value) + parseInt(toSubtract);
//	tipValues.value = tipValues.value.replace(currentTipValue, newTipValue);
//	
//	// Used for changing HTML score. May not be needed
//	var scoreNode = window.document.getElementById("score");
//	var oldScore = scoreNode.firstChild.nodeValue;
//	var newScore = parseFloat(oldScore) - parseFloat(toSubtract);
//	scoreNode.replaceChild(document.createTextNode(newScore.toString()), scoreNode.firstChild);
//}


function killTimer(timerID)
{
	clearTimeout(timerID);
}

//sets a timeout for closing the sub menu
function fetchTip(tipName, finalScore, carbonTons)
{
	flashTimer = setTimeout(function(){swapTip(tipName, finalScore, carbonTons);}, 100);
	return flashTimer;
}



// Call this function to load a tip passing the tip name.
// Only the last two need a finalScore, and carbonTons passed in. 
// On all others pass in 0's for these values.

// tip names are below in order:

// Zip
// 01
// 02
// 03
// 04
// 05 - this tip only loads if user has 3 or 4 cars
// 06
// 07
// 08
// Commit
// Account - pass in a final score and carbon tons to be displayed
// Thankyou - pass in a final score and carbon tons to be displayed
function swapTip(tipName, finalScore, carbonTons)
{
	var mc = window.document.flashTip;
	//var mcHelp = window.document.scoreHelp;
	//var isOpen = mcHelp.GetVariable("helpOpen");
	 
	//if(isOpen == "true")
	//{
		//mcHelp.SetVariable("closeHelp", "true");
		//mcHelp.GotoFrame(1);
	//}
	//window.alert(mc.GotoFrame(1));
	//window.alert(mc.TGetProperty('/', 12));
	if(mc.PercentLoaded() != 100)
	{
		fetchTip(tipName, finalScore, carbonTons);
	}
	else
	{
		//currentTip = tipName;
		mc.SetVariable("tipName", "tip" + tipName);
	//	mc.SetVariable("finalScore", finalScore);
	//	mc.SetVariable("carbonTons", carbonTons);
		//window.alert(mc.PercentLoaded());
		mc.GotoFrame(1);
	}
	killTimer(flashTimer);
}

function popupWin(page, name, w, h, scroll)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var winprop  = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';
	win = window.open(page, name, winprop);
	win.focus();
	//return win;
}

function PageQuery(q)
{
	if(q.length > 1)
	{
		this.q = q.substring(1, q.length);
	}
	else 
	{
		this.q = null;
	}
	
	this.keyValuePairs = new Array();
	
	if(q)
	{
		for(var i=0; i < this.q.split("&").length; i++)
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	
	this.getKeyValuePairs = function()
	{
		return this.keyValuePairs;
	}
	
	this.getValue = function(s)
	{
		for(var j=0; j < this.keyValuePairs.length; j++)
		{
			if(this.keyValuePairs[j].split("=")[0] == s)
			{
				return this.keyValuePairs[j].split("=")[1];
			}
		}
		return false;
	}
	
	this.getParameters = function()
	{
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++)
		{
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		
		return a;
	}
	
	this.getLength = function()
	{
		return this.keyValuePairs.length;
	} 
}

function queryString(key)
{
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

function displayItem(key)
{
	if(queryString(key)=='false') 
	{
		document.write("you didn't enter a ?name=value querystring item.");
	}
	else
	{
		document.write(queryString(key));
	}
}