function setRequired(form, l) 
{
	for (var i = 0; i < form.length; i++) 
	{
		// assumes is optional
		form.elements[i].optional = true;
		// if in the list, reset back to true
		for (var j = 0; j < l.length; j++) 
		{
			if (form.elements[i].name == l[j]) 
			{
				form.elements[i].optional = false;
				continue;
			}
		}
	}
}		

function checkRequiredFields(form, formlist, numlist) 
{
	var msg;
	var error = "";
	var breakout = false;

	for(var f = 0; f < form.length; f++) 
	{
		for (var n = 0; n < numlist.length; n++)
		{
			if (form.elements[f].name == numlist[n])
			{
				if (!isBlank(form[f].value))
				{
					if (isNaN(parseInt(form[f].value)) )
					{
						error += "Field " + numlist[n] + " must be a number.\n";
					}
				}
			}
		}
	}	

	// Set the required fields to be of type required.
	setRequired(form, formlist);

	// Check to see all required fields are entered.
	for (var i = 0; i < form.length; i++) 
	{
		var e = form.elements[i];
		if ((e.type == "radio" || e.type == "checkbox") && !e.optional)  
		{
			var e_name = e.name;  // stores the name to check.
			var anychecked = false;
			// Check all values in this set with the same name.  Increment counter.
			while ((e.name == e_name) && (anychecked == false)) 
			{
				if (e.checked) 
				{
					anychecked = true;
				}
				e = form.elements[++i];
			}
			if (anychecked == false) {
				// Nothing was selected.
				error += "Field " + e_name + " does not have a selected value.\n";
			}
		}
				
		if (((e.type == "text") || (e.type == "textarea")) && !e.optional) 
		{
			if ((e.value == null)  || (e.value == "") || isBlank(e.value)) 
			{
				error += "Field " + e.name + " was not filled in.\n";
			}
		}
	}

	
	if (!error) 
	{
		return true;
	}
	
	msg = "The form was not submitted because of the following error(s).\n";
	msg += "Please correct these error(s) and re-submit.\n\n";
	msg += error;
	alert(msg);
	return false;
}
	
function confirmClearForm(theForm) 
{
	var msg = "Are you sure you want to clear the entire form?";
	if (confirm(msg)) 
	{
		theForm.reset();
	}
}

function isBlank(s) 
{	
	for (var i = 0; i < s.length; i++) 
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) 
		{
			return false;
		}
	}
	return true;
}

function clearListBoxes(theForm) 
{
	var urlselect = eval("document." + theForm.name + "." + "mediaUrl");
	if (urlselect != null) 
	{
		var urlListLength = urlselect.length;
		for (count=0; count < urlListLength; count++) 
		{
			urlselect.selectedIndex = 0;
		}
	}
}

function checkLength(form, tname, len)
{
	for(var f = 0; f < form.length; f++)
	{
		if (form.elements[f].name == tname)
		{
			var s = form.elements[f].value;
			if (s.length > len)
			{
				alert("Field Input Error:\nThe maximum number of characters allowed in this field is " + 
				len + " characters.\n" + "Please remove " + (s.length - len) + " characters.");
			}
		}
	}
}

function checkIfValidUrl(textbox) 
{
	var urlToTest = new String(textbox.value);
	if (urlToTest == "")
	{
		return;
	}
	var indexOfProtocolEnd = urlToTest.indexOf("://");
	var protocol = "";
	if (indexOfProtocolEnd > 0) 
	{
		protocol = urlToTest.substring(0, indexOfProtocolEnd);
	}
	// Check against all used protocols, return true if no errors
	if (protocol == "ftp" || protocol == "http" || protocol == "https") 
	{
		return;
	}
	var msg = "That does not appear to be a valid URL entry.";
	alert(msg);
}

function addRelatedInfo(theForm, text, val)
{
	var error = false;
	var index = eval("theForm.sel" + text + ".options.length");
	if (index == null)
	{
		index = 0;
	}	
	var textInput = eval("theForm." + text + "Input");
	var valInput = eval("theForm." + val + "Input");
	if (textInput.value == "" || valInput.value == "")
	{
		alert("Please enter information in both fields and try again.");
	    error = true;
	}	
	
	if (error == false)
	{	
   	   var option = new Option(textInput.value, textInput.value);
       eval("theForm.sel" + text + ".options[" + index + "] = option");
	   var valOption = new Option(valInput.value, valInput.value);
       eval("theForm.sel" + val + ".options[" + index + "] = valOption");
	   textInput.value = "";
	   valInput.value = "";
	}
	addToHiddenField(theForm, text, index);
	addToHiddenField(theForm, val, index);
}

function removeRelatedInfo(theForm, text, val)
{
	var index = eval("theForm.sel" + text + ".selectedIndex");
    eval("theForm.sel" + text + ".options["+index+"] = null");
	var valIndex = eval("theForm.sel" + val + ".selectedIndex");
    eval("theForm.sel" + val + ".options["+valIndex+"] = null");
	var textInput = eval("theForm." + text + "Input");
	var valInput = eval("theForm." + val + "Input");
	textInput.value = "";
	valInput.value = "";
	removeFromHiddenField(theForm, text, index);
	removeFromHiddenField(theForm, val, index)
}

function selectValList(theForm, text, val)
{
	var index = eval("theForm.sel" + text + ".selectedIndex");
	eval("theForm.sel" + val + ".options["+index+"].selected=true");
	var textInput = eval("theForm." + text + "Input");
	var valInput = eval("theForm." + val + "Input");
	textInput.value = eval("theForm.sel" + text + "["+index+"].text");
	valInput.value = eval("theForm.sel" + val + "["+index+"].text");
}

function selectTextList(theForm, text, val)
{
	var index = eval("theForm.sel" + val + ".selectedIndex");
	eval("theForm.sel" + text + ".options["+index+"].selected=true");
	var textInput = eval("theForm." + text + "Input");
	var valInput = eval("theForm." + val + "Input");
	textInput.value = eval("theForm.sel" + text + "["+index+"].text");
	valInput.value = eval("theForm.sel" + val + "["+index+"].text");
}

function changeRelatedInfo(theForm, text, val)
{
	addRelatedInfo(theForm, text, val);
	removeRelatedInfo(theForm, text, val);
}

function addToHiddenField(theForm, text, index)
{
	eval("theForm." + text + ".value += theForm.sel" + text + ".options["+index+"].text");
	var hdnField = eval("theForm." + text);
	hdnField.value += ";";
}

function removeFromHiddenField(theForm, text, index)
{
    var s = eval("theForm." + text + ".value");
	a = s.split(";");
	a[index] = 0;
	var output = "";
	for(var i = 0; i < a.length - 1; i++)
	{
		if (a[i] != 0)
		{
		    output += a[i] + ";";
		}
	}
	eval("theForm." + text + ".value = output");
}

function loadSelectList(theForm, text, val, textString, valString)
{
    if(textString == " ")
	{
	    textString = "";
	}
	if(valString == " ")
	{
	    valString = "";
	}
    if(textString.length > 0 && textString.indexOf(";", textString.length-1) == -1)
	{
	    textString = textString + ";";
	}
	if(valString.length > 0 && valString.indexOf(";", valString.length-1) == -1)
	{
	    valString = valString + ";";
	}
	t = new Array();
	v = new Array();
	t = textString.split(";");
	v = valString.split(";");
	for(var i = 0; i < (t.length - 1); i++)
	{
       var option = new Option(t[i], t[i]);
       eval("theForm.sel" + text + ".options[" + i + "] = option");
	   var valOption = new Option(v[i], v[i]);
       eval("theForm.sel" + val + ".options[" + i + "] = valOption");
	}
}

function clearMediaURLs(theForm)
{
    for(var i = 1; i <= 10; i++)
	{
		eval("theForm.mediaFileName" + i + ".value = \"\"");
		eval("theForm.mediaURL" + i + ".selectedIndex = " + 0);
		eval("theForm.streamingSource" + i + ".value = \"\"");
		eval("theForm.contentSource" + i + ".value = \"\"");
		eval("theForm.frameSizeHeight" + i + ".value = \"\"");
		eval("theForm.frameSizeWidth" + i + ".value = \"\"");
	}
}

function winOpen(page,w,h,name)
{          
  var params = "width="+w+",height="+h+",toolbar=yes,resizable=yes,status=no,location=no,directories=no,scrollbars=yes"
  window.open(page, name, params) ;
}

function clearSpeeds(theForm)
{
    if(theForm.speedAll.checked)
	{
	    theForm.speedRM56.checked = false;
		theForm.speedRM100.checked = false;
		theForm.speedRM300.checked = false;
		theForm.speedRM500.checked = false;
		theForm.speedWM56.checked = false;
		theForm.speedWM100.checked = false;
		theForm.speedWM300.checked = false;
		theForm.speedWM500.checked = false;
	}
}

function clearAllSpeed(theForm)
{
    theForm.speedAll.checked = false;
}

function disableSpeeds(theForm)
{
    if(theForm.quickPickMediaURL.value == 2)
	{
	    theForm.speedRM500.disabled = true;
		theForm.speedRM500.checked = false;
		theForm.speedWM500.disabled = true;
		theForm.speedWM500.checked = false;
	}
	else
	{
	    theForm.speedRM500.disabled = false;
		theForm.speedWM500.disabled = false;
	}
}

function fillMediaURLs(theForm)
{
    var file = theForm.quickPickFile.value;
    var mediaURL = theForm.quickPickMediaURL.value;
    var stream = theForm.quickPickStream.value;
    var content = theForm.quickPickContent.value;
    var height = theForm.quickPickHeight.value;
    var width = theForm.quickPickWidth.value;
    
    var aspectRatio = theForm.aspectRatio.value;
 
    <!--- if no item was selected in the quick pick drop down clear all fields --->
    if(mediaURL == 0)
    {
        file = "";
        stream = "";
        content = "";
        height = "";
        width = "";
        theForm.quickPickFile.value = "";
        theForm.quickPickHeight.value = "";
        theForm.quickPickWidth.value = "";
        theForm.quickPickStream.value = "";
        theForm.quickPickContent.value = "";
    }
	<!--- globix selected --->
    else if(mediaURL == 1 || mediaURL == 1.5)
    {
        if(stream == "")
            stream = "Globix";
        if(content == "")
		    if(mediaURL == 1.5)
			{
			    content = "AP";
			}
			else
			{
                content = "Firstlook";
			}
    }
	<!--- video pipeline selected --->
    else if(mediaURL == 2)
    {
	    mediaURL = 5;
        aspectRatio = 0;
        if(stream == "")
            stream = "Video Pipeline";
        if(content == "")
            content = "Video Pipeline";
    }

	<!--- add the file extensions --->
    for (var i = 1; i < 11; i++)
    {
        file = theForm.quickPickFile.value;
        if(mediaURL == 0)
            file = "";
            
        if(mediaURL > 0 && mediaURL < 5)
        {
            if(i == 2)
                file = file + "_56.ram";
            else if(i == 3)
                file = file + "_100.ram";
            else if(i == 4)
                file = file + "_300.ram";
            else if(i == 5)
                file = file + "_500.ram";
            else if(i == 7)
                file = file + "_56.asx";
            else if(i == 8)
                file = file + "_100.asx";
            else if(i == 9)
                file = file + "_300.asx";
            else if(i == 10)
                file = file + "_500.asx";
        }   

		<!--- if the appropriate checkbox is selected, fill it --->
		if((i == 2) && theForm.speedRM56.checked)
		{
		    eval("theForm.mediaFileName2.value = file");
	        eval("theForm.mediaURL2.selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource2.value = stream");
	        eval("theForm.contentSource2.value = content");
	        eval("theForm.frameSizeHeight2.value = height");
	        eval("theForm.frameSizeWidth2.value = width");
		}
		else if((i == 3) && theForm.speedRM100.checked)
		{
		    eval("theForm.mediaFileName3.value = file");
	        eval("theForm.mediaURL3.selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource3.value = stream");
	        eval("theForm.contentSource3.value = content");
	        eval("theForm.frameSizeHeight3.value = height");
	        eval("theForm.frameSizeWidth3.value = width");
		}
		else if((i == 4) && theForm.speedRM300.checked)
		{
		    eval("theForm.mediaFileName4.value = file");
	        eval("theForm.mediaURL4.selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource4.value = stream");
	        eval("theForm.contentSource4.value = content");
	        eval("theForm.frameSizeHeight4.value = height");
	        eval("theForm.frameSizeWidth4.value = width");
		}
		else if((i == 5) && theForm.speedRM500.checked)
		{
		    eval("theForm.mediaFileName5.value = file");
	        eval("theForm.mediaURL5.selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource5.value = stream");
	        eval("theForm.contentSource5.value = content");
	        eval("theForm.frameSizeHeight5.value = height");
	        eval("theForm.frameSizeWidth5.value = width");
		}
		else if((i == 7) && theForm.speedWM56.checked)
		{
		    eval("theForm.mediaFileName7.value = file");
	        eval("theForm.mediaURL7.selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource7.value = stream");
	        eval("theForm.contentSource7.value = content");
	        eval("theForm.frameSizeHeight7.value = height");
	        eval("theForm.frameSizeWidth7.value = width");
		}
		else if((i == 8) && theForm.speedWM100.checked)
		{
		    eval("theForm.mediaFileName8.value = file");
	        eval("theForm.mediaURL8.selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource8.value = stream");
	        eval("theForm.contentSource8.value = content");
	        eval("theForm.frameSizeHeight8.value = height");
	        eval("theForm.frameSizeWidth8.value = width");
		}
		else if((i == 9) && theForm.speedWM300.checked)
		{
		    eval("theForm.mediaFileName9.value = file");
	        eval("theForm.mediaURL9.selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource9.value = stream");
	        eval("theForm.contentSource9.value = content");
	        eval("theForm.frameSizeHeight9.value = height");
	        eval("theForm.frameSizeWidth9.value = width");
		}
		else if((i == 10) && theForm.speedWM500.checked)
		{
		    eval("theForm.mediaFileName10.value = file");
	        eval("theForm.mediaURL10.selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource10.value = stream");
	        eval("theForm.contentSource10.value = content");
	        eval("theForm.frameSizeHeight10.value = height");
	        eval("theForm.frameSizeWidth10.value = width");
		}
		else if((i != 1 || i != 6) && theForm.speedAll.checked)
		{
	        eval("theForm.mediaFileName" + i + ".value = file");
	        eval("theForm.mediaURL" + i + ".selectedIndex = " + mediaURL);
	        eval("theForm.streamingSource" + i + ".value = stream");
	        eval("theForm.contentSource" + i + ".value = content");
	        eval("theForm.frameSizeHeight" + i + ".value = height");
	        eval("theForm.frameSizeWidth" + i + ".value = width");
		}
		
		<!--- clear out the 28k fields always --->
		theForm.mediaFileName1.value = "";
		eval("theForm.mediaURL1.selectedIndex = 0");
		theForm.streamingSource1.value = "";
		theForm.contentSource1.value = "";
		theForm.frameSizeHeight1.value =  "";
		theForm.frameSizeWidth1.value = "";
		
		theForm.mediaFileName6.value = "";
		eval("theForm.mediaURL6.selectedIndex = 0");
		theForm.streamingSource6.value = "";
		theForm.contentSource6.value = "";
		theForm.frameSizeHeight6.value =  "";
		theForm.frameSizeWidth6.value = "";
    }
    
    if(aspectRatio != 0)
    {
        fillAspectRatio(theForm, aspectRatio);
    }

	<!--- this is video pipeline, so clear the 500k fields --->
    if(mediaURL == 5)
    {
        theForm.mediaURL5.selectedIndex = 0;
        theForm.mediaURL10.selectedIndex = 0;
        theForm.mediaFileName5.value = "";
        theForm.mediaFileName10.value = "";
        theForm.streamingSource5.value = "";
        theForm.streamingSource10.value = "";
        theForm.contentSource5.value= "";
        theForm.contentSource10.value = "";
        theForm.frameSizeHeight5.value = "";
        theForm.frameSizeHeight10.value = "";
        theForm.frameSizeWidth5.value = "";
        theForm.frameSizeWidth10.value = "";
    }
}

function fillAspectRatio(theForm, aspectRatio)
{
    if(aspectRatio == 1)
    {
        theForm.frameSizeHeight2.value = 136;
        theForm.frameSizeWidth2.value = 176;
        theForm.frameSizeHeight3.value = 180;
        theForm.frameSizeWidth3.value = 240;
        theForm.frameSizeHeight4.value = 240;
        theForm.frameSizeWidth4.value = 320;
        theForm.frameSizeHeight5.value = 384;
        theForm.frameSizeWidth5.value = 512;
		theForm.frameSizeHeight7.value = 144;
        theForm.frameSizeWidth7.value = 176;
        theForm.frameSizeHeight8.value = 160;
        theForm.frameSizeWidth8.value = 208;
        theForm.frameSizeHeight9.value = 240;
        theForm.frameSizeWidth9.value = 320;
        theForm.frameSizeHeight10.value = 384;
        theForm.frameSizeWidth10.value = 512;
    }
    else if(aspectRatio == 2)
    {
        theForm.frameSizeHeight2.value = 124;
        theForm.frameSizeWidth2.value = 192;
        theForm.frameSizeHeight3.value = 164;
        theForm.frameSizeWidth3.value = 256;
        theForm.frameSizeHeight4.value = 216;
        theForm.frameSizeWidth4.value = 336;
        theForm.frameSizeHeight5.value = 352;
        theForm.frameSizeWidth5.value = 528;
		theForm.frameSizeHeight7.value = 128;
        theForm.frameSizeWidth7.value = 192;
        theForm.frameSizeHeight8.value = 144;
        theForm.frameSizeWidth8.value = 224;
        theForm.frameSizeHeight9.value = 224
        theForm.frameSizeWidth9.value = 336;
        theForm.frameSizeHeight10.value = 352;
        theForm.frameSizeWidth10.value = 528;
    }
    else if(aspectRatio == 3)
    {
        theForm.frameSizeHeight2.value = 120;
        theForm.frameSizeWidth2.value = 200;
        theForm.frameSizeHeight3.value = 160;
        theForm.frameSizeWidth3.value = 264;
        theForm.frameSizeHeight4.value = 208;
        theForm.frameSizeWidth4.value = 352;
        theForm.frameSizeHeight5.value = 336;
        theForm.frameSizeWidth5.value = 544;
		theForm.frameSizeHeight7.value = 112;
        theForm.frameSizeWidth7.value = 192;
        theForm.frameSizeHeight8.value = 144;
        theForm.frameSizeWidth8.value = 240;
        theForm.frameSizeHeight9.value = 208;
        theForm.frameSizeWidth9.value = 352;
        theForm.frameSizeHeight10.value = 336;
        theForm.frameSizeWidth10.value = 544;
    }
    else if(aspectRatio == 4)
    {
        theForm.frameSizeHeight2.value = 112;
        theForm.frameSizeWidth2.value = 208;
        theForm.frameSizeHeight3.value = 152;
        theForm.frameSizeWidth3.value = 280;
        theForm.frameSizeHeight4.value = 200;
        theForm.frameSizeWidth4.value = 372;
        theForm.frameSizeHeight5.value = 304;
        theForm.frameSizeWidth5.value = 560;
		theForm.frameSizeHeight7.value = 112;
        theForm.frameSizeWidth7.value = 208;
        theForm.frameSizeHeight8.value = 128;
        theForm.frameSizeWidth8.value = 240;
        theForm.frameSizeHeight9.value = 192;
        theForm.frameSizeWidth9.value = 352;
        theForm.frameSizeHeight10.value = 304;
        theForm.frameSizeWidth10.value = 560;
    }
    else if(aspectRatio == 5)
    {
        theForm.frameSizeHeight2.value = 96;
        theForm.frameSizeWidth2.value = 220;
        theForm.frameSizeHeight3.value = 132;
        theForm.frameSizeWidth3.value = 308;
        theForm.frameSizeHeight4.value = 176;
        theForm.frameSizeWidth4.value = 416;
        theForm.frameSizeHeight5.value = 256;
        theForm.frameSizeWidth5.value = 608;
		theForm.frameSizeHeight7.value = 96;
        theForm.frameSizeWidth7.value = 224;
        theForm.frameSizeHeight8.value = 112;
        theForm.frameSizeWidth8.value = 272;
        theForm.frameSizeHeight9.value = 176;
        theForm.frameSizeWidth9.value = 416;
        theForm.frameSizeHeight10.value = 256;
        theForm.frameSizeWidth10.value = 608;
    }
    else{}
	
	<!--- i'm cheating here - clear out fields that don't have appropriate checkboxes checked --->
	if(!(theForm.speedRM56.checked) && !(theForm.speedAll.checked))
	{
	    theForm.frameSizeHeight2.value = "";
        theForm.frameSizeWidth2.value = "";
	}
	if(!(theForm.speedRM100.checked) && !(theForm.speedAll.checked))
	{
	    theForm.frameSizeHeight3.value = "";
        theForm.frameSizeWidth3.value = "";
	}
	if(!(theForm.speedRM300.checked) && !(theForm.speedAll.checked))
	{
	    theForm.frameSizeHeight4.value = "";
        theForm.frameSizeWidth4.value = "";
	}
	if(!(theForm.speedRM500.checked) && !(theForm.speedAll.checked))
	{
	    theForm.frameSizeHeight5.value = "";
        theForm.frameSizeWidth5.value = "";
	}
	if(!(theForm.speedWM56.checked) && !(theForm.speedAll.checked))
	{
	    theForm.frameSizeHeight7.value = "";
        theForm.frameSizeWidth7.value = "";
	}
	if(!(theForm.speedWM100.checked) && !(theForm.speedAll.checked))
	{
	    theForm.frameSizeHeight8.value = "";
        theForm.frameSizeWidth8.value = "";
	}
	if(!(theForm.speedWM300.checked) && !(theForm.speedAll.checked))
	{
	    theForm.frameSizeHeight9.value = "";
        theForm.frameSizeWidth9.value = "";
	}
	if(!(theForm.speedWM500.checked) && !(theForm.speedAll.checked))
	{
	    theForm.frameSizeHeight10.value = "";
        theForm.frameSizeWidth10.value = "";
	}
}