
// numbers and commas for broadcast list entry boxes
var Global_regexp =   /[^a-zA-Z?.;:\'\" \+\-=\\\/\*\[\]{}`~!@#\$%\^&\(\)_<>|]/; 

// numbers only for phone number input
var Global_regexp2 = /[^,a-zA-Z?.;:\'\" \+\-=\\\/\*\[\]{}`~!@#\$%\^&\(\)_<>|]/; 

// allow any input EXCEPT space
function restrictSpaceInput(event)
{
    var keyCode = event.keyCode ? event.keyCode :
                  event.which ? event.which :
                  event.charCode;
    var key = String.fromCharCode(keyCode);

    if (key == ' ') {
        return false;
    } else {
        return true;
    }
}


function onChangeNumberField(event)
{
         var keyCode = event.keyCode ? event.keyCode :
                       event.which ? event.which :
                       event.charCode;
         var key = String.fromCharCode(keyCode);
         
         return Global_regexp.test(key); 
}

function allowNumbersOnly(event)
{
         var keyCode = event.keyCode ? event.keyCode :
                       event.which ? event.which :
                       event.charCode;
         var key = String.fromCharCode(keyCode);
         
         return Global_regexp2.test(key); 
}


function loadDone()
{
    if ( document.form1.saved_state.value == "yes" )
    {
         document.form1.saved_state.value = "no";
         alert("Your changes have been saved");
    }
}


function MM_goToURL()
{   //v3.0
    var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
    for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


// Page state variable
var Global_PageState_isModified=false;

// The form object which will be submitted if
// no changes has been detected.
// see validateLinkSubmit()
var Global_PageState_currentFormObj=null; 

// Confirmation message
var Global_PageState_message = null;

/**
 * Returns boolean(true/false) if 
 * a field has been changed
 * @return true - a field has been changed
 *  	   false - no change
 */
function isModified(){
	return (Global_PageState_isModified);
}

/**
 * This function sets the
 * global variable Global_isModified to true.
 * Calling this function inside the form element's
 * onChange event handler allows the feature bar
 * menu to detect changes done on any field.
 * 
 * @param form - document.form object which this form
 *				 element belongs to
 */
function setModified(form){
	Global_PageState_isModified=true;
	Global_PageState_currentFormObj=form;
}

/**
 * Set the message which will be displayed when the
 * user is prompted to save changes.
 * @param message - i18nalized message which will be prompted
 *				    to the user if any change has been detected
 */
function setConfirmationMessage(message){

	Global_PageState_message = message;
}

/**
 * returns the confirmation message
 * @return message - confirmation message
 */
function getConfirmationMessage(){
	return (Global_PageState_message);
}

/**
 * 
 * Since this function could be called from an external
 * JSP the form object is passed via call to
 * setModified(), see setModified(document.form) for details.
 *
 * @param url - location to which the request will be forwarded
 *			    to for sucessful operation
 */
function validatePageState(url){

	if (isModified())
    {
		var result = confirm(getConfirmationMessage());

		if (result== true){
			// user selected OK then submit the form
			// otherwise proceed to the URL
			Global_PageState_currentFormObj.submit();
			return;
		}
	}
	window.location = url;

}



/**
 * FUNCTION NAME: isEmpty
 *
 * DESCRIPTION:   Checks if a string is empty
 *
 * PARAMS:        s - string to validate
 *
 * RETURNS:       true  - if s is empty
 *                false - if s is not empty
 */
function isEmpty(s)
{
	i = 0;
	while ( (s.charAt(i) == " ") && (i < s.length) )
		{ i++; }

	if (i != s.length)
		{ return false; }
	else
		{ return true; }
}


/* 20 Nov 2003 shyu created */
/**
 * Remove the leading and trailing space of a string.
 * @return str - string with leading and trailing space removed.
 */
function trimString(str)
{
    return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function status_message(message_txt)
{
  status = message_txt;
  return true;
}
