function submitFormOnEnter(event, formId){
	var characterCode;
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.getElementById(formId).submit(); //submit the form 
		return false
	}
	else{
		return true;
	}
	
}

function showOrHideElement(strElementId, strDisplayValue){
//strDisplayValue should be passed as EITHER "inline" or "block" PASSING 'none' will always HIDE the element indicated--even if it is NOT currently showing
	var theElement = document.getElementById(strElementId);

	if(theElement.style.display == 'block' || theElement.style.display == 'inline'){
		theElement.style.display = 'none';
	}else{
		theElement.style.display = strDisplayValue;
		//special case -- if showing the MM login form, give focus to the loginId field 
		if(strElementId == 'login' && strDisplayValue != 'none'){
			document.getElementById('loginIdField').focus();
			document.getElementById('loginIdField').select();
		}
	}
}
function boolIsEmail(objTestField){
//pass in an email field object and the script will both alert the user if it is not valid and return true or false 
//also, if there is more than one address in the field, the script will change the value of the field to equal only the
//first address in the field.
	var stringTest = objTestField.value;
	var objEmailRegex = /([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})/g;
	var arrEmails = stringTest.match(objEmailRegex);
	if(arrEmails){
		objTestField.value = arrEmails[0];
		return true;
	}else{
		alert('Please enter a valid email address.');
		objTestField.focus();
		objTestField.select();
		return false;
	}
}
//STRING MANIPULATION FUNCTIONS
// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}


/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function strGetUrlParam( name ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );

	if( results == null ){
		return "";
	}else{
		return Url.decode(results[1]);
	}
}

function prePopulateField(fieldId){
	var objField = document.getElementById(fieldId);
	
	objField.value = strGetUrlParam(fieldId);
}
			
