if (window.XMLHttpRequest) {
	var xmlHttp = new XMLHttpRequest();

	if (xmlHttp.readyState == null) {
		xmlHttp.readyState = 1;
	}

}
if (window.ActiveXObject) {
	var xmlHttp = new ActiveXObject("MsXml2.XmlHttp");
}

function get_print_xmlhttp(obj,aurl) {
    var async = true;
	var rmsg = ''
	xmlHttp.open("GET",aurl, async);

   xmlHttp.onreadystatechange = function () {
      if (xmlHttp.readyState == 4) {
		obj.innerHTML=xmlHttp.responseText;
      }
   }
	xmlHttp.send(null);
    if (xmlHttp.readyState == null) {
        xmlHttp.readyState = 1;
    }

}


function get_cart_xmlhttp(d,aurl) {
    var async = true;
	var rmsg = ''
	xmlHttp.open("GET",aurl, async);

   xmlHttp.onreadystatechange = function () {
      if (xmlHttp.readyState == 4) {
		d.innerHTML=xmlHttp.responseText;
      }
   }
	xmlHttp.send(null);
    if (xmlHttp.readyState == null) {
        xmlHttp.readyState = 1;
    }

}


function get_cart_xmlhttp2(d,aurl) {

    var async = true;
	var rmsg = ''
	xmlHttp.open("POST",aurl, false);


   xmlHttp.onreadystatechange = function () {
      if (xmlHttp.readyState == 4 && xmlHttp.status == 200 && xmlHttp.statusText=='OK') {
		d.innerHTML=xmlHttp.responseText;
      }
   }
	xmlHttp.send(null);
	d.innerHTML=xmlHttp.responseText;
}

function get_coupon_check(aurl) {

    var async = true;
	var rmsg = ''
	xmlHttp.open("GET",aurl, async);

   xmlHttp.onreadystatechange = function () {
      if (xmlHttp.readyState == 4) {
		check_payment(xmlHttp.responseText);

      }
   }
	xmlHttp.send(null);
    if (xmlHttp.readyState == null) {
        xmlHttp.readyState = 1;
    }
}

function number_format(inputNum, decimals) {

	decimals=2;
    var new_number_str = '';
    var i, number_info, number_info_int, len;
    var number_str = String(inputNum);
    if(isNaN(number_str)) number_str = de_number_format(number_str );

    number_info = number_str.split('.');
    number_info_int = number_info[0];
    if(number_info.length == 1){
        number_info[1] = "0";
    }
    if (decimals != null ) {
        if (decimals > 0){
            new_number_str = String(Math.round(Number('1.' +number_info[1]) * Math.pow(10, decimals)) );
            new_number_str = '.' + new_number_str.substring(1,new_number_str.length);
        }else if (decimals < 0) {
            number_info_int = String(Math.round(Number(number_info[0]) / Math.pow(10, decimals *(-1))) *Math.pow(10, decimals*(-1)));
        }
    }
    len = number_info_int.length;
    for (i = len; i >= 0; i--) {
        if ( (len - i) > 1 && (len - i) % 3 == 1 ) {
            if(number_info_int.substring(i, i+1) != '-'){
                new_number_str = ',' + new_number_str;
            }
        }
        new_number_str = number_info_int.substring(i, i+1) +  new_number_str;
    }
    return new_number_str;
}
function de_number_format(inputStr){
    var arr = inputStr.toString().split(",");
    var returnStr = '';
    for (var i = 0 ; i < arr.length ; i++){
        returnStr += arr[i]+'';
    }
    return returnStr;
}


function get_ship_price(aurl) {
    var async = true;
	var rmsg = ''
	xmlHttp.open("GET",aurl, async);

   xmlHttp.onreadystatechange = function () {
      if (xmlHttp.readyState == 4) {
		  var rtxt = xmlHttp.responseText;
		  if (rtxt!='')
		  {
			  var rarray=rtxt.split('|');
			  document.getElementById('price_ship1').innerHTML=rarray[0];
			  document.getElementById('price_ship2').innerHTML=rarray[1];
			  document.getElementById('price_ship3').innerHTML=rarray[2];
		  }
      }
   }
	xmlHttp.send(null);
    if (xmlHttp.readyState == null) {
        xmlHttp.readyState = 1;
    }

}

function get_ship_price_upsxml(aurl) {
    var async = true;
    var rmsg = '';
    var replhtml = '<table width="100%" border=0 cellpadding=0 cellspacing=0>' + "\n";
        // we are going to build a complete replacement table.
    xmlHttp.open("GET",aurl, async);

    xmlHttp.onreadystatechange = function () {
      if (xmlHttp.readyState == 4) {
          var rtxt = xmlHttp.responseText;
          if (rtxt!='')
          {
              var rarray=rtxt.split('|');
              var limit=rarray.length;

              for (var i=1; i<limit; i=i+3)
              {
                replhtml = replhtml + '<tr>' + "\n";
                replhtml = replhtml + '<td ><span id="meth_ship' + i + '">' + rarray[i-1] + '</span></td>' + "\n";
                replhtml = replhtml + '<td >$ <span id="price_ship' + i + '">' + rarray[i] + '</span></td>' + "\n";
                replhtml = replhtml + '<td><font class=vsfont>&nbsp;&nbsp;<input type="radio" value="' + rarray[i+1] + '" name="ship_method" id="ship_method" class=ninput></font></td>' + "\n";
                replhtml = replhtml + '</tr>' + "\n";
              }
              replhtml = replhtml + '</table>' + "\n";
              document.getElementById('shiptable').innerHTML=replhtml;
         }
      }
   }
    xmlHttp.send(null);
    if (xmlHttp.readyState == null) {
        xmlHttp.readyState = 1;
    }

}
