var cnt=0;
var addressSubmit=0;
var addressCASubmit=0;


function LogOut()
{
  top.window.close();
}

function LoginPageLogOut()
{
  top.window.close();
}

function RefreshMnuPg()
{
  window.parent.frames("_mnu").location.reload();
  //window.parent._mnu.forms['frmMenu'].submit();
}

function CheckNumeric()
{

  if (window.event.keyCode > 58 || window.event.keyCode < 48 && window.event.keyCode != 13)
  {
    window.event.keyCode = 0;
  }

}

function CheckAlpha()
{

  if (window.event.keyCode > 48 || window.event.keyCode < 58 && window.event.keyCode != 13)
  {
    window.event.keyCode = 0;
  }

}


function checkForNumber(objSource, objArgs)
{
  var inputStr = objArgs.Value;
  inputStr = inputStr.toString();

  for (var i = 0; i < inputStr.length; i++)
  {
    var oneChar = inputStr.charAt(i)
    if (oneChar < "0" || oneChar > "9")
    {
      objArgs.IsValid = false;
      return;
    }
  }

  objArgs.IsValid = true;
  return;

}

function validate()
{

  if (document.activeElement.id != "ImgLogOut" && document.activeElement.id != "ImgClose") {

      if (cnt!=0) {
        alert("Please do not re-click the Submit button, this could result \nin the payment response not being displayed.");
        return false;
      }

      if (cnt==0 && Page_IsValid==true) {
        document.all("ImgClose").disabled = true;
        alert("Processing the payment may take a few seconds.");
        cnt+=1;
      }
  }
}

function calBillPayAmount(txtName)
{
    if (window.event.keyCode != 13) {

        var CCFeeAmt = document.getElementById('hdCCTransFee').value;

        if (CCFeeAmt != '0') {

            if ((txtName.id == 'txtPayDollar') || (txtName.id == 'txtPayCents')) {

                var tmpAmt = (document.getElementById('txtPayDollar').value + "." + calculateCent(document.getElementById('txtPayCents').value));
                
                tmpAmt = roundAmount(Number(tmpAmt) + Number(tmpAmt * CCFeeAmt/100)) + "";

                document.getElementById('txtDollar').value = tmpAmt.substring(0,tmpAmt.indexOf("."));
                document.getElementById('txtCents').value = calculateCent(tmpAmt.substring(Number(tmpAmt.indexOf(".")) + 1, Number(tmpAmt.indexOf(".")) + 3));
            }
            else {

                var tmpAmt = document.getElementById('txtDollar').value + "." + calculateCent(document.getElementById('txtCents').value);
                tmpAmt = roundAmount(tmpAmt / (1 + Number(CCFeeAmt/100))) + "";


                document.getElementById('txtPayDollar').value = tmpAmt.substring(0,tmpAmt.indexOf("."));
                document.getElementById('txtPayCents').value = calculateCent(tmpAmt.substring(Number(tmpAmt.indexOf(".")) + 1, Number(tmpAmt.indexOf(".")) + 3));
            }
        }
    }
}

function calculateCent(strCent)
{

    if (strCent.length == 0) {
        return "00";
    }
    else if(strCent.length == 1){
        return strCent + "0";
    }
    else {
        return strCent;
    }
}

function roundAmount(tmpAmt)
{
    // added this 0.00000...1 to fix the rounding bug 
    tmpAmt = tmpAmt + Number(0.000000000001);
    tmpAmt = Math.round(tmpAmt*100)/100 + "";

    if ((tmpAmt.indexOf(".") == -1) && (tmpAmt.length == 0)){
        return "0.00";
    }
    else if (tmpAmt.indexOf(".") == -1) {
        return tmpAmt + ".00";
    }
    else {
        return tmpAmt;
    }
}



function check(IsPostCodeAustralia)
{

    if(IsPostCodeAustralia)
    {
        if(document.all("hdFlag").value != document.all("txtPostCode").value)
        {
            document.all("ddlCountry").disabled = true;
        }

    }

}

function validateAddressSubmit()
{
  if(document.activeElement.id != "ImgCancel" ) {

      if (addressSubmit!=0) {
        alert("Please do not re-click the Modify button.");
        return false;
      }

      if (addressSubmit==0 && Page_IsValid==true) {
        document.all("ddlCountry").disabled = true;
        addressSubmit+=1;
      }

  }
}

function validateAddressCASubmit()
{
  if(document.activeElement.id != "ImgCancelCA" ) {

      if (addressCASubmit!=0) {
        alert("Please do not re-click the Modify button.");
        return false;
      }

      if (addressCASubmit==0 && Page_IsValid==true) {
        document.all("ddlCountryCA").disabled = true;
        addressCASubmit+=1;
      }

  }
}



function fnTrapKD(btn, event){

    if (document.all){

        if (event.keyCode == 13){
           event.returnValue=false;
           event.cancel = true;
           document.getElementById(btn).click();
        }

    }

    else if (document.getElementById){

        if (event.which == 13){
           event.returnValue=false;
           event.cancel = true;
           document.getElementById(btn).click();
        }

    }

    else if(document.layers){

        if(event.which == 13){
           event.returnValue=false;
           event.cancel = true;
           document.getElementById(btn).click();
        }

    }

}


