
jQuery(document).ready(function (){
	if(!navigator.cookieEnabled){
		jQuery('#noCookies').css('display', '');
	}
});

function populateSearchValues(e, localArray) {
	var d = new Array();
	d = localArray;
	for (var i = 0; i < e.length; i++) {
		for (var j = 0; j < d.length; j++) {
			if (e[i].value == d[j]) {
				e[i].checked = true;
				e[i].selected = true;
			}
		}
	}
}
function submitForm(form, location) {
	form.action = location;
	var keepGoing = true;
	if (form.SubmitFunction) {
		keepGoing = eval(form.SubmitFunction.value);
	} 
  // alert(keepGoing);
	if (keepGoing) {
		form.submit();
	}
}
function moveAthletic(sourceList, radioset, destList) {
	isThere = 0;
	i = sourceList.options.length;
	var selected;
	for (i = 0; i < radioset.length; i++) {
		if (radioset[i].checked == true) {
			selected = radioset[i].value;
		}
	}
	if (sourceList.options[sourceList.selectedIndex] && sourceList.options[sourceList.selectedIndex].value) {
		var tmp1 = selected + sourceList.options[sourceList.selectedIndex].value;
		var tmp2 = sourceList.options[sourceList.selectedIndex].text + "(" + selected + ")";
		for (j = 0; j < destList.options.length; j++) {
			if (tmp1 == destList.options[j].value) {
				isThere = 1;
			}
		}
		if (isThere == 0) {
			if (sourceList.options != null) {
				var i = destList.options.length;
				destList.options[i] = new Option(tmp2);
				destList.options[i].value = tmp1;
			}
		}
	} else {
		alert("Please select a sport!");
	}
}
/////////////////////////////////////////////////////////////////////////////////
function fillSelectFromArray(selectCtrl, itemArray) {
	var i, j;
	var prompt;
	
 	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null;
	}
	j = 0;
	if (itemArray != null) {
		//alert("testing good array: "+itemArray.length+":"+selectCtrl.options.length);
  		// add new items
		for (i = 0; i < itemArray.length; i++) {
			selectCtrl.options[i] = new Option(itemArray[i][1]);
			if (itemArray[i][1] != null) {
				selectCtrl.options[i].value = itemArray[i][0];
			}
		}
		j++;
	}
}
////////////////////////////////////////////////////////////////////////////////
function moveTo(selectOne, selectTwo) {
	isThere = 0;
	i = selectTwo.options.length;
	if (selectOne.options[selectOne.selectedIndex] && selectOne.options[selectOne.selectedIndex].value) {
		for (k = 0; k < selectOne.options.length; k++) {
			isThere = 0;
			if (selectOne.options[k].selected == true) {
				for (j = 0; j < selectTwo.options.length; j++) {
					if (selectOne.options[k].value == selectTwo.options[j].value) {
						isThere = 1;
					}
				}
				i = selectTwo.options.length;
				if (isThere == 0) {
					selectTwo.options[i] = new Option(selectOne.options[k].text);
					selectTwo.options[i].value = selectOne.options[k].value;
				}
			}
		}
	} else {
		alert("Please select a value!");
	}
}
////////////////////////////////////////////////////////////////////////////////
function moveAll(selectOne, selectTwo) {
	isThere = 0;
	for (k = 0; k < selectOne.options.length; k++) {
		isThere = 0;
		for (j = 0; j < selectTwo.options.length; j++) {
			if (selectOne.options[k].value == selectTwo.options[j].value) {
				isThere = 1;
			}
		}
		i = selectTwo.options.length;
		if (isThere == 0) {
			selectTwo.options[i] = new Option(selectOne.options[k].text);
			selectTwo.options[i].value = selectOne.options[k].value;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////
function moveFrom(selectform) {
	if (selectform.selectedIndex != -1) {
		for (k = 0; k < selectform.options.length; k++) {
			if (selectform.options[k].selected == true) {
				selectform.options[k] = null;
				k--;
			}
		}
	}
}
////////////////////////////////////////////////////////////////////////////////
function moveTextAndSelect(textbox, sourceList, destList1, destList2) {
	moveTo(sourceList, destList2);
	value = textbox.value + ":" + sourceList.options[sourceList.selectedIndex].value;
	isThere = 0;
	for (j = 0; j < destList1.options.length; j++) {
		if (destList1.options[j].value == value) {
			isThere = 1;
		}
	}
	if (isThere == 0 && !textbox.value == "") {
		i = destList1.options.length;
		destList1.options[i] = new Option(textbox.value);
		destList1.options[i].value = value;
	}
}
////////////////////////////////////////////////////////////////////////////////
function moveSelectAndSelect(slist, sourceList, destList1, destList2) {
	moveTo(sourceList, destList2);
	value = slist.options[slist.selectedIndex].value;
	isThere = 0;
	for (j = 0; j < destList1.options.length; j++) {
		if (destList1.options[j].value == value) {
			isThere = 1;
		}
	}
	if (isThere == 0) {
		i = destList1.options.length;
		destList1.options[i] = new Option(slist.options[slist.selectedIndex].text);
		destList1.options[i].value = value;
	}
}
////////////////////////////////////////////////////////////////////////////////
function test(sourceList, radioset, destList) {
	var value;
	var text = sourceList.options[sourceList.selectedIndex].text + "(" + radioset.value + ")";
	if (radioset.value == "local") {
		value = sourceList.options[sourceList.selectedIndex].value + ":true";
	} else {
		value = sourceList.options[sourceList.selectedIndex].value + ":false";
	}
	var i = destList.options.length;
	destList.options[i] = new Option(text);
	destList.options[i].value = value;
}
////////////////////////////////////////////////////////////////////////////////
function moveRadiosetAndSelect(sourceList, radioset, destList) {
	isThere = 0;
	i = sourceList.options.length;
	for (j = 0; j < destList.options.length; j++) {
		reg = new RegExp(sourceList.options[sourceList.selectedIndex].text + ":*");
		if (reg.test(destList.options[j].text)) {
			isThere = 1;
		}
	}
	if (isThere == 0) {
		var value;
		for (i = 0; i < radioset.length; i++) {
			if (radioset[i].checked == true) {
				var Selected = radioset[i].value;
			}
		}
		var text = sourceList.options[sourceList.selectedIndex].text + "(" + Selected + ")";
		if (Selected == "local") {
			value = sourceList.options[sourceList.selectedIndex].value + ":true";
		} else {
			value = sourceList.options[sourceList.selectedIndex].value + ":false";
		}
		var i = destList.options.length;
		destList.options[i] = new Option(text);
		destList.options[i].value = value;
	}
}
////////////////////////////////////////////////////////////////////////////////
function moveSelect(sourceList, destList) {
	isThere = 0;
	i = destList.options.length;
	for (j = 0; j < destList.options.length; j++) {
		if (sourceList.options[sourceList.selectedIndex].text == destList.options[j].text) {
			isThere = 1;
		}
	}
	if (isThere == 0) {
		var text = sourceList.options[sourceList.selectedIndex].text;
		destList.options[i] = new Option(text);
		destList.options[i].text = text;
	}
}
////////////////////////////////////////////////////////////////////////////////
function oldmoveSelect(sourceList, destList) {
	var text = sourceList.options[sourceList.selectedIndex].text;
	var l = destList.options.length;
	destList.options[l] = new Option(text);
	destList.options[1].value = value;
}
////////////////////////////////////////////////////////////////////////////////
function moveSelect(sourceList1, sourceList2, sourceList3, destList) {
	var text = sourceList1.options[sourceList1.selectedIndex].text + "(" + sourceList2.options[sourceList2.selectedIndex].text + "," + sourceList3.options[sourceList3.selectedIndex].text + ")";
	var value = sourceList1.options[sourceList1.selectedIndex].value + ":" + sourceList2.options[sourceList2.selectedIndex].value + ":" + sourceList3.options[sourceList3.selectedIndex].value;
	isThere = 0;
	i = destList.options.length;
	for (j = 0; j < destList.options.length; j++) {
		reg = new RegExp(sourceList1.options[sourceList1.selectedIndex].text + ":*");
		if (reg.test(destList.options[j].text)) {
			isThere = 1;
		}
	}
	if (isThere == 0) {
		destList.options[i] = new Option(text);
		destList.options[i].value = value;
	}
}
////////////////////////////////////////////////////////////////////////////////
function selectAll(sourceList1) {
	for (i = 0; i < sourceList1.options.length; i++) {
		sourceList1.options[i].selected = true;
	}
	return true;
}
////////////////////////////////////////////////////////////////////////////////
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(";");
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == " ") {
			c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) == 0) {
				var cParse = c.split("=");
				var e = cParse[1].split(":");
				return "aos=" + e[0] + "&locations=" + e[1] + "&two_four_year=" + e[2] + "&public_private=" + e[3] + "&regions=" + e[4];
			}
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
function zipFocus(i, j) {
	if (i == 0 && j.value == "Zip Code") {
		j.value = "";
	} else {
		if (i == 1 && j.value == "") {
			j.value = "Zip Code";
		}
	}
}
function validateZipcode() {
	for (i = 0; i < radio.length; i++) {
		if (radio[i].checked && radio[i].value == 1) {
			var zippy = "";
			zippy = document.csearch.zipcode.value;
			var exp = new RegExp(/[0-9]{5}/);
			if (zippy == "Zip Code") {
				document.csearch.zipcode.value = "";
				return true;
			} else {
				if (exp.test(zippy)) {
					return true;
				} else {
					alert("Please enter a valid 5 digit zip-code.");
					return false;
				}
			}
		}
	}
	return true;
}
function clearSearch() {
	var form = document.createElement("form");
	form.action = "/collegesearch/areaofstudy.jsp";
	form.method = "GET";
	var input = document.createElement("input");
	input.setAttribute("name", "domain");
	input.setAttribute("type", "hidden");
	input.setAttribute("value", "clear");
	form.appendChild(input);
	document.getElementsByTagName("body")[0].appendChild(form);
	form.submit();
}
function disableForm(which) {
	if (which == 1) {
		var locations = document.csearch.locations;
		for (i = 0; i < locations.length; i++) {
			locations[i].disabled = true;
		}
		var checkit = document.csearch.checkit;
		for (i = 0; i < checkit.length; i++) {
			checkit[i].disabled = true;
		}
		document.csearch.distance.disabled = false;
		document.csearch.zipcode.disabled = false;
		document.csearch.distance.style.color = "#000000";
		document.csearch.zipcode.style.color = "#000000";
	} else {
		var locations = document.csearch.locations;
		for (i = 0; i < locations.length; i++) {
			locations[i].disabled = false;
		}
		var checkit = document.csearch.checkit;
		for (i = 0; i < checkit.length; i++) {
			checkit[i].disabled = false;
		}
		document.csearch.distance.disabled = true;
		document.csearch.zipcode.disabled = true;
		document.csearch.distance.style.color = "#999999";
		document.csearch.zipcode.style.color = "#999999";
	}
}
function addClassName(element, className) {
	element.className += " " + className;
}
function removeClassName(element, className) {
	var temp = new Array();
	element.className = element.className.replace(new RegExp("\\b" + className + "\\b", "g"), "");
}
function selectSchools(checkbox, formName) {
	var form = document[formName];
	if (form != null) {
		var schoolList = makeArray(form.schoolList);
		for (i = 0; i < schoolList.length; i++) {
			if (checkbox.checked == true) {
				schoolList[i].checked = true;
			} else {
				schoolList[i].checked = false;
			}
		}
	}
}
function makeArray(tmp) {
	if (!tmp.length) {
		tmp = [tmp];
	}
	return tmp;
}
function submitSearchForm(formName, action) {
	form = document[formName];
	var schoolList = makeArray(form.schoolList);
	if(formName == 'featured_schools') {
		if (schoolList.length == 1) {
			form.productTypeID.value = 2;
		}
	}
	form.action = action;
	form.submit();
}
function checkCount(formName, min, max) {
	var count = 0;
	var form = document[formName];
	if (form != null) {
		var schoolList = makeArray(form.schoolList);
		for (i = 0; i < schoolList.length; i++) {
			if (schoolList[i].checked == true) {
				count++;
			}
		}
	}
	if (count <= max && count >= min) {
		return true;
	} else {
		if (count < min) {
			alert("Please select at least " + min + " school(s).");
		}
		if (count > max) {
			alert("A maximum of " + max + " school(s) can be selected.");
		}
		return false;
	}
}
function checkCount2(formNames, min, max) {
	var count = 0;
	for (var i = 0; i < formNames.length; i++) {
		count += getCount(formNames[i]);
	}
	if (count <= max && count >= min) {
		return true;
	} else {
		if (count < min) {
			alert("Please select at least " + min + " school(s).");
		}
		if (count > max) {
			alert("A maximum of " + max + " school(s) can be selected.");
		}
		return false;
	}
}
function submitForms(formNames, action) {
	var masterList = new Array();
	for (var i = 0; i < formNames.length; i++) {
		var form = document[formNames[i]];
		if (form != null) {
			var schoolList = makeArray(form.schoolList);
			for (var j = 0; j < schoolList.length; j++) {
				if (schoolList[j].checked == true) {
					masterList.push(schoolList[j]);
				}
			}
		}
	}
	var form = document.createElement("form");
	form.setAttribute("method", "post");
	form.setAttribute("action", action);
	for (var i = 0; i < masterList.length; i++) {
		var input = document.createElement("input");
		input.setAttribute("type", "hidden");
		input.setAttribute("name", masterList[i].name);
		input.setAttribute("value", masterList[i].value);
		form.appendChild(input);
	}
	document.body.appendChild(form);
	form.submit();
}
function getCount(formName) {
	var count = 0;
	var form = document[formName];
	if (form != null) {
		var schoolList = makeArray(form.schoolList);
		for (var i = 0; i < schoolList.length; i++) {
			if (schoolList[i].checked == true) {
				count++;
			}
		}
	}
	return count;
}
function getElementsByClassName(oElm, strTagName, oClassNames) {
	var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if (typeof oClassNames == "object") {
		for (var i = 0; i < oClassNames.length; i++) {
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	} else {
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for (var j = 0; j < arrElements.length; j++) {
		oElement = arrElements[j];
		bMatchesAll = true;
		for (var k = 0; k < arrRegExpClassNames.length; k++) {
			if (!arrRegExpClassNames[k].test(oElement.className)) {
				bMatchesAll = false;
				break;
			}
		}
		if (bMatchesAll) {
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements);
}
function restoreSearchNavigation() {
	try {
		updatePrograms();
	}
	catch (err) {
	}
	var elements = getElementsByClassName(document, "*", "hiddenNavigation");
	for (i = 0; i < elements.length; i++) {
		removeClassName(elements[i], "hiddenNavigation");
	}
}
function submitInfozapForm() {
	var featuredForm = document["featured_schools"];
	var tempList = makeArray(featuredForm.schoolList);
	var schoolList = new Array();
	var count = 0;
	for (i = 0; i < tempList.length; i++) {
		if (tempList[i].checked) {
			schoolList[count] = tempList[i];
			count++;
		}
	}
	var form = document.createElement("form");
	form.action = "/userdata/secured/infozap.jsf";
	form.method = "post";
	var input = document.createElement("input");
	input.setAttribute("name", "infozapType");
	input.setAttribute("type", "hidden");
	if (schoolList.length == 1) {
		input.setAttribute("value", "normalInfozap");
	} else {
		input.setAttribute("value", "dynamicInfozap");
	}
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute("name", "productTypeID");
	input.setAttribute("type", "hidden");
	if (schoolList.lenght == 1) {
		input.setAttribute("value", 2);
	} else {
		input.setAttribute("value", 3);
	}
	form.appendChild(input);
	var input = document.createElement("input");
	input.setAttribute("name", "productAreaID");
	input.setAttribute("type", "hidden");
	input.setAttribute("value", 9);
	form.appendChild(input);
	for (i = 0; i < schoolList.length; i++) {
		var input = document.createElement("input");
		input.setAttribute("name", "schoolList");
		input.setAttribute("type", "hidden");
		if (schoolList.length == 1) {
			input.setAttribute("value", normalInfozapIds[schoolList[i].value]);
		} else {
			input.setAttribute("value", dynaInfozapIds[schoolList[i].value]);
		}
		form.appendChild(input);
	}
	document.getElementsByTagName("body")[0].appendChild(form);
	form.submit();
}