//伸展菜单
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="";
  }
}

function ConfirmDel()
{
        if(confirm("确定要删除吗？删除将不能恢复！"))
                return true;
        else
                return false;
        
}

function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}


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 addtobasket(id,listcode,product_type,isValid){  
		if (isValid != 1)
		{
			location.href= EshopDomin+''+ LangPath +'Message/Error/default.asp?action=notgrade';
			return false;
		}
		var pro_num = 1;
		var pro_size = "-";
		var pro_color = "-";
		var formBuy = document.forms['LEBI_FORMBUY_'+listcode];
		if (formBuy)
		{
			var pro_num = formBuy.elements['pro_num_'+listcode+'_'+id].value;
			var pro_size = formBuy.elements['pro_size_'+listcode+'_'+id].value;
			if (pro_size == "")
			{
				var pro_size = document.getElementById("pro_size_"+listcode+"_"+id+"").options[document.getElementById("pro_size_"+listcode+"_"+id+"").selectedIndex].value;  
			}
			var pro_color = formBuy.elements['pro_color_'+listcode+'_'+id].value;
			if (pro_color == null || pro_color == "")
			{
				var pro_color = document.getElementById("pro_color_"+listcode+"_"+id+"").options[document.getElementById("pro_color_"+listcode+"_"+id+"").selectedIndex].value;  
			}
		}
		var url=EshopDomin+""+ LangPath +"basket/default.asp?action=buy&id="+id+"&pro_num="+pro_num+"&pro_size="+escape(pro_size)+"&pro_color="+escape(pro_color)+"&product_type="+product_type;
		xmlHttp.open("GET", url, true);
        xmlHttp.send(null);  
		var url1=EshopDomin+"include/lebi_ajax/cart.asp";
		xmlHttp1.open("GET", url1+"?moneyhl="+moneyhl+"&t="+Math.random(), true);
		xmlHttp1.onreadystatechange = upcart;
        xmlHttp1.send(null);  
		if (formBuy)
		{
			fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], Ajaxbaskettext, null, null)
		}else{
			fixedtooltip(document.getElementById('button_'+listcode+'_'+id+''), Ajaxbaskettext, 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];
  }
}
/**** 商品购物车对比栏 **************/
function setCookie(name, value) //cookies设置 
{ 
	var argv = setCookie.arguments; 
	var argc = setCookie.arguments.length; 
	var expires = (argc > 2) ? argv[2] : null; 
	if(expires!=null) 
	{ 
		var LargeExpDate = new Date (); 
		LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24)); 
	} 
	document.cookie = name + "= " + escape(value)+';path=/'+((expires == null) ? " " : ( "; expires= " +LargeExpDate.toGMTString())); 
} 

function getCookie(name) //cookies读取 
{ 
	var search = name + "=" 
	if(document.cookie.length > 0) 
	{ 
		offset = document.cookie.indexOf(search);
		if(offset != -1) 
		{ 
			offset += search.length;
			end = document.cookie.indexOf( "; ", offset);
			if(end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		} 
		else return ""; 
	} 
}

function herfComp()	// 对比栏
{
	var str = getCookie('56770_Product_comp');
	if (str != "")
	{
		var compidstr = "";
		var tArr = str.split('||$$||');
		for (i = 0; i < tArr.length; i++)
		{
			var sArr = tArr[i].split('|$|');
			if (sArr.length > 0)
			{
				if (compidstr=="")
				{
					compidstr = sArr[1];
				}else{
					compidstr = compidstr + ", " + sArr[1];
				}
			}
		}
		location.href=EshopDomin+'comp.asp?com_id='+compidstr;
	}else{
		return false;
	}
}
function setCartComp() // 初次载入时从 cookie 读取对比栏对比产品数量
{
	var str = getCookie('56770_Product_comp');
	if (str != "")
	{
		var tArr = str.split('||$$||');
		if (tArr.length > 0)
		{
			carttocomp.innerHTML = tArr.length;
		}else
		{
			carttocomp.innerHTML= "0";
		}
	}else{
		carttocomp.innerHTML= "0";
	}
}

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;
//		case 2 :
//			xmlHttp.onreadystatechange = setarea2;
//			break;
		default :
			break;
	} 
	xmlHttp.send(null);  
}
/*******************/

function selectall() 
{ 
   var a = document.getElementsByTagName("input"); 
   for (var i=0; i<a.length; i++) 
      if (a[i].type == "checkbox") a[i].checked =!a[i].checked; 
} 


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 = '999';
	_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('fixedtipdiv').style.display = 'none';
	}, 6000);
}