
var OPTIONS_CATEGORY_INDEX = 0;
var OPTIONS_LABEL_INDEX = 1;
var OPTIONS_KEY_INDEX = 2; //Probably dont even need this
var CATEGORIES_CATEGORY_INDEX = 0;
var CATEGORIES_LABEL_INDEX = 1;
var CATEGORIES_KEY_INDEX = 2;
function removeAllAvailableOptions(selectbox) {
	alert("Box: " + selectbox.options[0]);
	var i;
	if (selectbox != null) {
		for (i = selectbox.options.length - 1; i >= 0; i--) {
			selectbox.remove(i);
		}
	}
}
function addOption(selectbox, text, value, isSelected) {
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	if (isSelected) {
		optn.selected = isSelected;
	} //if isSelected, set it's value.  Must be boolean.
	selectbox.options.add(optn);
}
function addOptions(selectbox, selectbox2, valArray) {
	alert("Test: " + valArray.length);
	//removeAllAvailableOptions(selectbox);
	mgtest(selectbox2);
	if (valArray != null) {
		for (var i = 0; i < valArray.length; i++) {
			addOption(selectbox, valArray[i], valArray[i]);
		}
	}
}
function mgtest(selectbox) {
	alert("MG Test: " + selectbox.options.length);
	alert("MG Test: " + selectbox.name);
	for (var i = 0; i < selectbox.options.length; i++) {
		alert(i + selectbox.options[i].value);
	}
}
function mgtest2() {
	this.submit();
}
/*
Initializes the lists for the form
*/
function init() {
	//alert('init');
	var routeHidden = document.getElementById("contactUsPopupForm:selectedCategory");
	//alert("Var: "+routeHidden.value);
	if (routeHidden.value == "pr") {
		//alert("PR: "+routeHidden.value);
		return;
	} else {
		if (routeHidden.value) {
		//alert("Non-PR: "+routeHidden.value);
			selectedCategory = routeHidden.value;
		}
	}
	loadRecipients();
	loadOptions();
}
/*
Loads the options available by recipient
KWB 7/06/2007
*/
function loadOptions() {
	var optionsSelect = document.getElementById("regardingOptions");
	for (var i = 0; i < options.length; i++) {
		var category = options[i][OPTIONS_CATEGORY_INDEX];
		if (category == selectedCategory) {
			var label = options[i][OPTIONS_LABEL_INDEX];
			var key = options[i][OPTIONS_KEY_INDEX];
			var isSelected = (selectedOption == options[i][OPTIONS_KEY_INDEX]);
			addOption(optionsSelect, label, key, isSelected);
		}
	}
}
/*
Loads the possible recipients of the contact us form
KWB 7/06/2007
*/
function loadRecipients() {
	var recipientsSelect = document.getElementById("recipients");
	for (var i = 0; i < categories.length; i++) {
		var category = categories[i][CATEGORIES_CATEGORY_INDEX];
		var label = categories[i][CATEGORIES_LABEL_INDEX];
		var isSelected = (category == selectedCategory);

		//alert(isSelected + ": " + category + " " + selectedCategory);
		addOption(recipientsSelect, label, category, isSelected);
	}
	var recipientsOptions = recipientsSelect.options;
	for (var j = 0; j < recipientsOptions.length; j++) {
		if (recipientsOptions[i] == selectedCategory) {
			recipientsOptions.selectedIndex = i;
		}
	}
}
/*
Pulls the values from the select boxes and adds them to the hidden fields
*/
function organizeFieldsForSubmit() {
	var recipientsSelect = document.getElementById("recipients");
	var optionsSelect = document.getElementById("regardingOptions");
	var recipientHidden = document.getElementById("contactUsPopupForm:selectedCategory");
	var optionHidden = document.getElementById("contactUsPopupForm:selectedOption");
	recipientHidden.value = recipientsSelect.options[recipientsSelect.selectedIndex].value;
	optionHidden.value = optionsSelect.options[optionsSelect.selectedIndex].value;
}
function reloadOptions(currentCategory) {
	var recipientsSelect = document.getElementById("recipients");
	var recipientsValue = recipientsSelect.value;
	var optionsSelect = document.getElementById("regardingOptions");
	optionsSelect.length = 0;
	for (var i = 0; i < options.length; i++) {
		var category = options[i][OPTIONS_CATEGORY_INDEX];
		var label = options[i][OPTIONS_LABEL_INDEX];
		var key = options[i][OPTIONS_KEY_INDEX];
		if (category == currentCategory) {
			//alert("Matched: " + category + " and " + currentCategory);
			addOption(optionsSelect, label, key, false);
		}
	}
}

function resizeContactForm(offset) {
	var correction = 20;
    //To correct for margin
	var arrDimentions = getPopupOriginalSize();
	var width = arrDimentions[0];
	var height = arrDimentions[1];
	
    //alert('Original Dimentions width / height: '+ width + ':' + height);
    //alert('Offset: ' + offset);
	var calculatedHeight = parseInt(height) + parseInt(offset) - parseInt(correction);
    //alert('Height + offset: '+ calculatedHeight);
	parent.resizePopup(width, calculatedHeight);
}

function resizeConfirmation(height) {
	var arrDimentions = getPopupOriginalSize();
	var width = arrDimentions[0];
	var confirmationHeight = parseInt(height);
	if(isNaN(confirmationHeight))
		confirmationHeight = 160;
	parent.resizePopup(width, confirmationHeight);
}

