﻿/* Navigation */
function toggleNav(cell) {
// highlights and unhighlights navigation links
	switch (cell.className) {
		case 'nav navOff': 
			cell.className = 'nav navOn';
			break;
		case 'nav navOn':
			cell.className = 'nav navOff';
			break;
	}
}

function validateSignon() {
    // used on signon.aspx
    var isValid = true;
    var confirmMember = null;
	var firstName = null;
	var lastName = null;
	var graduationYear = null;
	var securityAnswer = null;
    var form = document.getElementById('SignOnForm');

    try {
        var inputs = form.getElementsByTagName('input');        
        for (i=0; i<inputs.length; i++) {
            if (inputs[i].id.indexOf('ConfirmMembership') > -1) {
                confirmMember = inputs[i];
            } else if (inputs[i].id.indexOf('AlumniFirstName') > -1) {
                firstName = inputs[i];
            } else if (inputs[i].id.indexOf('AlumniLastName') > -1) {
                lastName = inputs[i];
            } else if (inputs[i].id.indexOf('SecurityAnswer') > -1) {
                securityAnswer = inputs[i];
            }
        }
        
        var selects = form.getElementsByTagName('select');
        for (i=0; i<selects.length; i++) {
            if (selects[i].id.indexOf('GraduationYear') > 0) {
                graduationYear = selects[i];
            }
        }

        if (confirmMember.checked == false) {
            alert('You must check the box to confirm you are a member and agree to the terms listed.');
		    confirmMember.select();
		    isValid = false;
        }

	    if (isValid && firstName.value == '') {
		    alert('You must enter your first name.');
		    firstName.focus();
		    isValid = false;
	    }
    	
	    if (isValid && lastName.value == '') {
		    alert('You must enter your last name.');
		    lastName.focus();
		    isValid = false;
	    }
    	
	    if (isValid && graduationYear.value == '') {
		    alert('You must enter a graduation year.');
		    graduationYear.focus();
		    isValid = false;
	    }
    	
	    if (isValid && securityAnswer.value == '') {
		    alert('You must answer the security question.');
		    securityAnswer.focus();
		    isValid = false;
	    }
	    
    } catch(e) {
        isValid = false;
        alert('An error occurred while validating the data.');
        //throw e.message;
    } finally {
        return isValid;
    }	
}

function validateAdminLogon() {
    // used on adminlogon.aspx
    var isValid = true;
    var adminUsername = document.getElementById('AdminUsername');
	var adminPassword = document.getElementById('AdminPassword');

	if (isValid && adminUsername.value == '') {
		alert('A valid username must be specified.');
		adminUsername.focus();
		isValid = false;
	}
	
	if (isValid && adminPassword.value == '') {
		alert('A valid password must be specified.');
		adminPassword.focus();
		isValid = false;
	}
	
	return isValid;
}

/***********************************************/
/* Error Handling */

//window.onerror = customErrorHandler;
/*
function customErrorHandler(desc, page, line, chr)  {
	alert(
		'JavaScript error. \n'
		+ '\nError description: \t' + desc
		+ '\nPage address:      \t' + page
		+ '\nLine number:       \t' + line
	);
	return true;
}
*/

/* General Functions */
/*
function trim(string) {
	string = string.replace(/^[\s]+/g,'');
	return string;
}

function keyIsEnter(evt) {
	if (evt.keyCode == 13) {
		return true;
	} else {
		return false;
	}
}

function keyIsTab(evt) {
	if (evt.keyCode == 9) {
		return true;
	} else {
		return false;
	}
}

function scrollToSelection(elementID) {
	var select = document.getElementById(elementID);
	if (select != null) {
		var index = select.selectedIndex;
		var origState = false;
		
		if (index + 4 < select.options.length) {
			index += 4;
		}
		
		origState = select.options[index].selected;	
		select.options[index].selected = true;
		select.options[index].selected = origState;
	}
}
*/

/* Navigation */
/*
function changeDirectoryPage(goToPage) {
  // switches pages for directory search
	if (goToPage == null) { goToPage = 1; }
	var form = document.getElementById('DirectorySearch');
	var input = document.getElementById('GoToPage');
	
	input.value = goToPage;
	form.submit();
}

function redirect(url, openNewWindow, windowProperties, windowName) {
  // redirect's to a URL either in the same window or a new one
	var newUrl = url.replace('amp;', '');	
	var sizeWidth = 800;
	var sizeHeight = 600;
	var positionLeft = 40;
	var positionTop = 20;
	var showTitlebar = 1;
	var showMenubar = 1; 
	var showToolbar = 0;
	var showLocation = 0;
	var showDirectories = 0;
	var showStatus = 0;
	var isResizable = 1;
	var hasScrollbars = 1;
	
	if (windowName == null) { windowName = "childWindow"; }
	
	if (windowProperties != null) {
		var propsArray = windowProperties.split(';');
		for (var i=0; i<propsArray.length; i++) {
			var part = new String(propsArray[i]);

			if (part.indexOf('width') > -1) { sizeWidth = part.match('[0-9]+'); }
			if (part.indexOf('height') > -1) { sizeHeight = part.match('[0-9]+'); }
			if (part.indexOf('left') > -1) { positionLeft = part.match('[0-9]+'); }
			if (part.indexOf('top') > -1) { positionTop = part.match('[0-9]+'); }
			if (part.indexOf('titlebar') > -1) { showTitlebar = part.match('[0-9]+'); }
			if (part.indexOf('menubar') > -1) { showMenubar = part.match('[0-9]+'); }
			if (part.indexOf('toolbar') > -1) { showToolbar = part.match('[0-9]+'); }
			if (part.indexOf('location') > -1) { showLocation = part.match('[0-9]+'); }
			if (part.indexOf('directories') > -1) {showDirectories = part.match('[0-9]+'); }
			if (part.indexOf('status') > -1) { showStatus = part.match('[0-9]+'); }			
			if (part.indexOf('resizable') > -1) { isResizable = part.match('[0-9]+'); }
			if (part.indexOf('scrollbars') > -1) { hasScrollbars = part.match('[0-9]+'); }
		}
	}
	
	//if (event && typeof(event) != 'undefined' && event.ctrlKey == true) { openNewWindow = true; windowName = '_blank'; windowProperties = 'none'; }

	if (openNewWindow != null && openNewWindow != false) {		
		if (windowProperties == 'none') {
			if (windowName != '_blank') { hWindow = window.open('about:blank', windowName); }
			hWindow = window.open(newUrl, windowName);
		} else {			
			windowProperties = "width=" + sizeWidth + ",height=" + sizeHeight + ", ";
			windowProperties += "left=" + positionLeft + ",top=" + positionTop + ", ";
			windowProperties += "titlebar=" + showTitlebar + ", menubar=" + showMenubar + ", ";
			windowProperties += "toolbar=" + showToolbar + ",location=" + showLocation + ", ";
			windowProperties += "directories=" + showDirectories + ", status=" + showStatus + ", ";
			windowProperties += "resizable=" + isResizable + ", scrollbars=" + hasScrollbars + " '";
			windowProperties += "fullscreen=0, channelmode=0'";
							
			if (windowName != '_blank') { hWindow = window.open('about:blank', windowName, windowProperties); }
			hWindow = window.open(newUrl, windowName, windowProperties);						
		}
		hWindow.focus();
		return hWindow;
	} else {
		location.href = newUrl;
	}
}
*/

/* Toggle Controls */
/*
function toggleCheckDisabled(isDisabled, checkboxId, labelId) {
	var check = document.getElementById(checkboxId);
	var label = document.getElementById(labelId);
	
	if (isDisabled != true) { isDisabled = false; }
	if (isDisabled) {
		if (check != null) { check.disabled = true; }
		if (label != null) { label.style.color = 'gray'; }
	} else {
		if (check != null) { check.disabled = false; }
		if (label != null) { label.style.color = ''; }
	}
}

function toggleCheckbox(isChecked, checkboxId) {
	var check = document.getElementById(checkboxId);
	
	if (isChecked != true) { isChecked = false; }
	if (isChecked) {
		if (check != null) { check.checked = true; }
	} else {
		if (check != null) { check.checked = false; }
	}
}
*/

/* Logon */
/*
function validateLogon() {
  // used on leftnav.ascx and logon.aspx
	var isValid = true;
	var txtUsername = document.getElementById('username');
	var txtPasswd = document.getElementById('passwd');

	if (txtUsername.value == '') {
		alert('A valid username must be specified.');
		txtUsername.focus();
		isValid = false;
	}
	
	if (isValid && txtPasswd.value == '') {
		alert('A password must be specified.');
		txtPasswd.focus();
		isValid = false;
	}
	
	return isValid;
}

function validateForgotPassword() {
  // used on forgotpassword.aspx
	var isValid = true;
	var txtEmail = document.getElementById('email');
	
	if (txtEmail.value == '') {
		alert('You must enter your e-mail address.');
		txtEmail.focus();
		isValid = false;
	}
	
	return isValid;
}
*/
