function changeSchool(redirection,str)
{
	var schoolID = str.split("_")[0];
	var productID = str.split("_")[1];
	var cateringID = str.split("_")[2];
	var giftID = str.split("_")[3];

	var oldSchool = GetCookie('base_school');

	if (oldSchool != schoolID) {
		DeleteCookie('base_school');
		SetCookie('base_school',schoolID,365);
	}

	SetCookie('base_product',productID,365);
	SetCookie('base_catering',cateringID,365);
	SetCookie('base_gift',giftID,365);

	if(schoolID == 255) redirection = 2;		// Specialized Override for NYU Dining

	switch(redirection)
	{
		case 0:			// Late Night Menu
			//if(oldSchool != schoolID) {
			//	document.location="/store/index.php?categoryID="+productID+"&sort=categoryID&direction=ASC&wipe=true";
			//}
			//else document.location="/store/index.php?categoryID="+productID+"&sort=categoryID&direction=ASC";
			document.location="/store/index.php?categoryID="+productID+"&sort=categoryID&direction=ASC";
			break;
		case 1:			// Catering & Gifts
			if(cateringID != -1 || schoolID == 131) 
			document.location="/store/index.php?categoryID="+cateringID+"&sort=categoryID&direction=ASC";
			else alert("NO CATERING FOR THIS SCHOOL");
			break;
		case 2:			// Cookie Gifts
			document.location="/store/index.php?categoryID="+giftID+"&sort=categoryID&direction=ASC";
			break;
		case 3:			// Deal of the Day
			switch(schoolID)
			{
				// Manhattan
				case "79": document.location="/store/index.php?categoryID=133&sort=categoryID&direction=ASC"; break;
				// Cornell
				case "127": document.location="/store/index.php?categoryID=144&sort=categoryID&direction=ASC"; break;
				// Indiana University
				case "130": document.location="/store/index.php?categoryID=156&sort=categoryID&direction=ASC"; break;
				// Michigan State University
				case "80": document.location="/store/index.php?categoryID=162&sort=categoryID&direction=ASC"; break;
				// Ohio State
				case "129": document.location="/store/index.php?categoryID=250&sort=categoryID&direction=ASC"; break;
				// Penn State
				case "83": document.location="/store/index.php?categoryID=175&sort=categoryID&direction=ASC"; break;
				// Purdue University
				case "128": document.location="/store/index.php?categoryID=187&sort=categoryID&direction=ASC"; break;
				// University of Wisconsin
				case "132": document.location="/store/index.php?categoryID=199&sort=categoryID&direction=ASC"; break;
				// Syracuse
				case "82": document.location="/store/index.php?categoryID=206&sort=categoryID&direction=ASC"; break;
				// University of Florida
				case "131": document.location="/store/index.php?categoryID=219&sort=categoryID&direction=ASC"; break;
				// University of Illinois
				case "84": document.location="/store/index.php?categoryID=227&sort=categoryID&direction=ASC"; break;
				// University of Michigan
				case "85": document.location="/store/index.php?categoryID=235&sort=categoryID&direction=ASC"; break;
				// University of Pennsylvania
				case "81": document.location="/store/index.php?categoryID=243&sort=categoryID&direction=ASC"; break;
				// Virginia Tech
				case "131": document.location="/store/index.php?categoryID=243&sort=categoryID&direction=ASC"; break;
				//University of Delaware
				case "300": document.location="/store/index.php?categoryID=309&sort=categoryID&direction=ASC"; break;
				//Ohio University
				case "336": document.location="/store/index.php?categoryID=346&sort=categoryID&direction=ASC"; break;
				//University of Kentucky
				case "312": document.location="/store/index.php?categoryID=321&sort=categoryID&direction=ASC"; break;
				//University of South Carolina
				case "288": document.location="/store/index.php?categoryID=291&sort=categoryID&direction=ASC"; break;
				//West Virginia
				case "324": document.location="/store/index.php?categoryID=333&sort=categoryID&direction=ASC"; break;
				// Default
				default: document.location="/";
			}
			break;
		case 5:			// Apparel
			break;
		case 6:			// Catering
			document.location="/store/index.php?categoryID="+cateringID+"&sort=categoryID&direction=ASC";
			break;
		case 7:			// SuperBowl Special
			switch(schoolID)
			{
				// Manhattan
				case "79": document.location="/store/index.php?categoryID=266&sort=categoryID&direction=ASC"; break;
				// Cornell
				case "127": document.location="/store/index.php?categoryID=263&sort=categoryID&direction=ASC"; break;
				// Indiana University
				case "130": document.location="/store/index.php?categoryID=264&sort=categoryID&direction=ASC"; break;
				// Michigan State University
				case "80": document.location="/store/index.php?categoryID=265&sort=categoryID&direction=ASC"; break;
				// Ohio State
				case "129": document.location="/store/index.php?categoryID=267&sort=categoryID&direction=ASC"; break;
				// Penn State
				case "83": document.location="/store/index.php?categoryID=268&sort=categoryID&direction=ASC"; break;
				// Purdue University
				case "128": document.location="/store/index.php?categoryID=269&sort=categoryID&direction=ASC"; break;
				// St. Joseph's
				case "132": document.location="/store/index.php?categoryID=199&sort=categoryID&direction=ASC"; break;
				// Syracuse
				case "82": document.location="/store/index.php?categoryID=270&sort=categoryID&direction=ASC"; break;
				// University of Florida
				case "131": document.location="/store/index.php?categoryID=219&sort=categoryID&direction=ASC"; break;
				// University of Illinois
				case "84": document.location="/store/index.php?categoryID=271&sort=categoryID&direction=ASC"; break;
				// University of Michigan
				case "85": document.location="/store/index.php?categoryID=272&sort=categoryID&direction=ASC"; break;
				// University of Pennsylvania
				case "81": document.location="/store/index.php?categoryID=273&sort=categoryID&direction=ASC"; break;
				// Virginia Tech
				case "131": document.location="/store/index.php?categoryID=243&sort=categoryID&direction=ASC"; break;
				// Default
				default: document.location="/";
			}
			break;
	}
}
function SetCookie(cookieName,cookieValue,nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";path=/;expires="+expire.toGMTString();
}
function DeleteCookie(cookieName)
{
	if (GetCookie(name)) {
		document.cookie = cookieName+"="+";path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}
function noenter()
{
	return !(window.event && window.event.keyCode == 13);
}
function GetCookie(cookieName)
{
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookieName);
	if (index1==-1 || cookieName=="") return ""; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookieName.length+1,index2));
}

var isFirefox = false; if(navigator.appName.indexOf("Netscape") != -1) isFirefox = true;
var _xmlHttp = true;

function genericAJAXGET(qryStr,rscFunc)
{
	_xmlHttp = false;
	if (window.XMLHttpRequest)  // Mozilla, Safari,...
	{
		_xmlHttp = new XMLHttpRequest();
		if (_xmlHttp.overrideMimeType)
		{
			_xmlHttp.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)  // IE
	{
		try {
			_xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!_xmlHttp)
	{
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	if(isFirefox == true) _xmlHttp.overrideMimeType('text/html');		// Needed to avoid Firefox js error
	_xmlHttp.onreadystatechange = rscFunc;
	_xmlHttp.open('GET', qryStr, true);
	_xmlHttp.send(null);
}

function genericAJAXPOST(qryStr,parameters,rscFunc)
{
	_xmlHttp = false;
	if (window.XMLHttpRequest)  // Mozilla, Safari,...
	{
		_xmlHttp = new XMLHttpRequest();
		if (_xmlHttp.overrideMimeType)
		{
			_xmlHttp.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)  // IE
	{
		try {
			_xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!_xmlHttp)
	{
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	if(isFirefox == true) _xmlHttp.overrideMimeType('text/html');		// Needed to avoid Firefox js error
	_xmlHttp.onreadystatechange = rscFunc;
	_xmlHttp.open('POST', qryStr, true);
	_xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	_xmlHttp.setRequestHeader("Content-length", parameters.length);
	_xmlHttp.setRequestHeader("Connection", "close");
	_xmlHttp.send(parameters);
}

function toggleProductStatus(productID,imgref)
{
	genericAJAXGET("/manage/process/process_togglestate.php?productid=" + productID,function(){toggleProductCB(imgref);});
}
function toggleProductCB(imgref)
{
	var e_img = new Image(); e_img.src = "/images/icons/accept.png";
	var d_img = new Image(); d_img.src = "/images/icons/cross.png";
	
	if(_xmlHttp.readyState == 4)
	{
		if(_xmlHttp.status == 200)
		{
			if(_xmlHttp.responseText != "")
			{
				if(_xmlHttp.responseText == 0)		// disable product
				{
					imgref.src = d_img.src;
				}
				else															// enabel product
				{
					imgref.src = e_img.src;
				}
			}
		}
	}
}
function toggleGalleryStatus(galleryID,imgref)
{
	genericAJAXGET("/manage/process/process_togglegallerystate.php?galleryid=" + galleryID,function(){toggleGalleryCB(imgref);});
}
function toggleGalleryCB(imgref)
{
	var e_img = new Image(); e_img.src = "/images/icons/accept.png";
	var d_img = new Image(); d_img.src = "/images/icons/cross.png";
	
	if(_xmlHttp.readyState == 4)
	{
		if(_xmlHttp.status == 200)
		{
			if(_xmlHttp.responseText != "")
			{
				if(_xmlHttp.responseText == 0)		// disable gallery
				{
					imgref.src = d_img.src;
				}
				else															// enable gallery
				{
					imgref.src = e_img.src;
				}
			}
		}
	}
}
function showAUMenu()
{
	var au_menu = document.getElementById("auwrapper");
	au_menu.style.display = "block";
	au_menu.style.visibility = "visible";
}
function hideAUMenu(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	if(targ.id == "auwrapper")
	{
		targ.style.display = "none";
	}
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function valCount(reqcount)
{
	if(reqcount != 0)
	{
		var frm1 = document.HiddenFieldsForm;
		var frm2 = document.MainForm;
		var rgx1 = /^(\d{1,})\s(.*)$/;
		var tally = 0;

		for(var i=0; i < frm2.elements.length; i++)
		{
			var eref = frm2.elements[i];
			if(eref.type == "select-one")
			{
				//alert(eref[eref.selectedIndex].text);
				if(rgx1.test(trim(eref[eref.selectedIndex].text)))
				{
					var count = RegExp.$1;
					tally += parseInt(count);
					//alert(count);
				}
			}
			else
			{
				//alert(frm2.elements[i].name);
			}
		}
		if(tally != reqcount)
		{
			var rref = document.getElementById("errorrow");
			var dref = document.getElementById("errordiv");
			if(tally < reqcount) dref.innerHTML = "You have only allocated " + tally + " out of " + reqcount + " parts of this product.<br/>Please allocate the remaining " + (reqcount-tally) + " pieces.<br/>";
			else dref.innerHTML = "You have allocated " + tally + " out of " + reqcount + " available parts.<br/>Please remove " + (tally-reqcount) + " products.<br/>";
			rref.style.display = "";
			return false;
		}
		else return true;
	}
	else
	{
		return true;
	}
}
