function viewPopupImage(name,w,h)
{
    if (!w) w = 100;
    if (!h) h = 100;
    var delta_h = (isNaN(window.screenY) ? 30 : 55) + 28;
    var delta_w = 10 + 10;
    
    var Settings = "location=no, menubar=no, toolbar=no, status=1, scrollbars=no, resizable=no, width="+w+", height="+h+", left=200, top=100";
    var myWindow = window.open (null,null,Settings);
    myWindow.focus();
    
    myWindow.document.write ('<html><head><title>Centennial InterPort</title>\n<script language="javascript" type="text/javascript">\n<!--//\n'+
    'function ResizePopup(obj,dw,dh){\n'+
    'window.resizeTo(obj.width+dw, obj.height+dh);\n'+
    '}\n//-->\n'+
    '</script>\n</head><body style="margin:3px;background-color:#FFFFFF;" onClick="window.close();" ><center>'+
      '<img src="'+name+'" border="0" onload="ResizePopup(this,'+delta_w+','+delta_h+')">' +
      '</center></body></html>');
    myWindow.document.close();
}


function openPopup(url, name, width, height)
{
	return openPopup(url, name, width, height, null)
}

function openPopup(url, name, Height, Width, sFeatures)
{
	var Top = Math.round((screen.availHeight-Height)/2);
	var Left = Math.round((screen.availWidth-Width)/2);
	
	if (sFeatures == null)
		sFeatures = 'status=no, toolbar=no, menubar=no, location=no, scrollbars=yes, channelmode=no, directories=no, resizable=yes';

	sFeatures = 'height='+Height+',width='+Width+', top='+Top+', left='+Left+', ' + sFeatures;

	var w=window.open(url, name, sFeatures);
	w.focus();
	return w;
}

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 HideControl( id )
{
	document.getElementById( id ).style.display = 'none';
}

function ShowControl( id )
{
	document.getElementById( id ).style.display = 'inline';
}

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 RowIllyminate(obj, Class)
{
	obj.className = Class;
}

//*************************************************************
function SetCurrencyValue(value) {

    return formatCurrency(value);
}

function AddCommasToNumber(number)
{
    number = '' + number;
    if (number.length > 3) 
    {
        var mod = number.length % 3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length / 3); i++) {
        if ((mod == 0) && (i == 0))
            output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
        else
            output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
    }
        return (output);
    }
    else return number;
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if(isNaN(num))
        num = "0"
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '' + num.substring(num.length - (4 * i + 3));
        //num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
    
    num = AddCommasToNumber(num);
    
    return (((sign) ? '' : '-') + '' + num + '.' + cents);
    //return (((sign) ? '' : '-') + '$' + num + '.' + cents);
}

function GetCurrencyValue ( value )
{
	var r = new RegExp(",", "g");    
	var s = String(value);
	return s.replace(r, "");
}


function OldSetCurrencyValue( value_old )
{   
    var value = Math.round(value_old*100)/100;
	var oldstr = Trim(GetCurrencyValue(String(value)));
	var indx = oldstr.indexOf( "." )-1;
	var newstr;
	var beg;
	var sign_val = '';
	if(oldstr.indexOf("-")!=-1)
	{
	    oldstr = oldstr.substring(1);
	    sign_val='-';
	}
	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 sign_val+newstr;
}

function IsInt(s)
{
  var rePosInt1, rePosInt2;
  rePosInt1=/^\s+$/;
  rePosInt2=/^\s*[\-\+]?[0-9]+\s*$/;
  if(rePosInt1.test(s)) return false;
  if(!rePosInt2.test(s)) return false;
  return true;
}

function addEvent(elm, evType, fn, useCapture) 
{
        if (elm.addEventListener) {
                elm.addEventListener(evType, fn, useCapture);
        return true;
        }
        else if (elm.attachEvent) {
                var r = elm.attachEvent('on' + evType, fn);
                return r;
        }
        else {
                elm['on' + evType] = fn;
        }
}



