/* Codes for Form Validation
 */
var f_OK = 0;
var f_SPACE_FOUND = 2;
var f_INVALID_CHARACTER = 4;
var f_NOT_NUMERIC = 6;
var f_NOT_ALPHANUMERIC = 8;
var f_NOT_ALPHA = 10;
var f_EMPTY = 12;
var f_NOT_WHOLE_NUMBER = 26;

/* Signup / Profile Validation
 */
var f_INVALID_PHONE = 14;
var f_INVALID_POSTAL_CODE = 16;
var f_INVALID_STATE = 18;

/* Game Registration
 */
var f_MIN_GREATER_THAN_MAX = 20;
var f_NOT_TWO_HOURS = 22;
var f_RANGE_ERROR = 24;


/* Variables required for Form Validation
 */
var numeric = "0123456789";
var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var alphaNum = alpha+numeric;
var special = "!@#$%^&*()-_+=:;?"
var space = " "; // Space is not allowed

var validSiteChars = alphaNum+special;
var validEmail = alphaNum+"@.--_";
var validNameChars = alphaNum+space+"@_-'";
var validAddressChars = alphaNum+space+".-,#";
var validStateChars = alpha;
var validPostalCodeChars = numeric+"- ";
var validPhoneChars = numeric+"()-\\ /";
var validExtensionChars = alphaNum+space;



/**
 * Set the focus to the first field with a problem.
 */
var isFocusSet;
function setFocus( element ) {

	if (!isFocusSet) {
		element.focus();
		element.style.border = "1px solid #ff0000";
		element.style.borderBottom = "2px solid #ff0000";
		isFocusSet = true;
	}
}

var oldBorderStyle = 'blank';
function resetBorders(form) {
	for (var i = 0; i < form.elements.length; i++) {
		form.elements[i].style.border = oldBorderStyle;
	}
}


/**
 *
 */
function getNumericValue(field) {

	var rawNumber = '';
	var testChar;
	
	for (var i = 0; i < field.length; i++) {
		testChar = field.substring(i,(i+1));
		if ( !isNaN(testChar) ) {
			rawNumber += testChar;
		}	
	}

	return rawNumber;
}

/**
 * Determines if the numeric value is a whole number. 
 * (Decimale places not allowed!)
 */
function isWholeNumber(field) {
	var rawValue = getNumericValue(field);
	if (field.length != rawValue.length) {
		return false;
	}
	
	return true;
}

/**
 * Common method to check for spaces in fields that do not allow them.
 */
function containsSpaces(field) {
	var spaceIndex = field.indexOf(space);
	
	if ( spaceIndex >= 0 ) {
		return true;
	}
	
	return false;
}

/**
 * Common method to check for empty fields (for Required fields).
 */
function isEmpty(field) {

	var temp = field.replace(/^\s+/g, '').replace(/\s+$/g, '');
	
	if (temp.length == 0) {
		return true;
	} 
	return false;
}


/**
 * Open a help Dialog window.
 */
function displayHelp(element) {
	var url = 'portal.html?exec=OnlineHelp';
	var item = '&selId=' + element.id;
	var location = url + item;
	window.open(location,'helpDialog', 'menubar=no,toolbar=no,location=no,status=yes,scrollbars=no,resizable=no,width=400,height=300');
}

/**
 * Open a standard Dialog window.
 */
function displayDialog(name,location) {
	window.open(location,name, 'menubar=no,toolbar=no,location=no,status=yes,scrollbars=no,resizable=no,width=984,height=668');
}

/**
 * Switch a tags class style.
 */
function classSwitch(element,style) {
   element.className = style;
}

/**
 * Used to collapse/expand time slots on the event list.
 */
function onClickTimeSlot(imageId,tableId) {
	var image = document.getElementById(imageId);
	var table = document.getElementById(tableId);

	var imageName = 'na';

	//if (image.hasAttributes()) {


		if (table.style.display != 'none') {
			table.style.display = 'none';
			image.setAttribute('src','img/Option-Show.gif');
		} else {
			table.style.display = '';
			image.setAttribute('src','img/Option-Hide.gif');
		}
	//}
}

/**
 * Used by the Event List to set page sizes.
 */
function setPageSize(formId) {
	document.getElementById(formId).submit();
}
