// JavaScript Document
function sure(are) {
  return confirm(are);
}

function popup(url, wname, w, h, features) {
	if(features.length > 0)
		features = ","+features;	
		
	if (document.all)
	  var xMax = screen.width, yMax = screen.height;//properties of IE

	if (document.layers)
	  var xMax = window.outerWidth, yMax = window.outerHeight;
	  //properties of Netscape

	var xOffset = (xMax - w)/2, yOffset = (yMax - h)/2;
	// center co-ordinates

	//screenX and screenY are properties of Netscape for centering window,
	//InternetExplorer uses top and left properties.

	var browserName = navigator.userAgent.toLowerCase();
	if( browserName.indexOf ("aol") != -1 )
	{
		var properties = "height="+h+",width="+w+features;
	}
	else
	{
		if(navigator.appName.toLowerCase().indexOf("microsoft") != -1){
		    var properties="height="+h+",width="+w+",top="+yOffset+",left="+xOffset+features		    
		}
		if(navigator.appName.toLowerCase().indexOf("netscape") != -1){
		    var properties="height="+h+",width="+w+",screenX="+xOffset+",screenY="+yOffset+features
		}
     }                         
     var wind = window.open(url, wname, properties)
        
     if(wind != null) {
       wind.focus();
       }                       
}
function showhide(i,id) {
	if (i.src=='http://www.salvex.com/images/icon/minus.gif') {i.src='http://www.salvex.com/images/icon/plus.gif';}
	else {i.src='http://www.salvex.com/images/icon/minus.gif'}
	if (document.getElementById(id).style.display=='none') {document.getElementById(id).style.display='inline';}
	else {document.getElementById(id).style.display='none';}
}
function formatDate(inputElement)
{
    var dateTxt = inputElement.value;
    if (dateTxt.charCodeAt(dateTxt.length-1) == "160")
      dateTxt = dateTxt.substr(0,dateTxt.length-1);

    var testDate=new Date(Date.parse(dateTxt));
    if (!testDate.getYear())
       inputElement.value = '';
    else if (inputElement.value.substr(inputElement.value.length-3,1) == '/' ||
            inputElement.value.substr(inputElement.value.length-3,1) == '\\' ||
            inputElement.value.substr(inputElement.value.length-3,1) == '-')
    {  inputElement.value = (testDate.getMonth()+1) + "/" + testDate.getDate() + "/"
                    + (Math.floor(new Date().getFullYear() / 1000) * 1000 + testDate.getFullYear() - 1900)
    }else {
      inputElement.value = (testDate.getMonth()+1) + "/" + testDate.getDate() + "/" + testDate.getFullYear();
    }

}
function strToDbl(str,decimals)
{ str = str.replace(/\%|\$|\,/g,'')
  var num = 0
  if (!isNaN(parseFloat(str)))
    num = parseFloat(str);

  if (!decimals) {
  	return num;
  }else{
	  if (   isNaN( parseInt(decimals) )   ) decimals = 2;
	  num = Math.floor( num * Math.pow(10,decimals) + 0.50000000001 );
	  cents = num % Math.pow(10,decimals);
  	  num = Math.floor( num / Math.pow(10,decimals) ).toString();
	  for (var i = decimals - 1; i > 0; i--)
		if (cents < Math.pow(10,i) )
		  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) );
	
	  return (num + (decimals > 0 ? '.' + cents: ''));
  }
}
function formatCurrency(num, decimals)
{
  if (   isNaN( parseInt(decimals) )   ) decimals = 2;

  num = num.toString().replace(/\$|\,/g,'');

  if(isNaN(num)) num = "0";

  sign = (   num == ( num = Math.abs(num) )   );
  num = Math.floor( num * Math.pow(10,decimals) + 0.50000000001 );
  cents = num % Math.pow(10,decimals);
  num = Math.floor( num / Math.pow(10,decimals) ).toString();

  for (var i = decimals - 1; i > 0; i--)
    if (cents < Math.pow(10,i) )
      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) );

  return (   ( sign ? '' : '(' ) + '$' + num + (decimals > 0 ? '.' + cents: '') + ( sign ? '' : ')' )  );
}


