NS4     = (document.layers);
IE4     = (document.all);
ver4    = (NS4 || IE4);
IE5     = (IE4 && navigator.appVersion.indexOf("5.")!=-1);
isMac   = (navigator.appVersion.indexOf("Mac") != -1);
isMenu  = (NS4 || (IE4 && !isMac) || (IE5 && isMac));


function ltrim (aStr, c){
	var tempStr = aStr;
	while ((tempStr.length > 0) && (tempStr.charAt(0)==c))
		  {tempStr = tempStr.substring(1);}
		  
	return tempStr;

} // end



function lpad (aStr, c, len){
	var tempStr = aStr;
	while (tempStr.length < len)
		{tempStr = c + tempStr;}
			
	return tempStr;

} // end


function trim(val) {
    return rTrim(lTrim(val));
}

function lTrim(val) { // Trim leading spaces
    while( '' + val.charAt(0)==' ' ) {
        val = val.substring(1,val.length);
    }
    return val;
} // end

function rTrim(val) {	// Trim trailing spaces
    while( '' + val.charAt(val.length-1)==' ') {
        val = val.substring(0,val.length-1)
    }
    return val;
} // end

function redirect( location ){
    window.location = location;
} // end


function trimzero(val) {
    return rTrimzero(lTrimzero(val));
} // end

function lTrimzero(val) { // Trim leading zeroes
    while( '' + val.charAt(0)=='0' ) {
        val = val.substring(1,val.length);
    }
    return val;
} // end

function rTrimzero(val) {	// Trim trailing zeroes
    while( '' + val.charAt(val.length-1)=='0') {
        val = val.substring(0,val.length-1)
    }
    return val;
} // end

function popUp( loc, w, h, menubar, thisWindow ) {
    if( w == null ) { w = 500; }
    if( h == null ) { h = 350; }
    menubar = "";
    
    if( NS4 ) { w += 50; }
    // Need the var or else IE4 blows up not recognizing editorWin
    thisWindow = window.open(loc, thisWindow, menubar + 'resizable,scrollbars,statusbars,width=' + w + ',height=' + h);
    //if( !newWin.opener )
    //newWin.opener = window;
    thisWindow.focus(); //causing intermittent errors
} // end

function popUpLarge( loc, menubar ) {
    if( menubar == null ) { menubar = false; }
    popUp( loc, 700, 500, menubar );
} // end

function closeMe() {
    parent.close();
} // end


//returns true if e-mail is no good
function notEmailAddress(jsObject, jsObjectText){
    
    // Note: The next expression must be all on one line...
    //       allow no spaces, linefeeds, or carriage returns!
    if  (jsObject.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi) == null){
        alert(jsObjectText);
        jsObject.focus();
        return(true);
    }
    else {
        return(false);
    }
} // end


//returns true if not a valid phone number
function notPhoneNumber(jsObject, jsObjectText) {
    var GoodChars = "0123456789()-+ ";
    var i = 0;
    
    for (i =0; i <= jsObject.length -1; i++) {
        if (GoodChars.indexOf(jsObject.charAt(i)) == -1) {
            alert(jsObjectText);
            jsObject.focus();
            return(true);
        } // End if statement
        
    } // End for loop
    
    return(false);
} // end

//returns true if field contains spaces
function containsSpaces(jsObject, jsObjectText){
    var badChars = " ";
    var i = 0;
    
    for (i =0; i <= jsObject.length -1; i++) {
        if (badChars.indexOf(jsObject.charAt(i)) != -1) {
            alert(jsObjectText);
            jsObject.focus();
            return(true);
        } // End if statement
        
    } // End for loop
    
    return(false);
} // end



// Returns true if field is empty or if user has actually entered the
// word "null"

function isEmpty(jsObject, jsObjectText){
    if ((jsObject.value == '') || (jsObject.value.match(/\w/g) == null)){
        alert(jsObjectText);
        jsObject.focus();
        return(true); 
	}
    var trimmed = trim(jsObject.value);
    trimmed = trimmed.toLowerCase();
    if (trimmed == "null"){
        alert("Value of null is not allowed");
        jsObject.focus();
        return(true); 
	}
    
    return(false);
    
} // end

// Returns true if none selected
function isNotSelected(jsObject, jsObjectText){
    if (jsObject.options[0].selected){
        alert(jsObjectText);
        jsObject.focus();
        return(true);
    }
    else{
        return(false);
    }
} // end

// Returns true if not checked
function isChecked(jsObject, jsObjectText){
    if (! jsObject.checked){
        alert(jsObjectText);
        return(false);
    }else{
        return(true);
    }
} // end


// Returns true if not numeric
function isNotNumeric(jsObject, jsObjectText){
    if (isNaN(jsObject.value)){
        alert(jsObjectText);
        jsObject.focus();
        return(true);
    }
    else{
        return(false);
    }
} // end


//figure out what the last day of any month is
function calcLastDay(month,year) {
    if ((month==1) && ((year%4)==0))
        return 29;
    
    if ((month==1) && ((year%4)!=0))
        return 28;
    
    if ((month==0) || (month == 2) || (month == 4) || (month == 6) ||
    (month==7) || (month == 9) || (month ==11))
        return 31;
    
    return 30;
} // end

//javascript y2k fix
function y2k(number) {
    return (number < 1000) ? number + 1900 : number;
} // end


//figure out the number of days between 2 dates
function daysElapsed(date1,date2) {
    
    var difference =
    Date.UTC(y2k(date1.getFullYear()),date1.getMonth(),date1.getDate(),0,0,0)
    - Date.UTC(y2k(date2.getFullYear()),date2.getMonth(),date2.getDate(),0,0,0);
    
    return difference/1000/60/60/24;
} // end

function confirmPrompt(message){
	if (confirm(message)){
			return(true);
	}else{
			return(false);	
	}
} // end

function closeWin(){
	window.close();
	opener.focus();
}

function openWindow(url){
	_openWindow(url,"theWindow", 800, 800, "yes", "yes");
}

function _openWindow(url, win, width, height, scroll, resize){
		var txt = "screenX=0,screenY=0,top=0,left=0,scrollbars="+scroll+",resizable="+resize+",status=no,width="+width+",height="+height;
        if(navigator.appName == "Netscape") {//moz
	        popWin = window.open(url,win,txt);
	        popWin.focus();
        }
        else{  //ie
	       if (navigator.userAgent.indexOf("MSIE") >= 0){ 
	           popWin = window.open(url,win,txt);
	           popWin.location.href = url;
	           //if (popWin.opener == null) popWin.opener = window; 
	           //popWin.opener.name = "opener";
			   popWin.focus();
	       }else{
	           var popWin = window.open(url,win,txt);
			   popWin.focus();
	       }
       }
}

function resizeWindow(height, width) {
	// window.resizeTo(height, width);
	if (parseInt(navigator.appVersion)>3) {
	if (navigator.appName=="Netscape") {
		top.outerWidth=width;
		top.outerHeight=height;
	}
	else top.resizeTo(width, height);
 }

}

function maximizeWindow(){
  if (window.screen){
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
  }
}

// Check that a string contains only letters and numbers
function isAlphanumeric(string) {
	if (string.search) {
		if ((string.search(/[^\w\s]/) != -1) || (string.search(/\W/) != -1)) return false;
	}
	return true;
}

function isValidLength(string, min, max) {
	if (string.length < min || string.length > max) {
		return false;
	}
	else {
		return true;
	}
}

// Retrieves rich text from control to the source element.
function getHTML(form){
	for (var i=0; i < form.elements.length; i++){
		var editorElement 		= form.elements[i];
		var editorElementName	= editorElement.name;
		// If there is an editor defined for this element
		var objEditorElement 	= document.getElementById(editorElementName + '_editor');
		if ((objEditorElement != null) && (objEditorElement != 'undefined')){
			var objSourceElement  = document.getElementById(editorElementName);
			if ((objSourceElement != 'undefined') && (objEditorElement != 'undefined')){
				objSourceElement.innerText = objEditorElement.docHtml;
			}
		}
	}
}

function mouseOver(imageName){
	var imgFileName;
	imgFileName = document.images[imageName].src;
	document.images[imageName].src = imgFileName.substr(0, (imgFileName.length - 4)) + '_mo.jpg';
}
 
function mouseOut(imageName){
	var imgFileName;
	imgFileName = document.images[imageName].src;
	document.images[imageName].src = imgFileName.substr(0, (imgFileName.length - 7)) + '.jpg';
}