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};
}

/*
	Regular display/hide
*/
function displayOrHideFormSection1(formSection)
{
	if (document.getElementById(formSection).style.display == 'block')
	{
		hideFormSection1(formSection);
	}
	else
	{
		displayFormSection1(formSection);
	}
}

function displayFormSection1(formSection)
{
	document.getElementById(formSection).style.display = 'block';
}	

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


/* 
	Display hide w/ bold/unbold functionality
*/
function displayOrHideFormSection(formSection, quest)
{
	if (document.getElementById(formSection).style.display == 'block')
	{
		hideFormSection(formSection, quest);
	}
	else
	{
		displayFormSection(formSection, quest);
	}
}


function displayFormSection(formSection, quest)
{
	document.getElementById(formSection).style.display = 'block';
	document.getElementById(quest).className ='singleQuesionSelected';
}


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


/* 
	Table specific 
*/
function displayOrHideFormRow1(formRow)
{
	if ((document.getElementById(formRow).style.display == 'table-row')||(document.getElementById(formRow).style.display == ''))
	{
		hideFormRow1(formRow);
	}
	else
	{
		displayFormRow1(formRow);
	}
}


function displayFormRow1(formRow)
{   
    // set to default for browser.
    // Mozilla will interpret this as 'table-row'
    // IE will interpret this as block 
    // (IE does not support 'table-row' as a display value)
	document.getElementById(formRow).style.display = '';
}


function hideFormRow1(formRow)
{
	document.getElementById(formRow).style.display = 'none';
}


function displayOrHideFormRow(formRow, quest)
{
	if ((document.getElementById(formRow).style.display == 'table-row')||(document.getElementById(formRow).style.display == ''))
	{
		hideFormRow(formRow, quest);
	}
	else
	{
		displayFormRow(formRow, quest);
	}
}


function displayFormRow(formRow, quest)
{   
    // set to default for browser.
    // Mozilla will interpret this as 'table-row'
    // IE will interpret this as block 
    // (IE does not support 'table-row' as a display value)
	document.getElementById(formRow).style.display = '';
	document.getElementById(quest).className ='singleQuesionSelected';
}


function hideFormRow(formRow, quest)
{
	document.getElementById(formRow).style.display = 'none';
	document.getElementById(quest).className ='singleQuesionUnselected';
}


/* 
	Image changing functions 
*/
function changeClusterBtn(formSection, img_id)
{
	if (document.getElementById(img_id).src == 'http://www.nyu.edu/epubs/preview/hr/benefits/images/btn.cluster.expand.gif')
	{
		
	    document.getElementById(img_id).src = 'images/btn.cluster.collapse.gif';
	}
	else
	{
	    document.getElementById(img_id).src = 'images/btn.cluster.expand.gif';
	}
}


function changeSingleBtn(formSection, img_id)
{
	if (document.getElementById(img_id).src == 'http://www.nyu.edu/epubs/preview/hr/benefits/images/btn.single.expand.gif')
	{
		
	    document.getElementById(img_id).src = 'images/btn.single.collapse.gif';
	}
	else
	{
	    document.getElementById(img_id).src = 'images/btn.single.expand.gif';
	}
}


function boldOrUnboldText(formSection)
{
	if (document.getElementById(formSection).style.fontWeight == 'bold')
	{
		document.getElementById(formSection).style.fontWeight == 'normal';
	}
	else
	{
		document.getElementById(formSection).style.fontWeight == 'bold';
	}
}


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/springinny/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/springinny/web/images/btn.expand.all.gif';
}

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


/* 
	For select drop downs with active link options 
*/
function getNavSelection(url)
{
	window.location = url;
}


/* BELOW FUNCTIONS USED TO OPEN SPECIFIC FAQ CLUSTERS AND QUESTIONS ----------------------------------------------------------------------- */

/* 
	Use to get QUERY string from url via Javascript rather than PHP 
*/

function PageQuery(q) 
{
	if(q.length > 1) 
		this.q = q.substring(1, q.length);
	else 
		this.q = null;

	this.keyValuePairs = new Array();
	
	if(q) 
	{
		for(var i=0; i < this.q.split("&").length; i++) 
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() 
	{ 
		return this.keyValuePairs; 
	}
	this.getValue = function(s) 
	{
		for(var j=0; j < this.keyValuePairs.length; j++) 
		{
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	
	this.getParameters = function() 
	{
		var a = new Array(this.getLength());
	
		for(var j=0; j < this.keyValuePairs.length; j++) 
		{
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}

	this.getLength = function() 
	{ 
		return this.keyValuePairs.length; 
	}
}	


function queryString(key)
{
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key));
}


/* Specific to Campus Cable page */
function displayItem(key1, key2)
{
	var ans = queryString(key1);
	var que = queryString(key2);
	displayOrHideFormSection1(ans);		
	jumpTo(que);	
}


function showFAQ (url, formSection, section)
{
	window.location = url;
	displayOrHideFormSection1(formSection);
}

function jumpTo (section)
{
	window.location.hash=section;
}