var request = false;
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = false;
    }
  }
}

if (!request)
{
  alert2("Error initializing XMLHttpRequest!");
}
function getRootPath() {
    var strFullPath = window.document.location.href;
    var strPath = window.document.location.pathname;
    var pos = strFullPath.indexOf(strPath);
    var prePath = strFullPath.substring(0, pos);
    var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
    return (postPath);
}
function product_xuan(peizhiid, id, value,product_id) {
    var beizhu = document.getElementById("beizhu").value;
    var url = "/inc/product_ajax.aspx?peizhiid=" + escape(peizhiid) + "&id=" + escape(id) + "&value=" + escape(value) + "&beizhu=" + escape(beizhu) + "&product_id=" + escape(product_id) + "&sid=" + Math.random();
    //document.write(url);
   //document.getElementById("shuoming").innerHTML = url;
	        request.open("GET", url, true);
            request.onreadystatechange = loadPage;
            request.send(null);

	  }

    function loadPage() {
	        if (request.readyState == 4) 
			{
		   if (request.status == 200) 
		   {
			   	if(request.responseText!="")
				{
				    var response = request.responseText.split("|");

					if (parseFloat(response[1]) > 0) {
					    document.getElementById("jiage_view").innerHTML = response[1] + "~" + response[2];
					    document.getElementById("jiage").value = response[1] + "~" + response[2];
					}
					else {
					    document.getElementById("jiage_view").innerHTML = response[2];
					    document.getElementById("jiage").value = response[2];
                    }
                    document.getElementById("beizhu").value=response[0];
                    document.getElementById("kucun").innerHTML = response[3];
				}
			
		   }
     

   }
   }


   //购物车的js
   function set_cart(id, g1, peizhiid) {

       var shuliang = document.getElementById("shuliang").innerHTML;
       var beizhu = document.getElementById("beizhu").value;
        var jiage = document.getElementById("jiage").value;
        if (beizhu == "") {
            alert2("请选择颜色或者尺寸");
            return false;
        }

        var url = "/inc/set_cart.aspx?id=" + id + "&shuliang=" + shuliang + "&jiage=" + jiage + "&beizhu=" + escape(beizhu) + "&type=" + escape(g1) + "&sid=" + Math.random();
     //  document.write(url);
       request.open("GET", url, true);
       request.onreadystatechange = ajax_loadPage;
       request.send(null);


   }

   function ajax_loadPage() {
       if (request.readyState == 4) {
           if (request.status == 200) {
               if (request.responseText != "") {
                   var response = request.responseText.split("{fzw:next}");
                   if (response == "err") {
                       alert2("请先登录");
                       window.location.href = "default.aspx?login&tipurl=" + window.location.href.replace("&", "fzw123");
                       window.event.returnValue = false;
                   }
                   else {
                       if (response[1] == "1") {
                           window.location = "/pay/cart.aspx";
                           window.event.returnValue = false;
                       }
                       else {
                           // document.getElementById("order_count").innerHTML = response[0];
                           alert2("加入购物车成功");
                       }
                   }

               }

           }


       }
   }
   //end