﻿
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
	found = true;
	else
	index++;
	return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
	}
	return true;
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	{	
		field.value = field.value.substring(0, maxlimit);
 		alert("The data you entered is " + field.value.length + " characters." + strPersonalstat)
 	}
		// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function isValidPostalcode(postalcode) {
	postalcode = trim(postalcode);
	if (postalcode.search) {
		postalcode = removeSpaces(postalcode);
		if (postalcode.length == 6 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true;
		else if (postalcode.length == 7 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]-\d[a-zA-Z]\d$/) != -1) return true;
		else return false;
	}
		return true;
}

function checkStateUS(checkstate) {	
	var returnFlag = false;
	var statearray = new Array("AA", "AE", "AP", "AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MS","MO","MT","NE","NM","NV","NH","NJ","NM","NY","MN","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY", "PR", "AS", "FM", "GU", "MH", "MP", "PW", "VI")
	var statenumber = statearray.length;
	for (var i = 0; i < statenumber; i++)
	{
		if (statearray[i] == checkstate)
			returnFlag = true;
	}
	return returnFlag
}
 

function checkStateCA(checkstate) {
	var returnFlag = false;
	var statearray = new Array("AB","BC","MB","NB","NF","NS","ON","PE","PQ","SK", "NT", "YT", "QC")
	var statenumber = statearray.length;
	for (var i = 0; i < statenumber; i++)
	{
		if (statearray[i] == checkstate)
			returnFlag = true;
	}
	return returnFlag
}

// BUG18627
function checkTerritoryUS(checkstate) {	
	var returnFlag = false;
	var statearray = new Array("PR", "AS", "FM", "GU", "MH", "MP", "PW", "VI", "")
	var statenumber = statearray.length;
	for (var i = 0; i < statenumber; i++)
	{
		if (statearray[i] == checkstate)
			returnFlag = true;
	}
	return returnFlag
}

function removeSpaces(string) {
	var newString = '';
	for (var i = 0; i < string.length; i++) {
		if (string.charAt(i) != ' ') newString += string.charAt(i);
	}
	return newString;
}

function modifydata(menu, option)
{
	var v_member_type = document.regpage.Membertype.options[document.regpage.Membertype.selectedIndex].value
	if (v_member_type == 'OCA_USER')
	{
		document.regpage.stud_first_name.value = document.regpage.Firstname.value;
		document.regpage.stud_last_name.value = document.regpage.Lastname.value;
	}
}

function copyData(theObject)
{
	var v_member_type = document.regpage.Membertype.options[document.regpage.Membertype.selectedIndex].value
	if (v_member_type == 'OCA_USER')
	{
		if (theObject.name == 'Firstname') 
			document.regpage.stud_first_name.value = theObject.value
		if (theObject.name == 'Lastname') 
			document.regpage.stud_last_name.value = theObject.value
	}
}

function verifyDigit(input, inputlenth) {
	var nonnumberCheck = /\D/i	
	if (nonnumberCheck.test(input)) 
	{
		return false	
	} else
	{
		if (inputlenth > 0) {
			if (inputlenth == input.length) 
				return true
			else
				return false;
		} else
			return true
	}
}

function isObject(a) {
    return (typeof a == 'object' && !!a) || isFunction(a);
}

function isFunction(a) {
    return typeof a == 'function';
}


// This is for OptinSurvey
 function chkRegPage()
 {
	var check_flag = true;
	
	var strIam = "Please select a member type."
	var strGradYear = "Please select a graduation year."	
	var strPhone = "Please enter a valid phone number."
		
	if (isObject(document.optinsurvey.iam)) 
	{	
		if ( document.optinsurvey.iam.value == "" && check_flag )	{
 			alert(strIam)
 			document.optinsurvey.iam.focus();
 			check_flag = false;
 		}
	}

	if ( document.optinsurvey.gradyear.value == "" && check_flag )	{
 		alert(strGradYear)
 		document.optinsurvey.gradyear.focus();
 		check_flag = false;
 	}
 	
 	var phone_area = document.optinsurvey.phone_area.value;
	var phone1 = document.optinsurvey.phone1.value;
	var phone2 = document.optinsurvey.phone2.value;
	var phone_ext = document.optinsurvey.phone_ext.value;
	
	
 		
 	if ((document.optinsurvey.testprep_opt.selectedIndex < 0) && (document.optinsurvey.FINAID.checked != true) && (document.optinsurvey.ADESSAYHELP.checked != true) && (document.optinsurvey.DISTLEARN.checked != true) && (document.optinsurvey.SEARCHSEL.checked != true) && check_flag)
 		{
 		alert('Please select at least one area of interest.')
 		 document.optinsurvey.testprep_opt.focus();
 		 check_flag = false;
 		}						
								
	if (check_flag)
	{
		document.optinsurvey.submit();						
	}
}
function $(id)
{
    return document.getElementById(id);
}
function opendiv() 
{
	 for (var i=0; i< opendiv.arguments.length; i++) 
	 {	
		  var element = document.getElementById(opendiv.arguments[i]);
		  if(!element) return; 
		  element.style.display ="block";
	 }
}

function closediv() 
{
	 for (var i=0; i< closediv.arguments.length; i++) 
	 {	
		  var element = document.getElementById(closediv.arguments[i]);
		  if(!element) return;
		  element.style.display ="none";
	 }
}

           
            
function DetectIE6()
{
    var returnVal = false;
    
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
    { //test for MSIE x.x;
    var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
    if (ieversion>=6)
        returnVal = true;
    }
    return returnVal;
}


var newwindowpopmystudentedgeinfo;
var newwindowpop;
function pop(url,width,height,resizeable)
{
  var left=(screen.width-width)/2;
  var top = (screen.height-(height+110))/2; 
  newwindowpop = window.open(url,'Help','width='+width+',height='+height+',resizable='+resizeable+',left='+left+',top='+top+',status=no');
  if (window.focus) {newwindowpop.focus()}
}

function popmystudentedgeinfo(url)
{
  if (DetectIE6())
  {
     if (window.name != 'mystudentedgeinfo')
     {
	      newwindowpopmystudentedgeinfo=window.open(url,'mystudentedgeinfo','width=980,scrollbars=yes,height=533,resizable=yes,status=no')
	      if (window.focus) {newwindowpopmystudentedgeinfo.focus()}     
     }
     else
     {
	      newwindowpopmystudentedgeinfo=window.open(url,'mystudentedgeinfo','width=980,scrollbars=yes,height=533,resizable=yes,status=no')
        newwindowpopmystudentedgeinfo.location.reload(true);
        newwindowpopmystudentedgeinfo.focus()
     }
  }
  else
  {
	  newwindowpopmystudentedgeinfo=window.open(url,'mystudentedgeinfo','width=980,scrollbars=yes,height=533,resizable=yes,status=no')
	  if (window.focus) {newwindowpopmystudentedgeinfo.focus()}
	}
}

    