

/*--------------------------------------------------
 formscript.js

 Date: 10/19/2006
 Purpose: forms-related JavaScript functionality
/--------------------------------------------------*/




/***************************************************
 countChars( textboxID, counterID )

 Date: 10/18/2006
 Purpose: Count and limit the chars in a textbox. 
 Update a counter element with the remaining chars
***************************************************/

function countChars( textboxID, counterID ) {
	if( t = $( textboxID ) ) {
		var count = t.value.length;
		var max = t.getAttribute( "maxlength" ) * 1;
		if( count > max ) {
			t.value = t.value.substring( 0, max );
		} else {
			$( counterID ).innerHTML = '<br />characters left: ' + ( max - count );
		}
	}
}



/***************************************************
 keyPressHandler()

 Date: 8/16/2007
 Purpose: Handle pressing of enter key and submit 
 the form which contains data (IE-specific hack)
***************************************************/

function keyPressHandler( e ){
	// Non-IE browsers behave fine, so return
	if( ! window.event ) return;
	// Handle i.e. (window.event) and firefox (e)
	var eventInstance = window.event ? event : e;
	// Handle i.e. (charCode) and firefox (keyCode)
	var keyCode = eventInstance.charCode ? eventInstance.charCode : eventInstance.keyCode;
	if( keyCode == 13 ) {
		// Determine which form has been filled and submit
		forms = document.forms;
		var formDataLength = new Array();
		var value = "";
		for( i = 0; i < forms.length; i++) {
			formDataLength[i] = 0;
			for( j = 0; j < forms[i].elements.length; j++ ) {
				value = forms[i].elements[j].value.toString();
				formDataLength[i] += value.length;
			}
		}
		// Submit the filled form. Login form is default if both have data
		if( formDataLength[0] > 0 ) {
			document.getElementById("Login").click();
		} else if( formDataLength[1] > 3 ) {
			document.getElementById("Register").click();
		}
	}
}








