/*-----------------------------------------------------------------------------+
 |    $Copyright    2000-2004 168now.com. ALL RIGHTS RESERVED.  $              |
 |    $Id: wwf_util.js,v 1.3 2004/03/05 09:17:19 klou Exp $                    |
 |    This file contains common utility functions.                             |
 |                                                                             | 
 |    15-SEP-2002 KLOU 1. Add function money().                                |
 |    03-MAR-2004 KLOU 1. Add onKeyPress handler for quick search.             |
 |    04-MAR-2004 KLOU 1. Remove onKeyPress handler for quick search.          |
 +-----------------------------------------------------------------------------*/

//document.quick_search.searchingString.onkeypress = keyhandler;
function skipTo(selectSrc, formName) {
//this function is for skip to the screen in the selected value
//It assumes that the selected value is the URL
//e.g. order_sum.php/pOrderStatus=N&pStartIdx=0&pNumOfRows=10

        var i = selectSrc.selectedIndex;
        var goToURL = selectSrc.options[i].value;
        formName.action=goToURL;
        formName.submit();

 }

function goToURL(formName, parameterName, selectSrc, destParameterValue) {
//This function takes a form name and add parameterName=destParamterValue
//If destParameterValue is null, then parameterName=selectSrc.value
//to formName.action.
//NOTE: selectSrc and destParameteValue cannot be null at the same time
//e.g: original formName.action is "order_sum.php"
//and parameterName="pOrderStatus", selectSrc.value="I"
//The new action will be "order_sum.php?pOrderStatus=I"

    if (destParameterValue==null) {
        var i = selectSrc.selectedIndex;
        var parameterValue= selectSrc.options[i].value;
    }
    else {
        parameterValue = destParameterValue;
    }

    var oldURL=formName.action;

    if (parameterValue==null || parameterValue == "") {
        formName.action=oldURL + "?" + parameterName + "=N";

    }
    else {
       formName.action=oldURL + "?" + parameterName + "=" + parameterValue;
    }

    formName.submit();
}

function newOrderForm(formName) {

    formName.submit();

}


function round(x) {
  // return Math.round(x*100)/100;
  return money(x);
}

function clearText(textField) {
//This function clear the values of the given textObject
     // alert ("in");
     textField.value ="";
}


var nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4));
function openWin(n, u, w, h, x)
{
   if (nav4) {
    left2 = window.screenX + ((window.outerWidth - w) / 2);
    top2 = window.screenY +  ((window.outerHeight - h) / 2);
    attr = 'screenX=' + left2 + ',screenY=' + top2;
  } else {
    left2 = (screen.width - w) / 2;
    top2 = (screen.height - h) / 2;
    attr = 'left=' + left2 + ',top=' + top2;
  }

   args = attr + ',width=' + w + ',height=' + h +
    ',resizable=yes,scrollbars=yes,status=0';
    
  remote = window.open(u, n, args);

  if (remote != null)
  {
    if (remote.opener == null)
      remote.opener = self;
  }

  if (x == 1)
  {
    return remote;
  }
}

function money(x) {
	 wholeNum = Math.floor(x*100+0.50);
	 decimals = wholeNum%100;
	// alert("decimals is " + decimals);
	 if(decimals<10) decimals = "0" + decimals;
	 wholeNum = Math.floor(wholeNum/100).toString();
  	 return wholeNum + '.'+decimals;
}
