function javaTrim(strIN) {
	return strIN.replace(/^\s*|\s*$/g, "");
}

function javaSafe(strIN) {
	if (strIN) {
		var strOut = ''+strIN+'';
		//strOut = strOut.replace(///gi, '&frasl;');
		//strOut = strOut.replace(/,/gi, "&#44;");
		//strOut = strOut.replace(/-/gi, "&#45;");
		strOut = strOut.replace(/"/gi, '&quot;');
		strOut = strOut.replace(/'/g, '`');
		//strOut = strOut.replace(/\n/gi, ' ');
		//strOut = strOut.replace(/&#10;/gi, ' ');
		return strOut;
	}
	else return '';
}

function convertJavaSafe(stringIN) {
	stringIN = stringIN.replace(/&frasl;/gi, '/');
	stringIN = stringIN.replace(/&quot;/gi, '"');
	stringIN = stringIN.replace(/&#45;/gi, '-');
	stringIN = stringIN.replace(/&#44;/gi, ',');
	stringIN = stringIN.replace(/&#39;/gi, "'");
	return stringIN;
}
	
function morlesTXTcheck(thisTxt, heightIN, heightBig, bound1, bound2) {
	if (thisTxt.value.length > bound2) {
		thisTxt.style.height=heightBig+'px';
		thisTxt.style.overflow='auto';
	}
	else if (thisTxt.value.length > bound1) {
		thisTxt.style.height=(3*heightIN)+'px';
		thisTxt.style.overflow='visible';
	}
	else {
		thisTxt.style.height=heightIN+'px';
		thisTxt.style.overflow='visible';
	}
	return true;
}

function morlesTXTfield(frm, fld, val, width, heightIN, defhgt, onKeyUp, colorTxt, colorBg) {
	var retVal = '';
	var currLen = 0;
	var boundary1 = 45;
	var boundary2 = 150;
	if (width < 150) {
		boundary1 = 15;
		boundary2 = 65;
	}
	if (val && val.length > 0) currLen = val.length;
	var textColors = new Array('#000000', '#FFFFFF');
	if (colorTxt != '') textColors[0] = colorTxt;
	if (colorBg != '') textColors[1] = colorBg;
	retVal = '<textarea id="' + fld + 'ID" name="' + fld + '" style="font-size: 10pt; width: ' + width + 'px; height: ';
	if (currLen > boundary2) retVal += heightIN + 'px; overflow: visible;';
	else if (currLen > boundary1) retVal += (3*defhgt) + 'px; overflow: visible;';
	else retVal += (defhgt) + 'px; overflow: hidden;';
	retVal += ' color: ' + textColors[0] + '; background: ' + textColors[1] + ';" onKeyUp="morlesTXTcheck(this, '+defhgt+', '+heightIN+', '+boundary1+', '+boundary2+'); ';
	retVal += onKeyUp + '">' + val + ' </textarea>';
	return retVal;
}

function showHelixHelp(helpID, topIN, leftIN) {
	if (document.getElementById(helpID)) {
		document.getElementById(helpID).style.top=topIN+'px';
		document.getElementById(helpID).style.left=leftIN+'px';
	}
	return true;
}

function hideHelixHelp(helpID) {
	if (document.getElementById(helpID)) document.getElementById(helpID).style.left='2500px';
	return true;
}


	function Left(str, n) {
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
	}

   function selectAll() {

      for( i = 0; i < document.form1.elements.length; i++ ) {
         var e = document.form1.elements[i];
         if ( e.name.indexOf( 'mail_list_' ) == 0 ) {
            e.checked = true;
         }
      }
   }

   function selectNone() {

      for( i = 0; i < document.form1.elements.length; i++ ) {
         var e = document.form1.elements[i];
         if ( e.name.indexOf( 'mail_list_' ) == 0 ) {
            e.checked = false;
         }
      }
   }

   function countSelected() {
      var count = 0;
      for( i = 0; i < document.form1.elements.length; i++ ) {
         var e = document.form1.elements[i];
         if ( e.name.indexOf( 'mail_list_' ) == 0 ) {
            if(  e.checked ) {
               count++
            }
         }
      }
      return count;
   }

   function clearFilters() {
      for( i = 0; i < document.form1.elements.length; i++ ) {
         var e = document.form1.elements[i];
         if ( e.name.indexOf( 'filter_' ) == 0 ) {
            e.value = '';
         }
      }
      return false;
   }


   function approveChecked() {
      document.form1.form_action.value = "approve";
      document.form1.submit();
   }


   function denyChecked() {
      document.form1.form_action.value = "deny";
      document.form1.submit();
   }


   function sendCheckedApp() {
      document.form1.form_action.value = "sendApp";
      document.form1.submit();
   }

	function doSort( colName, sortDir ) {
		var sortOrder = "";

      if ( document.form1.sortCol.value == colName ) {

         if ( (sortDir == "") || (sortDir == "desc") ) {
            sortOrder = "asc";
         } else {
            sortOrder = "desc";
         }
      } else {
         sortOrder = "asc";
      }
		document.form1.form_action.value = "Sort";
		document.form1.sortCol.value = colName;
		document.form1.sortType.value = sortOrder;

		document.form1.submit();
	}

   function popWindow(url, height, width, xpos, ypos, title, name) {
   		winOptions = 'toolbar=0,location=0,directories=1,screenx=' +  xpos + ',screeny='+ ypos + ',top='+ ypos +',left=' + xpos + ',status=1,menubar=1,scrollbars=1,resizable=1,width=' + width + ',height=' + height;
  		var temp = window.open(url, title, winOptions);
      temp.focus();
   }

   function confirmDelete( url ) {
      if( confirm("Are you sure you want to delete this record? (This action cannot be undone.)" ) ) {
         document.location = url;
      }
   }

   function confirmRemove(url) {
      if (confirm("Are you sure you want remove this admin?  The user's record will not be deleted." )) {
         document.location = url;
      }
   }

   function confirmRemoveSchool(url) {
      if (confirm("Are you sure you want remove this school? (This action cannot be undone.)" )) {
         document.location = url;
      }
   }
   
   function Set_Cookie(name,value,expires,path,domain,secure) {
       document.cookie = name + "=" +escape(value) +
           ( (expires) ? ";expires=" + expires.toGMTString() : "") +
           ( (path) ? ";path=" + path : "") +
           ( (domain) ? ";domain=" + domain : "") +
           ( (secure) ? ";secure" : "");
   }

	function setSort(theField) {
		if (document.form1.sortCol.value == theField) {
			if (document.form1.sortType.value == 'desc')
				document.form1.sortType.value = 'asc';
		 	else
				document.form1.sortType.value = 'desc';
		} else {
			document.form1.sortType.value = 'asc';
		}
		document.form1.sortCol.value = theField;
		document.form1.submit();
	}

	function confirmMakeMember(){
		if (confirm("Are you sure you want to make the selected trainees into members?  This action cannot be undone!")) {
			if (confirm("Are you really sure?")) {
				document.form1.createMemberButton.value = 'Create Member';
				document.form1.submit();
			}
		}
	}

   function memberSelectAll() {
      for( i = 0; i < document.form1.elements.length; i++ ) {
         var e = document.form1.elements[i];
         if ( e.name.indexOf('selectBox') == 0 ) {
            e.checked = true;
         }
      }
   }

   function memberSelectNone() {
      for( i = 0; i < document.form1.elements.length; i++ ) {
         var e = document.form1.elements[i];
         if ( e.name.indexOf('selectBox') == 0 ) {
            e.checked = false;
         }
      }
   }



	var dotsRun = 0;
	var dotsPref = '';
	var dotsRot = 0;
	var dotsList = '... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...';
	function dotsRunning() {
		if (dotsRun != 0) {
			if (document.getElementById(dotsRun)) {
				dotsRot--;
				if (dotsRot < 0) dotsRot = 21;
				document.getElementById(dotsRun).innerHTML = dotsPref+dotsList.substring(dotsRot, dotsList.length-1);
				setTimeout("dotsRunning()", 333);
			}
		}
		return true;
	}

	function startDots(divID, prefIN) {
		dotsRun = divID;
		dotsPref = prefIN;
		setTimeout("dotsRunning()", 333);
		return true;
	}

	function stopDots() {
		dotsRun = 0;
		return true;
	}
	
	
