var longRef = "document.forms.resedform";

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


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


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


function displayFormRow(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 hideFormSection(formSection)
{
	document.getElementById(formSection).style.display = 'none';
}


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


function changeImage(formSection, img_id)
{
	if (document.getElementById(formSection).style.display == 'block')
	{
	    document.getElementById(img_id).src = 'http://www.nyu.edu/v55/images/button.off.gif';
	}
	else
	{
	    document.getElementById(img_id).src = 'http://www.nyu.edu/v55/images/button.on.gif';
	}
}


/*
	BEGIN: General Hide/Display w/Button Change and Background Color Change
*/
function displayOrHide(section, sectionInfo)
{
	if (document.getElementById(sectionInfo).style.display == 'block')
	{
		hide(section, sectionInfo);
	}
	else
	{
		display(section, sectionInfo);
	}
}

function display(section, sectionInfo)
{
	document.getElementById(section).style.backgroundColor = '#E6EBFF';
	document.getElementById(section).style.borderColor = '#DEE5FF';	
	document.getElementById(sectionInfo).style.display = 'block';	
}

function hide(section, sectionInfo)
{	
	document.getElementById(section).style.backgroundColor = '#F5F8FF';
	document.getElementById(section).style.borderColor = '#F4F4FE';	
	document.getElementById(sectionInfo).style.display = 'none';	
}

function changeIcon(sectionInfo, img_id)
{
	if (document.getElementById(sectionInfo).style.display == 'block')
	{
	    document.getElementById(img_id).src = 'http://www.nyu.edu/v55/images/btnMinus.gif';
	}
	else
	{
	   document.getElementById(img_id).src = 'http://www.nyu.edu/v55/images/btnPlus.gif';
	}
}
/* END */



function resetFields()
{
	eval(longRef).reset();
}


function populateCurrentDayMonthYear(month_field, day_field, year_field, year_code)
{
	// if year_code = 0, years go from 1900 up until current year
	// if year_code = 1, years go from (current year - 5) to (current year + 5)
	
	//var longRef = "document.forms.nyucardAuthorizationForm.";
	
	var temp=0;
	var today= new Date();
	var day= today.getDate();
	var month= today.getMonth();
	var year= today.getFullYear();

	var longRefDay = longRef + "." + day_field;
	var longRefMonth = longRef + "." +  month_field;
	var longRefYear = longRef + "." +  year_field;
	
	if ((eval(longRefMonth).value <= 1)||(eval(longRefMonth).value == ""))
	{
	   eval(longRefMonth).options[month].selected = true;
    }
	populateDaysOfMonth(month_field, day_field);
	if ((eval(longRefDay).value <= 1)||(eval(longRefDay).value == ""))
	{
	   eval(longRefDay).options[day-1].selected = true;
    }
	
	y = 1900;
	var y_dif = 0;
	if (year_code == 0)
	{
		y_dif = (year-y);
	}
	else
	if (year_code == 1)
	{
		y = year - 5;
		y_dif = 10;
	}

	var curYearSel = eval(longRefYear).value;
	for (var i=0; i<=y_dif; i++)
	{
		eval(longRefYear).options[i] = new Option(y,y);
		if (y == curYearSel)
		{
            eval(longRefYear).value = curYearSel;		
		}
		if (y == year)
		{
	       if ((curYearSel == null)||(curYearSel == ""))
	       {      
                eval(longRefYear).options[i].selected = true;
           }
		}
		y = y + 1;
	}
}


function populateDaysOfMonth(month_field, day_field)
{
	//var longRef = "document.forms.nyucardAuthorizationForm.";
	var longRefMonth = longRef + "." +  month_field;
	var longRefDay = longRef + "." +  day_field;
	
	var curDaySel = eval(longRefDay).value;
	
	var dayCt = 0;
	if (eval(longRefMonth).options[1].selected)
	{
		dayCt = 29;		//allow for leap years
	}
	else 
	{
		if ((eval(longRefMonth).options[8].selected) || //sept
			(eval(longRefMonth).options[3].selected) || //april
			(eval(longRefMonth).options[5].selected) || //june
			(eval(longRefMonth).options[10].selected))  //november
		{
			dayCt = 30;
		}
		else
		{
			dayCt = 31;
		}
	}
		
	for(i=0;i<31;i++)
	{
		eval(longRefDay).options[i] = null;
	}
	
	for (var i=0; i < dayCt ; i++)
	{
		var day= String(i+1);
        eval(longRefDay).options[i] = new Option(day, day);
	}
	
	eval(longRefDay).value = curDaySel;
}


function processAffiliateType()
{
		if (document.forms.nyucardAuthorizationForm.affiliate_type.value == 3)
		{
			document.getElementById('affiliate_family_id').style.visibility = 'visible';
		}
		else
		{
			document.getElementById('affiliate_family_id').style.visibility = 'hidden';
		}
}


/*
function processSubmit()
{
	var reqStr = "The following information is still needed:\n";
	var valid = 1;
	
	if (valid == 0)
	{
		alert(reqStr);
		return false;
	}
	else
	{
		return true;
	}
}
*/


function validEmail(email) 
{
	invalidChars = " /:,;";
				     
	if (email == "")  
	return false;
	
	for (i=0; i<invalidChars.length; i++) 
	{
		badChar = invalidChars.charAt(i);
		
		if (email.indexOf(badChar,0) > -1)
		 return false;
	}
		
	 atPos = email.indexOf("@",1);   
	 if (atPos == -1) 
		 return false;
						
	 if (email.indexOf("@",atPos+1) != -1)   
		 return false;
						
	periodPos = email.indexOf(".",atPos);
	if (periodPos == -1) 
		return false;
						
	if (periodPos+3 > email.length) 
		return false;
		
	return true; 
}


function isNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
      }
      return IsNumber;
}

   
function valButton(btn) 
{
	var cnt = -1;
	for (var i=btn.length-1; i > -1; i--) 
	{
   		if (btn[i].checked) {cnt = i; i = -1;}
   	}
	if (cnt > -1) return btn[cnt].value;
	else return null;
}   

function changePage(newLoc)
 {
   nextPage = newLoc.options[newLoc.selectedIndex].value
		
   if (nextPage != "")
   {
      document.location.href = nextPage
   }
 }
