// JavaScript Document
function getPage(mainMenuTopID,mainMenuSubID,userMenuTopID,userMenuSubID,appAction){
   var mtid = mainMenuTopID;
   var msid = mainMenuSubID;
   var utid = userMenuTopID;
   var usid = userMenuSubID;
   var aact = appAction;
   document.menuform.mtid.value = mtid;
   document.menuform.msid.value = msid;
   document.menuform.utid.value = utid;
   document.menuform.usid.value = usid;
   document.menuform.appAction.value = aact;
   document.menuform.submit();	
   return true;
}


function changeMenuPage(newLoc){
   page = newLoc.options[newLoc.selectedIndex].value;	
   document.menu.action = "authenticate";
   document.menu.target = "_self";	
   document.menu.method = "post";	
   document.menu.submit();	
   return true;
}
function changePage(newLoc){
   nextPage = newLoc.options[newLoc.selectedIndex].value	
   if (nextPage != ""){
      document.location.href = nextPage
   }
}
function moveOption(formname, fromObj, toObj) {      
for (var i = fromObj.options.length - 1; i >= 0; i--) {
	if (fromObj.options[i].selected) {          
		fromObj.options[i].selected = false;          
		optionText = fromObj.options[i].text;          
		optionValue = fromObj.options[i].value; 
		fromlength = fromObj.options.length;      
		for(var j = i; j < fromlength - 1; j++) {            
			fromObj.options[j].text = fromObj.options[j + 1].text;            
			fromObj.options[j].value = fromObj.options[j + 1].value;
		}       
		fromObj.options.length = fromObj.options.length - 1;          
		toObjIndex = toObj.options.length;          
		toObj.options.length = toObj.options.length + 1;          
		toObj.options[toObjIndex].text = optionText;          
		toObj.options[toObjIndex].value = optionValue;
		}     
	}
	return true;    
}
function moveAllOption(formname, fromObj, toObj) {  
for (var i=0; i<fromObj.options.length; i++) 
	fromObj.options[i].selected = true;
	moveOption(formname,fromObj,toObj);   
	return true;    
}
function autofocus(field, limit, next, evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if (charCode > 31 && field.value.length == limit) {
		field.form.elements[next].focus();
	}
}
function numeralsOnly(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		alert("Enter numerals only in this field.");
		return false;
	}
	return true;
}
// Permit only alphabetic letters (a-z) and (A-Z).
function alphaCharOnly(evt) {
	errmsg1 = "Please enter only alphabetic characters in this field.\n\n";
	errmsg3 = "Please click OK to continue.";
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if ( (charCode > 96 && charCode < 123) || (charCode > 64 && charCode < 91) ) {
		return true;
	} else {
		alert(errmsg1+errmsg3);
		return false;
	}
}
// Permit only alphanumeric, period and dash characters ('a-z' 'A-Z' '0-9' '.' '-').
function designCheck(evt) {
	errmsg1 = "Please enter only alphanumeric, period and dash characters in this field.\n\n";
	errmsg3 = "Please click OK to continue.";
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if ((charCode > 96 && charCode < 123) || //alphabetic(a-z)
		 (charCode > 64 && charCode < 91) || //alphabetic(A-Z)
		 (charCode > 47 && charCode < 58) || //numerals(0-9)
		 (charCode == 45) || //dash
		 (charCode == 32) || //space
		 (charCode == 46))   //period
	{
		return true;
	} else {
		alert(errmsg1+errmsg3);
		return false;
	}
}
// Verify only '.GIF' and '.JPG' images/photos are uploaded to the server.
function chkImageType(field) {
	if (form.new_photo.value.length > 4) {
		  var sFile = form.new_photo.value;
		  // valid extensions
		  var sValid = "gif,GIF,jpg,JPG";
		  // error msg
		  var errormsg = "Please upload a image/photo with a valid extension.\n\nValid image/photo formats end in the following: "+ sValid + "\n\nPlease click OK to continue.\n";
		  // get the file extension
		  var sExt = sFile.split(".")[sFile.split(".").length-1];
		  // if extension is found in list
		  if( String(","+sValid+",").indexOf(","+sExt+",") == -1 ){
			alert(errormsg);
			form.new_photo.value='';
			form.new_photo.focus();
			return false;
		  }
	}
}
// Count the number of characters in a textarea field. 
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
// Validate textarea fields
function textareaCheck(evt) {
 errmsg1 = "Please enter only alphanumeric, period, dash, exclamation, comma, pound, dollar, ampersand,\nparentheses, question mark, colon, quote, single quote, forward slash, semi-colon,\nplus, and equals characters in this field.\n\n";
 errmsg3 = "Please click OK to continue.";
 evt = (evt) ? evt : event;
 var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
 if ((charCode > 96 && charCode < 123) || //alphabetic(a-z)
   (charCode > 64 && charCode < 91) || //alphabetic(A-Z)
   (charCode > 47 && charCode < 58) || //numerals(0-9)
   (charCode == 45) || //dash
   (charCode == 32) || //space
   (charCode == 33) || //exclamation
   (charCode == 44) || //comma
   (charCode == 35) || //pound
   (charCode == 36) || //dollar
   (charCode == 38) || //ampersand
   (charCode == 40) || //open parenthesis
   (charCode == 41) || //closed parenthesis
   (charCode == 63) || //question
   (charCode == 58) || //colon
   (charCode == 34) || //quote
   (charCode == 39) || //single quote
   (charCode == 47) || //forward slash
   (charCode == 59) || //semi-colon
   (charCode == 43) || //plus
   (charCode == 61) || //equals
   (charCode == 46))   //period
 {
  return true;
 } else {
  alert(errmsg1+errmsg3);
  return false;
 }
} 
function alphanumericCheck(evt) {
	errmsg1 = "Please enter only alphanumeric characters in this field.\n\n";
	errmsg3 = "Please click OK to continue.";
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if ((charCode > 96 && charCode < 123) || //alphabetic(a-z)
		 (charCode > 64 && charCode < 91) || //alphabetic(A-Z)
		 (charCode > 47 && charCode < 58) ||  //numerals(0-9)
		 (charCode == 32)) //space
	{
		return true;
	} else {
		alert(errmsg1+errmsg3);
		return false;
	}
}
function trim(str) {
  while (str.charAt(str.length - 1)==" ")
    str = str.substring(0, str.length - 1);
  while (str.charAt(0)==" ")
    str = str.substring(1, str.length);
  return str;
}