var longRef = "document.forms.form";
var searchStr = 'Search This Site';
	
addEvent(window, "load", cleanSearch, false);
addEvent(window, "load", function() {enableDropdown('utilities')}, false);
addEvent(window, "load", function() {enableDropdown('nav')}, false);

var searchStr = 'Search This Site';

function cleanSASearch() 
{
	document.search.query.onfocus = function() {if (this.value == searchStr) this.value = ''};
	document.search.query.onblur = function() {if (this.value == '') this.value = searchStr};
}


function displayOrHideFormSection(formSection)
{
	if (document.getElementById(formSection).style.display == 'block')
	{
		hideFormSection(formSection);
	}
	else
	{
		displayFormSection(formSection);
	}
}
	
	
function displayFormSection(formSection)
{
	document.getElementById(formSection).style.display = 'block';
}


function hideFormSection(formSection)
{
	document.getElementById(formSection).style.display = 'none';
}


// full time and part time tabs
function displayFt (img_id)
{
	document.getElementById(img_id).src = 'http://www.nyu.edu/epubs/preview/mph/web/images/ft-on.gif';
}

function hidePt (img_id)
{
	document.getElementById(img_id).src = 'http://www.nyu.edu/epubs/preview/mph/web/images/pt-off.gif';
}

function displayPt (img_id)
{
	document.getElementById(img_id).src = 'http://www.nyu.edu/epubs/preview/mph/web/images/pt-on.gif';
}

function hideFt (img_id)
{
	document.getElementById(img_id).src= 'http://www.nyu.edu/epubs/preview/mph/web/images/ft-off.gif';
}

// used for plus minus btns on course boxes
function changeBtn(formSection, img_id)
{
	if (document.getElementById(img_id).src == 'http://www.nyu.edu/epubs/preview/mph/web/images/btn-plus.gif')
	{
		
	    document.getElementById(img_id).src = 'http://www.nyu.edu/epubs/preview/mph/web/images/btn-minus.gif';
	}
	else
	{
	    document.getElementById(img_id).src = 'http://www.nyu.edu/epubs/preview/mph/web/images/btn-plus.gif';
	}
}


// used for background color change course boxes
function changeColor(formSection, img_id)
{
	if (document.getElementById(img_id).src == 'http://www.nyu.edu/epubs/preview/mph/web/images/btn-plus.gif')
	{
		
	    document.getElementById(formSection).style.backgroundColor = '#ededed';
	}
	else
	{
	    document.getElementById(formSection).style.backgroundColor = '#faf6d7';
	}
}


// used for rsvp button on events pages
function changeBtn2(formSection, img_id)
{
	if (document.getElementById(img_id).src == 'http://www.nyu.edu/epubs/preview/mph/web/images/btn-clickToRsvp.gif')
	{
		
	    document.getElementById(img_id).src = 'http://www.nyu.edu/epubs/preview/mph/web/images/btn-clickToRsvpGray.gif';
	}
	else
	{
	    document.getElementById(img_id).src = 'http://www.nyu.edu/epubs/preview/mph/web/images/btn-clickToRsvp.gif';
	}
}


var ids=new Array();
var isExpand = 0;

function QAinit()
{
	if(document.getElementById)
	{	
		var tids=document.getElementsByTagName('div');
		for(i=0;i<tids.length;i++)
			if(tids[i].className=="courseTitle")
				ids[ids.length]=tids[i];
		for(i=0;i<ids.length;i++)
			ids[i].onmouseup=setstate;
	}
}

function setstate()
{
	for(i=0;i<ids.length;i++)
	{
		if(ids[i]==this)
		{
			var d=this.parentNode.getElementsByTagName('div')[1];
			if(d.style.display=="block")
			{
				d.style.display="none";
				isExpand = 0;
			}
			else 
			{
				d.style.display="block";
				isExpand = 1;
			}
		}
	}
}

function expandall()
{
	if(document.getElementById)
	{
		for(i=0;i<ids.length;i++)
			ids[i].parentNode.getElementsByTagName('div')[1].style.display="block";
	}

	isExpand = 1;
	document.getElementById('ecBtn').src = '/epubs/preview/ticket.central/web/images/btn.collapse.all.gif';
}

function collapseall()
{
	if(document.getElementById)
	{
		for(i=0;i<ids.length;i++)
			ids[i].parentNode.getElementsByTagName('div')[1].style.display="none";
	}
	isExpand = 0;
	document.getElementById('ecBtn').src = '/epubs/preview/ticket.central/web/images/btn.expand.all.gif';
}

function expandCollapseAll()
{
	if (isExpand == 0)
		expandall();
	else
		collapseall();
}
window.onload=QAinit;


/* 
	Email Form Verification
*/
function isBlank(string)
{
	for (var i = 0; i < string.length; i++) {
		var c = string.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

/**
	Receives a string of required elements
	split by commas and a reference to the form and test
	to see if they are filled out.
*/
function verifyForm(required, whichForm)
{
	var msg			= "";
	var error		= false;
	var errorMsg	= "";
	
	//	Split string of required fields into an array
	var reqList = required.split(/\s*,\s*/);
	
	//	Test for empty required fields and list name if empty
	for (var i = 0; i < reqList.length; i++) {
		var whichElement = eval("whichForm." + reqList[i]);
		if ((whichElement.value == null) || (whichElement.value == "") || isBlank(whichElement.value))
			errorMsg += "- " + whichElement.title + "\n";
	}
	
	//	If everything is ok, return true and submit the form already...
	if (errorMsg == "") return true;
	
	//	Shucks, we have to create an error message
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "Some required fields are missing:\n" + errorMsg;
	
	//	Show error message
	alert(msg);
	
	//	Prevent form from submitting
	return false;
}


