formValues = new Array();
formValues["client"] = "";
formValues["protocol"] = "pop";
formValues["authentication"] = "passwords";
formValues["location"] = "oncampus";

function setFormValues() {

	passedValues = location.search.substring(1);
	if (passedValues) {
		tempArrayOne = passedValues.split("&");

		for (i=0; i < tempArrayOne.length; i++) {
			tempArrayTwo = tempArrayOne[i].split("=");
			formValues[tempArrayTwo[0]] = tempArrayTwo[1];
		}
	}

	if (formValues["client"] != "") {
		for (i=0; i < document.form1.client.length; i++) {
			if (formValues["client"] == document.form1.client.options[i].value) {
				document.form1.client.options[i].selected = true;
			}
		}
		checkForKerberos();
	}
	
	
	if (formValues["location"] == "offcampus") {
		document.form1.location[0].checked = false;
		document.form1.location[1].checked = true;
	}
	
	if (formValues["protocol"] == "imap") {
		document.form1.protocol[0].checked = false;
		document.form1.protocol[1].checked = true;
	}
	
	if (formValues["authentication"] == "kerberos") {
		document.form1.authentication[0].checked = false;
		document.form1.authentication[1].checked = true;
	}

}


function sendToConfig() {
	
	clientInd = document.form1.client.selectedIndex;
	clientPiece = document.form1.client.options[clientInd].value;
	
	configOptions = new Array();
	marker = 0;
	if (document.form1.protocol[1].checked) {
		configOptions["protocol"] = "imap";
		marker = 1;
	}
	if (document.form1.authentication[1].checked) {
		configOptions["authentication"] = "kerberos";
		marker = 1;
	}
	if (document.form1.location[1].checked) {
		configOptions["location"] = "offcampus";
		marker = 1;
	}
	if (document.form1.debug) {
		if (document.form1.debug[0].checked) {
			configOptions["debug"] = "on";
			marker = 1;
		}
	}	
	
	optionsPiece = "";
	if (marker != 0) {
		optionsPiece = optionsPiece + "?";
		count = 1;
		for (tempVar in configOptions) {
			if (count > 1) {
				optionsPiece = optionsPiece + "&";
			}
			optionsPiece = optionsPiece + tempVar + "=" + configOptions[tempVar];
			count++;
		}
	}

	directoryPiece = "http://www.stanford.edu/services/email/config/";
	urlString = directoryPiece + clientPiece + "/" + optionsPiece;

	if (clientPiece == "") {
		alert("Please select a client from the drop down menu");
	}
	else {
		window.location.href = urlString;
	}

}

function checkForKerberos () {
	clientIndex = document.form1.client.selectedIndex;
	clientValue = document.form1.client.options[clientIndex].value;
	kerberizedClients = new Array ("eudora6_win", "eudora6_osx", "osx3mail", "osx5mail", "generic");
	showKerberos = "no";
	for (i=0; i < kerberizedClients.length; i++) {
		if (clientValue == kerberizedClients[i]) {
			showKerberos = "yes";
			break;
		}
	}
	if (showKerberos != "yes") {
		document.form1.authentication[0].checked=true;
		document.form1.authentication[1].disabled=true;
	} else {
		document.form1.authentication[1].disabled=false;
	}
}
