/* convert text INPUT special chars to ascii codes */
	function chars2ASCII(theInput){
		theString = theInput.value;
		var tempString = "";
		myRegExp = /\W/i
		for (i=0;i<theString.length;i++){
			if(myRegExp.test(theString.charAt(i))){
				tempString += "&#" + theString.charCodeAt(i) + ";";
			}else{tempString += theString.charAt(i);}
		}
		theInput.value = tempString;
	}
/* ------------------------------------ */
/* launch popup window */
	function launch(newURL, newName, newFeatures, orgName) {
	  var remote = open(newURL, newName, newFeatures);
	  if (remote.opener == null)
	    remote.opener = window;
	  remote.opener.name = orgName;
	  return remote;
	}
/* ------------------------------------ */
/* rollover */
	function changeBackVar(toClass,fromClass,theState,theRow){
		if(theState == 'over' && theRow.className == toClass){return;}
		if (theRow.className == fromClass){
			theRow.style.cursor = 'hand';
			theRow.className = toClass;
		}
		else{
			theRow.style.cursor = '';
			theRow.className = fromClass;
		}
	}
/* ------------------------------------ */
/* select all items in a SELECT list */
	function selectAll(selectList){
	    if(selectList){
	        for (i=0; i < selectList.length; i++) {selectList.options[i].selected = true;}
	    }
	}
/* ------------------------------------ */
/* changenext function that is used to allow multiple action locations for a single form */
	var nextLocation;
	function changeNext(newNext){
	    nextLocation = newNext;
	}
/* ------------------------------------ */
/* sets the action of a form to the value set by the above changenext function */
	function goNextPlus(targetForm){
		if(nextLocation){
			targetForm.action=nextLocation;
			return true;
		}else{return false;}
	}
/* ------------------------------------ */
/* perfoms goNext from a popup window, causing the parent to be the target of the submit */
	function goNextPlus_targetParent(targetForm){
	  targetForm.action=nextLocation;
	  targetForm.target=window.opener.name;
	  self.close();
	  return true;
	}
/* ------------------------------------ */
/* popup content search
   getContentValuesFromPopupFor : launch and set target function, used in opening window
   setContent : pass content name and id from popup to target funtion, used in popup window */
	var valueForContentName;
	var valueForContentID;
	var targetFunction;
	function getContentValuesFromPopupFor(trgtFunction,URL){
		targetFunction = trgtFunction;
		myRemote=launch(URL,"contentSearch", "height=500,width=750,dependent=1,resizable=1,scrollbars=1", "parentWindow");
	}
	function setContent(contentName,contentID){
		valueForContentName = contentName;
		valueForContentID = contentID;
		eval(targetFunction)();
	}
/* ------------------------------------ */
/* Limit length of text area
   usage: <textarea onKeyDown="textAreaLimit(this,1024);" onKeyUp="textAreaLimit(this,1024);">blah</textarea> */
	function textAreaLimit(field, maxlimit){
	    if (field.value.length > maxlimit){
	        field.value = field.value.substring(0, maxlimit);
	        alert("You have exceeded the maximum limit of " + maxlimit +" characters.");    
	    }
	}
/* ------------------------------------ */
/* move rows of a table */
	var moveTableRowStart = 1;
	function moveTableRow(targetId,direction,targetTable){
		theTable = document.getElementById(targetTable);
		theTRarray = theTable.getElementsByTagName('tr');
		moveDir = (direction == 'up')? -1 : 1 ;
		for(i=0;i<theTRarray.length;i++){
			if (theTRarray[i].id == targetId){
				if((i+moveDir)>=moveTableRowStart && (i+moveDir)<theTRarray.length){	
					theTRarray[i].swapNode(theTRarray[i+moveDir]);
					break;
				}else{
					alert("Can not move this item " + direction + " any further.");
					break;
				}
			}
		}
	}
/* ------------------------------------ */
/* disable enter key */
	/***********************************************
	* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
	* This notice must stay intact for use
	* Visit http://www.dynamicdrive.com/ for full source code
	*usage:  onkeypress="return handleEnter(this, event)"
	***********************************************/    
	function handleEnter(field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13){
			var i;
			for (i = 0; i < field.form.elements.length; i++){
				if (field == field.form.elements[i]){break;}
				i = (i + 1) % field.form.elements.length;
				field.form.elements[i].focus();
				return false;
			} 
		}else{return true;}
	}      
/* ------------------------------------ */
/* javascript version of .trim() */
	/*==================================================================
	LTrim(string) : Returns a copy of a string without leading spaces.
	==================================================================*/
	/*   PURPOSE: Remove leading blanks from our string.
	   IN: str - the string we want to LTrim*/
	function LTrim(str){
	   var whitespace = new String(" \t\n\r");
	   var s = new String(str);
	   if (whitespace.indexOf(s.charAt(0)) != -1) {// We have a string with leading blank(s)...   
	      var j=0, i = s.length;     
	      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)// Iterate from the far left of string until we don't have any more whitespace...
	         j++;
	      s = s.substring(j, i);// Get the substring from the first non-whitespace character to the end of the string...
	   }
	   return s;
	}
	/*==================================================================
	RTrim(string) : Returns a copy of a string without trailing spaces.
	==================================================================*/
	/*   PURPOSE: Remove trailing blanks from our string.
	   IN: str - the string we want to RTrim*/
	function RTrim(str){
	   var whitespace = new String(" \t\n\r");// We don't want to trip JUST spaces, but also tabs, line feeds, etc.  Add anything else you want to "trim" here in Whitespace
	   var s = new String(str);
	   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {// We have a string with trailing blank(s)... 
	      var i = s.length - 1;// Get length of string     
	      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)// Iterate from the far right of string until we don't have any more whitespace...
	         i--;
	      s = s.substring(0, i+1);// Get the substring from the front of the string to where the last non-whitespace character is...
	   }
	   return s;
	}
	/*=============================================================
	Trim(string) : Returns a copy of a string without leading or trailing spaces
	=============================================================*/
	/*   PURPOSE: Remove trailing and leading blanks from our string.
	   IN: str - the string we want to Trim
	   RETVAL: A Trimmed string!*/
	function Trim(str){return RTrim(LTrim(str));}
/* ------------------------------------ */
/* form validation */
	// A utility function that returns true if a string contains only
	// whitespace characters.
	function isblank(s){
	    for(var i = 0; i < s.length; i++){
	        var c = s.charAt(i);
	        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	    }
	    return true;
	}
	// A utility function that returns true if a string is a valid email
	function checkEmail(anEmailAddress){
	    var filter= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	    return filter.test(anEmailAddress);
	}
	// A utility function that returns true if a string is a valid URL
	function checkURL(aURL){
	    //CBNet specific hack
		if (aURL.indexOf("/servlet/Content?")==0 || aURL.indexOf("/servlet/File?")==0){return true;}
		else{
			//these two lines are the generic URL test that works for any site
			var filter= /^(((http|https|ftp)\072\057\057)|(mailto:)){1}(([a-zA-Z0-9\-\100])+\.)+([a-zA-Z0-9]{2,4}(\072\d{4})*(\s+$|\057[\041-\176]*$|$))/;
			return filter.test(aURL);
		}
	}
	// This is the function that performs form verification. It will be invoked
	// from the onSubmit() event handler. The handler should return whatever
	// value this function returns.
	function verify(f){
	    var msg;
	    var empty_fields = "";
	    var errors = "";
	    // Loop through the elements of the form, looking for all
	    // text and textarea elements that are required.
	    // Then, check for fields that are empty and make a list of them.
	    // Also, if any of these elements have a "min" or a "max" property defined,
	    // then verify that they are numbers and that they are in the right range.
	    // Put together error messages for fields that are wrong.
	    var len = f.elements.length;
	    for(var i = 0; i < len; i++){
	        var e = f.elements[i];
	        if ((e.type == "text") || (e.type == "textarea") ||
	            (e.type == "file") || (e.type == "password") ||
	            (e.type == "select-one") ){
	            //check if it is empty
	            if ((e.value == null) ||
	                (e.value == "")   ||
	                isblank(e.value)){
	                    // First check if the field is required
	                if (e.required){
	                    empty_fields += "\n          " + e.title;
	                    continue;
	                }
	            }else{
	                // Now check for fields that are supposed to be numeric.
	                if (e.numeric || (e.min != null) || (e.max != null)){
	                    var v = parseFloat(e.value);
	                    if (isNaN(v) ||
	                        ((e.min != null) && (v < e.min)) ||
	                        ((e.max != null) && (v > e.max)) ){
	                        errors += "- The field " + e.title + " must be a number";
	                        if (e.min != null){errors += " that is greater than " + e.min;}
	                        if (e.max != null && e.min != null){errors += " and less than " + e.max;}
	                        else if (e.max != null){errors += " that is less than " + e.max;}
	                        errors += ".\n";
	                    }
	                }
	                // now check to see if entered text is too long
	                if (e.maxstringlength < e.value.length){
	                    errors += "- The field " + e.title +
	                              " exceeds its maximum length of " +
	                              e.maxstringlength;
	                    errors += ".\n";
	                    continue;
	                }
	                // Enforce a general list of acceptable characters
	                if (e.enforceReasonableCharacters){
	                    e.acceptableCharacters = "0123456789" +
	                                             "abcdefghijklmnopqrstuvwxyz" +
	                                             "ABCDEFGHIJKLMNOPQRSTUVWXYZ()-_@.' ";
	                }
	                // Now check if there is a defined set of allowable characters,
	                // and if so, generate warning.
	                if (e.acceptableCharacters != null){
	                    uninvitedGuests = "";  // Illegal characters
	                    for (charCount=0; charCount < e.value.length; charCount++){
	                        currChar = e.value.charAt(charCount);
	                        if (e.acceptableCharacters.indexOf(currChar) == -1){
	                            uninvitedGuests += currChar;
	                        }
	                    }
	                    if (uninvitedGuests.length > 0){
	                       errors += "- The field " + e.title +
	                                 " contains the following unacceptable characters: " +
	                                 uninvitedGuests;
	                       errors += ".\n";
	                       continue;
	                    }
	                }
	                // Ensure it's a valid email address, if necessary
	                if (e.isemailaddress){
	                    // only bother if it's not empty
	                    if ( !((e.value == null) ||
	                           (e.value == "")   ||
	                           isblank(e.value)) ){
	                        if (!checkEmail(e.value)){
	                            errors += "- The field " + e.title +
	                                      " is not a valid email address";
	                            errors += ".\n";
	                            continue;
	                        }
	                    }
	                }
	                // Ensure it's a valid URL, if necessary
	                if (e.isURL){
	                    // only bother if it's not empty
	                    if ( !((e.value == null) ||
	                           (e.value == "")   ||
	                           isblank(e.value)) ){
	                        if (!checkURL(e.value)){
	                            errors += "- The field " + e.title +
	                                      " is not a valid URL.";
	                            errors += "\n\t";
	                            errors += "Please use full url. Example: http://www.google.com";
	                            errors += "\n";
	                            continue;
	                        }
	                    }
	                }
	                // Ensure it's a valid zip code, if necessary
	                if (e.iszip){
	                    // only bother if it's not empty
	                    if ( !((e.value == null) ||
	                           (e.value == "")   ||
	                           isblank(e.value)  )){
	                        zipRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
							if (!zipRegExp.test(e.value)){
	                            errors += "- The field " + e.title + " must be a valid Zip Code";
	                            errors += ".\n";
	                            continue;
	                        }
	                    }
	                }
	                // Ensure it's a valid phone number, if necessary
	                if (e.isphone){
	                    // only bother if it's not empty
	                    if ( !((e.value == null) ||
	                           (e.value == "")   ||
	                           isblank(e.value)  )){
	                        var s;
	                        s="";
	                        for (z=0;z < e.value.length;++z){
	                            if ( (e.value.charAt(z) != "-") && 
	                                 (e.value.charAt(z) != "(") && 
	                                 (e.value.charAt(z) != ")") ){
	                                s = s + e.value.charAt(z);
	                            }
	                        }
	                        var v = parseFloat(s);
	                        if (isNaN(v)){
	                            errors += "- The field " + e.title +
	                                      " must be a number";
	                            errors += ".\n";
	                            continue;
	                        }else{
	                            e.value = s;
	                            if (e.value.length < 10){
	                                errors += "- The field " + e.title +
	                                          " must be at least 10 digits," +
	                                          " not including dashes or parenthesis.";
	                                errors += ".\n";
	                                continue;
	                            }
	                        }
	                    }
	                }
	            } //end not empty block
	        }
	    }
	    // Now, if there were any errors, display the messages, and
	    // return false to prevent the form from being submitted.
	    // Otherwise return true.
	    if (!empty_fields && !errors) return true;
	    msg =  "______________________________________________________\n\n";
	    msg += "The form was not submitted because of the following error(s).\n";
	    msg += "Please correct these error(s) and re-submit.\n";
	    msg += "______________________________________________________\n\n";
	    if (empty_fields != ""){
	        msg += "- The following required field(s) are empty:"
	                + empty_fields + "\n";
	        if (errors) msg += "\n";
	    }
	    msg += errors;
	    alert(msg);
	    return false;
	}
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
