/*
Static Media Utilities - Create Media Selections function for Pull Down format
Creates media selections based on arguments passed from parent page

*******************************************************************************
Please do not edit or copy, if you have questions contact David Pedowitz
*******************************************************************************

REVISION HISTORY
12-17-01 Initial creation
04-10-02 Updated updateSpeed() method to include layer Id to fix NS4 issues with layers and nested objects

*/

var d = document;
var check;
var maxSpeed;

var type, speed, base;
var queryString = "?";

var speedText = new Array(
	"Choose Your Speed:",
	"56k Modem (slow)",
	"100k DSL (medium)",
	"300k Cable Modem or faster (fast)",
	"500k Broadband (fastest)"
);

var speedValue = new Array(
	"",
	"56000",
	"100000",
	"300000",
	"500000"
);

function updateSpeed(num, lyrId) {
	var formObj;
	if (d.layers && (typeof(lyrId) != "undefined")) {
		formObj = d[lyrId].document.selectionsForm;
	} else {
		formObj = d.selectionsForm;
	}
	if (num > 0 ) {
		type = formObj.type.options[num].value;
		//reset the speed Options object
		formObj.speed.length = 0;
		var speedInt = (parseInt(maxSpeed) > 300)?5:4;
		if (type == "windows") {
			//write all the speedOptions to the speed part of the form
			for (i = 0; i < speedInt; i++) {
				formObj.speed.options[i] = new Option(speedText[i], speedValue[i]);
			}
		} else {
			for (i = 0; i < 4; i++) {
				formObj.speed.options[i] = new Option(speedText[i], speedValue[i]);
			}
		}
		if (navigator.userAgent.indexOf("MSIE 4.") == -1) {
			formObj.speed.options[0] = new Option('Choose Your Speed:', '', true, true);
		}
		check = true;
	}
}

function createQuery(num) {
	if (check != null) {
		speed = speedValue[num];
		setWBOLMediaCookie(type, speed);
		location.href = base + "&type=" + type + "&speed=" + speed;
	} else {
		alert("Please Select a Player");
		d.selectionsForm.type.focus();
	}
}

function createSelections() {
//Initialize your variables you use later
	var selectionContent = "";
	var lyrId;
	var playPath;
	
	//Get the arguments passed to the function
	var args = createSelections.arguments;
	
	//If the first argment is a path to an html or jsp file then the selection Content is not writen in a layer
	if (args[0].indexOf(".html") != -1 || args[0].indexOf(".jsp") != -1) {
		lyrId = null;
		playPath = args[0];
		maxSpeed = args[1];
	} else {
		lyrId = args[0];
		playPath = args[1];
		maxSpeed = args[2];
	}
	
	//Get the base of the href based on parameters passed to the script
	var query = location.search;
	
	if (query.indexOf("settings") != -1) {
		query = query.substring(0, query.indexOf("&"));
	}

	base = playPath + query;
	
	selectionContent += "<form name=\"selectionsForm\">";
	if (lyrId == null) {
		selectionContent += "<select name=\"type\" onChange=\"updateSpeed(selectedIndex)\">";
	} else {
		selectionContent += "<select name=\"type\" onChange=\"updateSpeed(selectedIndex, '" + lyrId + "')\">";
	}
	selectionContent += "<option selected>Choose your player:</option>";
	selectionContent += "<option value=\"real\">Real Player</option>";
	selectionContent += "<option value=\"windows\">Windows Media Player</option>";
	selectionContent += "<option value=\"quicktime\">QuickTime</option>";
	selectionContent += "</select>";
	selectionContent += "<p>";
	selectionContent += "<select name=\"speed\" onChange=\"createQuery(selectedIndex)\">";
	selectionContent += "<option selected>Choose your speed:</option>";
	selectionContent += "<option></option>";
	selectionContent += "<option></option>";
	selectionContent += "<option></option>";
	selectionContent += "<option></option>";
	selectionContent += "</select>";
	selectionContent += "</form>";

	if (d.layers && lyrId != null) {
		d[lyrId].document.write(selectionContent)
	} else {
		d.write(selectionContent);
	}
}
