function twoDigits(d) {
    if(0 <= d && d < 10) return "0" + d.toString();
    if(-10 < d && d < 0) return "-0" + (-1*d).toString();
    return d.toString();
}
Date.prototype.toMysqlFormat = function() {
    return this.getUTCFullYear() + "-" + twoDigits(1 + this.getUTCMonth()) + "-" + twoDigits(this.getUTCDate()) + " " + twoDigits(this.getUTCHours()) + ":" + twoDigits(this.getUTCMinutes()) + ":" + twoDigits(this.getUTCSeconds());
};

function strrev(str) {
   if (!str) return '';
   var revstr='';
   for (i = str.length-1; i>=0; i--)
       revstr+=str.charAt(i)
   return revstr;
}

function rollover() {
  if (!document.getElementById) return
  var imgOrSrc;
  var imgPreload = new Array();
  var images = document.getElementsByTagName('img');
  for (var i = 0; i < images.length; i++) {
    if (images[i].getAttribute('rsrc')) {
      imgPreload[i] = new Image();
      imgPreload[i].src = images[i].getAttribute('rsrc');
      images[i].onmouseover = function() {
        imgOrSrc = this.getAttribute('src');
        this.setAttribute('src',this.getAttribute('rsrc'))
      }
      images[i].onmouseout = function() {
        this.setAttribute('src',imgOrSrc)
      }
    }
  }
  var images = document.getElementsByTagName('input');
  for (var i = 0; i < images.length; i++) {
    if (images[i].getAttribute('rsrc')) {
      imgPreload[i] = new Image();
      imgPreload[i].src = images[i].getAttribute('rsrc');
      images[i].onmouseover = function() {
        imgOrSrc = this.getAttribute('src');
        this.setAttribute('src',this.getAttribute('rsrc'))
      }
      images[i].onmouseout = function() {
        this.setAttribute('src',imgOrSrc)
      }
    }
  }
}

function Pause(millisecs)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millisecs);
}

function AttachFile( p_script_url ) {
    script = document.createElement( 'script' );
    script.src = p_script_url;
    document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function PriceScriptNew(l,y,n) {
    var DefaultExpireDays = 370;
    var YearlyExpireDays = 365;
    f = document.OrderForm;
    dt = '';
    var today = new Date();
    var promoExpire = new Date("02/28/2012");
    var nextPromoStart = new Date("11/18/2010");
    var nextPromoExpire = new Date("01/08/2011");
    var PriceEn = 499.00;
    var PriceEnSale = 399.00;
    var PriceEnSp = 998.00;
    var PriceEnSpSale = 598.00;
    if ((today <= promoExpire) || ( (today <= nextPromoExpire) && (today >= nextPromoStart) )) { // **** Sale Price ****
      if (y == 1) {
        if (l == 'En/Sp') {
          t2 = n * y * PriceEnSpSale;
          dt = '(Sale: $' + PriceEnSpSale.toFixed(2) + '/user/yr)';
        } else {
          t2 = n * y * PriceEnSale;
          dt = '(Sale: $' + PriceEnSale.toFixed(2) + '/user/yr)';
        }
      } else if (y == 2) {
        dscText = "w/10% off";
        if (l == 'En/Sp') {
          PriceDscnt = PriceEnSpSale * 0.9;
          t2 = n * y * PriceDscnt;
          dt = '(Sale: $' + PriceDscnt.toFixed(2) + '/user/yr ' + dscText + ')';
        } else {
          PriceDscnt = PriceEnSale * 0.9;
          t2 = n * y * PriceDscnt;
          dt = '(Sale: $' + PriceDscnt.toFixed(2) + '/user/yr ' + dscText + ')';
        }
      } else if (y == 3) {
        dscText = "w/15% off";
        if (l == 'En/Sp') {
          PriceDscnt = PriceEnSpSale * 0.85;
          t2 = n * y * PriceDscnt;
          dt = '(Sale: $' + PriceDscnt.toFixed(2) + '/user/yr ' + dscText + ')';
        } else {
          PriceDscnt = PriceEnSale * 0.85;
          t2 = n * y * PriceDscnt;
          dt = '(Sale: $' + PriceDscnt.toFixed(2) + '/user/yr ' + dscText + ')';
        }
      } else { // 4+ years
        dscText = "w/20% off";
        if (l == 'En/Sp') {
          PriceDscnt = PriceEnSpSale * 0.8;
          t2 = n * y * PriceDscnt;
          dt = '(Sale: $' + PriceDscnt.toFixed(2) + '/user/yr ' + dscText + ')';
        } else {
          PriceDscnt = PriceEnSale * 0.8;
          t2 = n * y * PriceDscnt;
          dt = '(Sale: $' + PriceDscnt.toFixed(2) + '/user/yr ' + dscText + ')';
        }
      }
    } else {              // **** Regular Price ****
      if (y == 1) {
        if (l = 'En/Sp') {
          t2 = n * y * 998.00;
          dt = '($998/user/yr)';
        } else {
          t2 = n * y * 499.00;
          dt = '($499/user/yr)';
        }
      } else if (y == 2) {
        if (l == 'En/Sp') {
          t2 = n * y * 898.20;
          dt = '($898.20/user/yr)';
        } else {
          t2 = n * y * 449.10;
          dt = '($449.10/user/yr)';
        }
      } else if (y == 2) {
        if (l == 'En/Sp') {
          t2 = n * y * 848.30;
          dt = '($848.30/user/yr)';
        } else {
          t2 = n * y * 424.15;
          dt = '($424.15/user/yr)';
        }
      } else { //4+ years
        if (l == 'En/Sp') {
          t2 = n * y * 898.20;
          dt = '($898.20/user/yr)';
        } else {
          t2 = n * y * 449.10;
          dt = '($449.10/user/yr)';
        }
      }
    }

    d1 = f.Promo_Discount.value;
    if (!isNaN(d1)) d1 = Number(d1);
    if ( (d1 < 1.0) && (d1 > 0.0) ) {
        t2 = t2 * (1.0 - d1);
    } else if (d1 > 0.0) {
        t2 = t2 - (n * y * d1);
    }
    s = n.toString() + '-user ' + y.toString() + '-year ' + ' HLA software license [' + l + ']';
    f.Ord_Description.value = s;
    f.Ord_Descript2.value = dt;
    f.Ord_Amount.value = t2.toString();
    f.fullAmt.value = '$' + formatDecimal(t2.toString());
    f.fullDesc.value = s + '     ' + dt;
    f.Ord_Days.value = DefaultExpireDays + ( (y - 1) * YearlyExpireDays);
}

function strToFloat(s) {
var n = new Number(0);
t = s.replace(/\$|\,/g,'');
t = t.replace(/\$|\%/g,'');
if (!isNaN(t)) n = Number(t);
return n;
}

function formatDecimal(s) {
num=strToFloat(s);
if (num==0) {
    return '';
} else {
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    if(cents<10) cents = '0' + cents;
    num = Math.floor(num/100).toString();
    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 + '.' + cents);
}
}

function formatInteger(s) {
num=strToFloat(s);
if (num==0) {
    return '1';
} else {
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    num = Math.floor(num/100).toFixed(0);
    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);
}
}

