﻿    function reportAjaxError(request) {
		alert('A Javascript/AJAX error occurred:\n' + request.statusText);
		//alert(request.responseText);
	}
	
		
	
	
	function markDirty() {
	    pageDirty=true;
	}
	
	function markClean(evt) {
	    pageDirty=false;
	    	    
	    if (!evt) var evt = window.event;
        if (evt.stopPropogation) {
            evt.stopPropogation();
        } else {
            evt.cancelBubble = true;
        }
	}
	
    	    	
	
	function doNothing() {
	}

    function rollon(img) {
        var s = img.src;
        s = s.replace("1.gif", "2.gif");
        s = s.replace("1.jpg", "2.jpg");
        img.src = s;
    }
    
    function rolloff(img) {
        var s = img.src;
        s = s.replace("2.gif", "1.gif");
        s = s.replace("2.jpg", "1.jpg");
        img.src = s;
    }
    
    function modalConfirm() {
        return confirm("are you sure?");
    }
    
    function isEmail(s) {
        if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
            return true;
        else
            return false;
    }
    
    function isDate(s) {
        if (s.search(/^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d/) != -1)
            return true;
        else
            return false;
    }    
    
    function alertDate(s) {
        if (isDate(s) == false) {
            alert("Please enter dates in mm.dd.yyyy format.");
        }
    }
    
    function toggleVisibility(e) {
        if ($(e).style.visibility == 'visible') {
            $(e).style.visible = 'hidden';
        } else {
            $(e).style.visibility = 'visible';
        }
    }
    
    function toggleDisplay(e) {
        if ($(e).style.display == 'inline') {            
            $(e).style.display = 'none';            
        } else {
            $(e).style.display = 'inline';           
        }
    }
    
    
    function toggle( targetId, overrideAction ){
	    if (document.getElementById){
		    target = document.getElementById( targetId );
    		
		    if (overrideAction == "on"){
			    target.style.display = "";
			    target.style.visibility = "visible";
		    } else if (overrideAction == "off") {
			    target.style.display = "none";
			    target.style.visibility = "hidden";
		    } else if (overrideAction == "block") {
			    target.style.display = "block";
			    target.style.visibility = "visible";
		    } else {
			    if (target.style.display == "none" || target.style.visibility == "hidden"){
				    target.style.display = "";
				    target.style.visibility = "visible";
			    } else {
				    target.style.display = "none";
				    target.style.visibility = "hidden";
			    }
		    }
	    }
    }

    
    function trimString(sInString) {
       sInString = sInString.replace( /^\s+/g, "" );// strip leading
       return sInString.replace( /\s+$/g, "" );// strip trailing
    }
    
    
    
    // return the value of the radio button that is checked
    // return an empty string if none are checked, or
    // there are no radio buttons
    function getRadioCheckedValue(radioObj) {
	    if(!radioObj)
    		return "";
	    var radioLength = radioObj.length;
	    if(radioLength == undefined)
		    if(radioObj.checked)
    			return radioObj.value;
	    	else
		    	return "";
	    for(var i = 0; i < radioLength; i++) {
		    if(radioObj[i].checked) {
			    return radioObj[i].value;
		    }
	    }
	    return "";
    }


    // set the radio button with the given value as being checked
    // do nothing if there are no radio buttons
    // if the given value does not exist, all the radio buttons
    // are reset to unchecked
    function setRadioCheckedValue(radioObj, newValue) {
	    if(!radioObj)
		    return;
	    var radioLength = radioObj.length;
	    if(radioLength == undefined) {
		    radioObj.checked = (radioObj.value == newValue.toString());
		    return;
	    }
	    for(var i = 0; i < radioLength; i++) {
		    radioObj[i].checked = false;
		    if(radioObj[i].value == newValue.toString()) {
    			radioObj[i].checked = true;
	    	}
	    }
    }
    
    
    

            
function removeCommas( strValue ) {
/************************************************
DESCRIPTION: Removes commas from source string.

PARAMETERS:
  strValue - Source string from which commas will
    be removed;

RETURNS: Source string with commas removed.
*************************************************/
  var objRegExp = /,/g; //search for commas globally

  //replace all matches with empty strings
  return strValue.replace(objRegExp,'');
}

function addCommas( strValue ) {
/************************************************
DESCRIPTION: Inserts commas into numeric string.

PARAMETERS:
  strValue - source string containing commas.

RETURNS: String modified with comma grouping if
  source was all numeric, otherwise source is
  returned.

REMARKS: Used with integers or numbers with
  2 or less decimal places.
*************************************************/
  var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');

    //check for match to search criteria
    while(objRegExp.test(strValue)) {
       //replace original string with first group match,
       //a comma, then second group match
       strValue = strValue.replace(objRegExp, '$1,$2');
    }
  return strValue;
}





function return2br(dataStr) {
    return dataStr.replace(/(\r\n|\r|\n)/g, "<br />");
}


function br2return(dataStr) {
    var s = dataStr;
    s = replace("<br>", "\n");
    s = replace("<br />", "\n");  
    return(s);     
}

function addtext(message,targetDiv){
    if (document.createTextNode){
        toggle(targetDiv, 'on');
        var mytext=document.createTextNode(message);
        document.getElementById(targetDiv).appendChild(mytext);
    }
}