String.prototype.replaceAll = function(search, replace){
  return this.split(search).join(replace);
  //var re = new RegExp(search, "g")
  //return this.replace (re, replace);
  
}

function openPopup(url, name, width, height)
{
  var oTarget = window.open(url, name, 'scrollbars=yes, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=250, left=350');
  oTarget.focus();
  return false;
}

function openScrolledPopup(url, name, width, height)
{
  var oTarget = window.open(url, name, 'scrollbars=yes, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=250, left=350');
  oTarget.focus();
  return false;
}

function openScrolledPopupPos(url, name, width, height, xpos, ypos)
{
  var oTarget = window.open(url, name, 'scrollbars=yes, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=' + ypos + ', left=' + xpos);
  oTarget.focus();
  return false;
}

function openPopupNoScroll(url, name, width, height)
{
  var oTarget = window.open(url, name, 'scrollbars=no, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=250, left=350');
  oTarget.focus();
  return false;
}


function showErrorAlert(controlID, message)
{
  document.getElementById(controlID).select();
  document.getElementById(controlID).focus();
  alert(message);
  return false;
}

function ShowErrorSummary(sender, args)
{
  ValidatorUpdateIsValid();
  args.IsValid = Page_IsValid;
  if ( !Page_IsValid )
    alert("Not all the required fields have been comlpeted. Please check your data and re-submit.");
}

function GetSelectValue(controlID)
{
  return document.getElementById(controlID).options[document.getElementById(controlID).options.selectedIndex].value;
}

function nextFieldFocus(curObj, prevObj, nextObj, length, event)
{
  if( event.keyCode == '37' || event.keyCode == '39' )
  {
    return;
  }
  if(nextObj != null && curObj.value.length == length && event.keyCode != '9' && event.keyCode != '16')
  {
    nextObj.focus();
    nextObj.select();
  }
  if(event.keyCode == '8' && curObj.value.length == 0)
  {
    prevObj.focus();
    rng = prevObj.createTextRange(); 
    rng.collapse(false); 
    rng.select(); 
    prevObj.click(); 
  }
}


function newImage(arg) {
  if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;
  }
}

function changeImages() {
  if (document.images) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
    }
  }
}

//************************************************************* 
function Trim (str)  
{ 
  return RTrim(LTrim(str)); 
} 
//*************************************************************   
function LTrim (str) { 
var ret_str = str; 
for (var i=0; i<str.length; i++){ 
  if (str.charAt(i) == ' ') {;} 
  else  
  { 
    ret_str = str.substring(i); 
    return ret_str; 
  } 
} 
ret_str=''; 
return ret_str; 
} 
//************************************************************* 
function RTrim (str) { 
  var ret_str = str; 
  for (var i=(str.length-1); i>=0; i--) 
  { 
    if (str.charAt(i) == ' ') {;} 
    else  
    { 
      ret_str = str.substring(0,(i+1)); 
      return ret_str; 
    } 
  } 
  ret_str=''; 
  return ret_str; 
} 

function ShowPopupText(form,field)
{
  var url = "PopupText.aspx?form="+form+"&field=" + field;
  newwindow = window.open(url,'HelpPopup','height=150,width=400,scrollbars=yes,resizable=yes top=100 left=300');
  if (window.focus) {newwindow.focus()}
  
}

function GetCurrencyValue ( value )
{
	var r = new RegExp(",", "g");    
	var s = String(value);
	return s.replace(r, "");
}


function SetCurrencyValue( value )
{   
	var oldstr = Trim(GetCurrencyValue(String(value)));
	var indx = oldstr.indexOf( "." );
	var newstr;
	var beg;
	
	if (indx>=0)
	{
		newstr = oldstr.substring(indx);
		beg = indx;
	}
	else
	{
		newstr = "";
		beg = oldstr.length;
	}
	//alert("value="+value+"  indx="+indx +" newstr="+newstr);
	var threecount = 0;
	
	
	for(i = beg-1; i>=0; i--)
	{
			if (oldstr.charAt(i) != ",")
			{
					newstr = oldstr.charAt(i) + newstr;
			
					threecount++;
					if (threecount == 3)
					{
							if (i != 0)
									newstr = "," + newstr;
							threecount = 0;
					}
			}
	}
	return newstr;
}