var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

var xmlHttp1 = false;
try {
  xmlHttp1 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp1 = false;
  }
}
if (!xmlHttp1 && typeof XMLHttpRequest != 'undefined') {
  xmlHttp1 = new XMLHttpRequest();
}
function EmptyBasket(){  
		fixedtooltip(document.getElementById("EmptyBasket"), "<b>确认清空全部商品吗？</b><br><input type=\"image\" onclick=\"location.href='Admin_order_cart.asp?action=del_all'\" src=\"images/bt_confirm.gif\">&nbsp;&nbsp;<input type=\"image\"  onclick=\"this.parentNode.style.display=\'none\';return false;\" src=\"images/bt_cancel.gif\">", null, null)
}
function FavBasket(){  
		fixedtooltip(document.getElementById("FavBasket"), "<b>确认收藏全部商品吗？</b><br><input type=\"image\" onclick=\"location.href='Admin_order_cart.asp?action=shoucang'\" src=\"images/bt_confirm.gif\">&nbsp;&nbsp;<input type=\"image\"  onclick=\"this.parentNode.style.display=\'none\';return false;\" src=\"images/bt_cancel.gif\">", null, null)
}
function addtobasket(id,listcode,product_type,isValid){  
	var pro_num = 1;
	var selectover = 1;
	var formBuy = document.forms['LEBI_FORMBUY_'+listcode];
	if (formBuy)
	{
		var pro_num = formBuy.elements['pro_num_'+listcode+'_'+id].value;
		list_hid=document.getElementsByName("hidv_"+listcode+"_"+id);
		var spname="";var spvalue="";
		for(var j=0;j<list_hid.length;j++){
			if (list_hid[j].value != "")
			{
				spname+=list_hid[j].value.split("|")[0];
				spvalue+=list_hid[j].value.split("|")[1];
				if (j<list_hid.length-1)
				{
					spname+=",";
					spvalue+=",";
				}
			}
		}
		for(var j=0;j<list_hid.length;j++){
			if (spvalue.split(",")[j] =="")
			{
				selectover = 0
			}
		}
	}
	if (selectover == 0)
	{
		fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], "<span style='font-weight:bold;color:#ff0000'>请先选择商品属性！</span><br /><a href='#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">关闭</a>", null, null)
	}else{
		var url="Admin_order_cart.asp?action=buy&ajaxbuy=1&id="+id+"&pro_num="+pro_num+"&spname="+escape(spname)+"&spvalue="+escape(spvalue)+"&product_type="+product_type+"&t="+Math.random();
//		location.href=url
		webRequest(url, "", "GET", true, function() {
			var xmlhttp = arguments[0];
			var args = new Array();
			if (xmlhttp.readyState == 4) {
				var type = xmlhttp.responseText.split("|")[0];
				var content = xmlhttp.responseText.split("|")[1];
				if (type == "1"){
					var ErrorAjaxbaskettext = "<strong>"+content+"</strong><br>&nbsp;&nbsp;<img src='/images/arr.gif'><a href='/#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">Close</a>";
					if (formBuy)
					{
						fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], ErrorAjaxbaskettext, null, null)
					}else{
						fixedtooltip(document.getElementById('button_'+listcode+'_'+id+''), ErrorAjaxbaskettext, null, null)
					}
				}else if (type == "2"){
					var ErrorAjaxbaskettext = "<strong>"+content+"</strong><br>&nbsp;&nbsp;<img src='/images/arr.gif'><a href='/#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">Close</a>";
					if (formBuy)
					{
						fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], ErrorAjaxbaskettext, null, null)
					}else{
						fixedtooltip(document.getElementById('button_'+listcode+'_'+id+''), ErrorAjaxbaskettext, null, null)
					}
				}else{
					webRequest("Ajax_cart.asp?showtype=0&t="+Math.random(), "", "GET", true, function() {
						var xmlhttp = arguments[0];
						var args = new Array();
						if (xmlhttp.readyState == 4) {
							var content = xmlhttp.responseText;
							document.getElementById("carttotalprice").innerHTML=content.split("|")[0];
							document.getElementById("carttotalnum").innerHTML=content.split("|")[1];
						}
					}, "");
					if (formBuy)
					{
						fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], "<b>恭喜：商品订购成功！</b><br /><a href='Admin_order_cart.asp'>结帐</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">继续订购</a>", null, null)
					}else{
						fixedtooltip(document.getElementById('button_'+listcode+'_'+id+''), "<b>恭喜：商品订购成功！</b><br /><a href='Admin_order_cart.asp'>结帐</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">继续订购</a>", null, null)
					}
				}
			}
		}, "");
	}
}
function addtobasket2(id,listcode,product_type,isValid){  
		var selectover = 1;
		var pro_num = 1;
		var formBuy = document.forms['LEBI_FORMBUY_'+listcode];
		if (formBuy)
		{
			var pro_num = formBuy.elements['pro_num_'+listcode+'_'+id].value;
			list_hid=document.getElementsByName("hidv_"+listcode+"_"+id);
			var spvalue="";
			for(var j=0;j<list_hid.length;j++){
				spvalue+=list_hid[j].value;
				if (j<list_hid.length-1)
				{
					spvalue+=",";
				}
			}
			for(var j=0;j<list_hid.length;j++){
				if (spvalue.split(",")[j] =="")
				{
					selectover = 0
				}
			}
		}
		if (selectover == 0)
		{
			fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], "<span style='font-weight:bold;color:#ff0000'>请先选择商品属性！</span><br /><a href='#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">关闭</a>", null, null)
		}else{
			var url="Admin_order_cart.asp?action=buy&id="+id+"&pro_num="+pro_num+"&spvalue="+escape(spvalue)+"&product_type="+product_type;
			location.href=url
			xmlHttp.open("GET", url, true);
			xmlHttp.send(null);  
			xmlHttp1.open("GET", "Ajax_cart.asp?showtype=0&t="+Math.random(), true);
			xmlHttp1.onreadystatechange = upcart;
			xmlHttp1.send(null);  
			fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], "<b>恭喜：商品订购成功！</b><br /><a href='Admin_order_cart.asp'>结帐</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">继续订购</a>", null, null)
		}
}
function upcart() {
  if (xmlHttp1.readyState < 4) {
	carttotalprice.innerHTML="Loading..";
	carttotalnum.innerHTML="Loading..";
  }
  if (xmlHttp1.readyState == 4) {
    var response = xmlHttp1.responseText.split("|");
	carttotalprice.innerHTML=response[0];
	carttotalnum.innerHTML=response[1];
  }
}

var _jsc = {};
_jsc.pos = (function(){
	var t = {};
	t.getX = function (obj){
        var curleft = 0;
        if (obj.offsetParent)
        {
          while (obj.offsetParent){
             curleft += obj.offsetLeft;
             obj = obj.offsetParent;
          }
          curleft += obj.offsetLeft;
        }
        else if (obj.x) {
          curleft += obj.x;
        }
        return curleft;
    };
    t.getY = function (obj){
    var curtop = 0;
        if (obj.offsetParent){
          while (obj.offsetParent){
             curtop += obj.offsetTop;
             obj = obj.offsetParent;
          }
          curtop += obj.offsetTop;
        }
        else if (obj.y)
          curtop += obj.y;
        return curtop;
    };
	return t;
})();
function market_tooltip(c){
	var _tooltips = document.getElementsByTagName('div');
	for (var i=0;i<_tooltips.length;i++) {
		if (_tooltips[i].getAttribute('tooltip') == 'market') _tooltips[i].parentNode.removeChild(_tooltips[i]);
	}
	var _tooltip = document.createElement('div');
	_tooltip.innerHTML = '<div id="fixedtipdiv">'+c+'</div>';
	_tooltip.className = 'mm_tips_market mm_tips_market_right';
	_tooltip.setAttribute('tooltip', 'market');
	//_tooltip.style.width='200px';
	_tooltip.style.zIndex = '9999';
	_tooltip.style.display = 'none';
	return document.body.appendChild(_tooltip);
}

// 气泡控制
var simple_fixedtooltip_timer;
function fixedtooltip(o, _tooltip_body,offsetT,offsetL){
	clearTimeout(simple_fixedtooltip_timer);
	var tooltip = market_tooltip(_tooltip_body);
	tooltip.style.top = offsetT ? (_jsc.pos.getY(o) + offsetT) + 'px' : (_jsc.pos.getY(o) - 80) + 'px';
	tooltip.style.left = offsetL ? (_jsc.pos.getX(o) + offsetL) + 'px' : (_jsc.pos.getX(o) - 80) + 'px';
	tooltip.style.display = 'block';
	tooltip.id = 'market_tooltip';
	tooltip.onmouseover = function() {
		clearTimeout(simple_fixedtooltip_timer);
	}
	simple_fixedtooltip_timer = setTimeout(function(){
		document.getElementById('market_tooltip').style.display = 'none';
	}, 6000);
}
/******* End (购买按钮显示层样式) 2008-5-23 by 56770.WangLei ******************/
function LebiCopy(form)
{
	var iscopy = document.getElementById('copy');
	if (iscopy.checked){
		form.to_name.value=form.from_name.value;
		form.to_tel.value=form.from_tel.value;
		form.to_zip.value=form.from_zip.value;
		form.to_adds.value=form.from_adds.value;
	}
}
maxLen = 200; 
function checkMaxInput(checkcase) 
{
	if (checkcase.to_other.value.length > maxLen) 
	checkcase.to_other.value = checkcase.to_other.value.substring(0, maxLen);
	else checkcase.remLen.value = maxLen - checkcase.to_other.value.length;
}
function from_checkMaxInput(checkcase) 
{
	if (checkcase.from_other.value.length > maxLen) 
	checkcase.from_other.value = checkcase.from_other.value.substring(0, maxLen);
	else checkcase.from_remLen.value = maxLen - checkcase.from_other.value.length;
}
var item_one='start';
var item_two='start';
function turnit(ss,bb) {
  if (ss.style.display=="none") {
    if(item_one!='start') item_one.style.display="none";
    if(item_one!='start') item_two.src="";
    ss.style.display="";
    item_one=ss;
    item_two=bb;
    bb.src="";
  }
  else {
    ss.style.display="none"; 
    bb.src="";
  }
}
/***** 配送地区 2008-3-13 by Lebi.WangLei **********/
function getDeliverArea2() {  
  if (xmlHttp.readyState < 4) {
	document.getElementById("deliver_area_2").innerHTML="loading...";
  }
  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	document.getElementById("deliver_area_2").innerHTML=response;
  }
}
/***** 配送方式列表地区 2008-3-13 by Lebi.WangLei **********/
function ajaxSub(t,url) 
{
	if (url.indexOf("?")==-1)
		url = url + '?t000='+Math.random()
	else
		url = url + '&t000='+Math.random()
	xmlHttp.open("GET", url, true);
	switch (t) {
		case 0 :
			xmlHttp.onreadystatechange = getDeliverArea2
			break;
		case 1 :
			xmlHttp.onreadystatechange = getDeliverList;
			break;
		default :
			break;
	} 
	xmlHttp.send(null);  
}
/*******************/
function ajaxSub1(t,url) 
{
	xmlHttp1.open("GET", url+'&t000='+Math.random(), true);
	xmlHttp1.onreadystatechange = getDeliverList;
	xmlHttp1.send(null);  
}