function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function replace(string,text,by) 
{
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) 
		return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) 
		return string;
	if (i == -1) 
		return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength)
		newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

function selectedTblData(obj)
{
	 var oTR = obj.parentNode.parentNode;
	 if (obj.checked)
	 {
	      oTR.className = 'lstdataselected';
	      oTR.id = "ignore";
	 }
	 else
	 {
	     oTR.className = 'lstdata';
	     oTR.id = "";
	 }
}

function checkedAll(checked, form)
{
	for (i = 0; i < form.elements.length; i++)
  	{
    	var item = form.elements[i];
		if (item.name.indexOf("isChecked") != -1)
		{
      		item.checked = checked;
      		var oTR = item.parentNode.parentNode;

      		if (checked)
      		{
            	oTR.className = 'lstdataselected';
            	oTR.id = "ignore";
        	}
        	else
        	{
            	oTR.className = 'lstdata';
            	oTR.id = "";
          	}
    	}
  	}
}

function disableAllButton(form)
{
   for (var n=0; n < form.elements.length; n++)
   {
       if (form.elements[n].type == "button" || form.elements[n].type == "submit")
       {
        	form.elements[n].disabled = "true";
       }         
   }
}

// Whole Row highligt script -- Wilsen
var highlightbehavior="TR"

var ns6=document.getElementById&&!document.all
var ie=document.all

var highlightcolor = 'highlightedrow'
var originalcolor = 'highlightedorig'

function changeto(e)
{
	source=ie? event.srcElement : e.target
	if (source.tagName=="TABLE")
	return
	while(source.tagName!=highlightbehavior && source.tagName!="HTML")
	source=ns6? source.parentNode : source.parentElement
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
	source.className="highlightedrow"
}

function contains_ns6(master, slave) 
{ 
	//check if slave is contained by master
	while (slave.parentNode)
	if ((slave = slave.parentNode) == master)
	return true;
	return false;
}

function changeback(e)
{
	if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
	return
	else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
	return
	if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
	source.className="lstdata"
}


// Function to manipulation of <Select> Object
function setSelectOption(selObj, val)
{
	if (selObj != null)
	{
		for(var i=0; i < selObj.options.length; i++)
		{	
			if (val == selObj.options[i].value)
			{
				selObj.options[i].selected = true;
				break;
			}
		}	
	}		
}

function addSelectOption(selObj, newVal, newDescr)
{
  if (newVal != '' && selObj != null)  
  {
   		var tmpval;
		var boxLength = selObj.length;
		var isnew = true;
		for (i = 0; i < boxLength; i++) 
		{
			tmpval = selObj.options[i].value;

			if (tmpval == newVal) 
				isnew = false;
		}
		
		if (isnew)
		{
	   		var newoption = new Option(newDescr, newVal, false, false);
	   		selObj.options[boxLength] = newoption;
		}
	}
}


function waitFor(milliseconds) 
{
	date = new Date();
	var curDate = null;
	
	do { var curDate = new Date(); } 
	while(curDate-date < milliseconds);
} 

function nextDay(obj)
{
	var date = obj.value;
	var day = date.substring(0,date.indexOf('/'));
	var mth = date.substring(date.indexOf('/')+1,date.lastIndexOf('/'));
	var yr = date.substring(date.lastIndexOf('/')+1);
	
	var idate = new Date(yr, mth-1, day);
	var newdate = new Date(yr, mth-1, day);
	newdate.setDate(idate.getDate()+1);
	
	obj.value = padout(newdate.getDate()) + '/' + padout(newdate.getMonth()+1) + '/' + y2k(newdate.getYear());
}

function backDay(obj)
{
	var date = obj.value;
	var day = date.substring(0,date.indexOf('/'));
	var mth = date.substring(date.indexOf('/')+1,date.lastIndexOf('/'));
	var yr = date.substring(date.lastIndexOf('/')+1);
	
	var idate = new Date(yr, mth-1, day);
	var newdate = new Date(yr, mth-1, day);
	newdate.setDate(idate.getDate()-1);
	
	obj.value = padout(newdate.getDate()) + '/' + padout(newdate.getMonth()+1) + '/' + y2k(newdate.getYear());
}

function padout(number) { return (number < 10) ? '0' + number : number; }

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function formatDt(i, delKey,direction) {
   if (i.value.length < 10) 
   {
      if (delKey!=9) { //tab
         if (delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41)) {
            //if the delete, backspace, shift, are not the keys that caused the keyup event.
            var fieldLen = i.value.length

            if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) {
               if (fieldLen == 2 || fieldLen == 5) {
                  i.value = i.value + "/";
               }
            }
            else {
               if (direction == "up") {
                  if (i.value.length == 0) {
                     i.value = ""
                  }
                  else {
                     i.value = i.value.substring(0,i.value.length-1)
                  }
               }
            }
  	    i.focus()
         }
      }
   }
}

function showHideDiv(objId, thisVal, matchVal)
{
	  if (document.layers) 
	  {
		  if (thisVal == matchVal)
			 document.layers[id].visibility = "show";
		  else
			 document.layers[id].visibility = "hide";
	  }
	  else if (document.all) 
	  {
	  	if (thisVal == matchVal)
		   document.all[id].style.display = "";
		else
		   document.all[id].style.display = "none";
	  }
	  else if (document.getElementById) 
	  {
		if (thisVal == matchVal)
		   document.getElementById(id).style.display = "";
		else
		   document.getElementById(id).style.display = "none";
	  }
}

function showHideDiv(id)
{
	  if (document.layers) 
	  {
		if (document.layers[id].visibility == "show")
		   document.layers[id].visibility = "hide";
		else
		   document.layers[id].visibility = "show";
	  }
	  else if (document.all) 
	  {
		if (document.all[id].style.display == "none")
		   document.all[id].style.display = "";
		else
		   document.all[id].style.display = "none";
	  }
	  else if (document.getElementById) 
	  {
		if (document.getElementById(id).style.display == "none")
		   document.getElementById(id).style.display = "";
		else
		   document.getElementById(id).style.display = "none";
	  }
}

function showDiv(id)
{
	  if (document.layers) 
	   	document.layers[id].visibility = "show";
	  else if (document.all) 
	   	document.all[id].style.display = "";
	  else if (document.getElementById) 
	   	document.getElementById(id).style.display = "";
}

function hideDiv(id)
{
	  if (document.layers) 
	   	document.layers[id].visibility = "hide";
	  else if (document.all) 
		document.all[id].style.display = "none";
	  else if (document.getElementById)
		document.getElementById(id).style.display = "none";
}

// 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 getCheckedValue(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 setCheckedValue(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 pagerSearch(url)
{
	document.forms[0].action = url;
	document.forms[0].submit();
}

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 99999;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';				 
  } else {
     dark.style.display='none';
  }
}
