/*============= 2013-05-09 by 56770.Kingdge =================*/
//伸展菜单
var item_one='start';
var item_two='start';
function turnit(ss,bb) {
  var ss = document.getElementById(ss);
  var bb = document.getElementById(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 webRequest(url,xmlstr,method,isAsync,callback,callbackargs)
{
    var xmlhttp = null;
	if (window.ActiveXObject) {
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }else if (window.XMLHttpRequest) {
       xmlhttp = new XMLHttpRequest();
    }
	if(!method) method = "GET";
	if(!isAsync) isAsync = false;
	if(isAsync && callback){
		var args = new Array();
		args.push(xmlhttp);
		if(typeof(callbackargs) == 'object'){
			args = args.concat(callbackargs);
		}
		xmlhttp.onreadystatechange = function(){callback.apply(null,args);}
	}
	xmlhttp.open(method,url,isAsync);
    if(method.toLowerCase() == 'post'){
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
    xmlhttp.send(xmlstr);
	if(!isAsync){
		return xmlhttp.responseText;
	}
}
function ConfirmDel()
{
        if(confirm("确定要删除吗？删除将不能恢复！"))
                return true;
        else
                return false;
        
}
function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}
function setCookie(name, value){
document.cookie = name+"="+value
}
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(s){  
	var args = arguments;
	var id = args[0];
	var listcode = args[1];
	var product_type = args[2];
	var isValid = args[3];
	if(args[4]) var ajaxbuy = args[4];
	var fatherlistcode = "";
	if(args[5]) fatherlistcode = args[5];
	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 (fatherlistcode != "")
	{
		listcode = fatherlistcode;
		var formBuy = document.forms['LEBI_FORMBUY_'+fatherlistcode];
	}
	if (selectover == 0)
	{
		fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], "<span style='font-weight:bold;color:#ff0000'>"+ text3 +"</span><br><br /><a href='#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">"+ text4 +"</a>", null, null,1)
	}else{
		var url=EshopDomin+""+ LangPath +"basket/post.asp?action=checkspecification&ajaxbuy=1&id="+id+"&pro_num="+pro_num+"&spname="+escape(spname)+"&spvalue="+escape(spvalue)+"&product_type="+product_type+"&listcode="+listcode+"&t="+Math.random();
//		location.href=url
		webRequest(url, "", "GET", true, function() {
			var xmlhttp = arguments[0];
			var args = new Array();
			if (xmlhttp.readyState == 4) {
				var content = xmlhttp.responseText;
				if (content != ""){
					var ErrorAjaxbaskettext = ""+content+"<br><img src='/images/arr.gif'><a href='/#'  onclick=\"this.parentNode.style.display=\'none\';return false;\">"+ text4 +"</a>";
					if (formBuy)
					{
						fixedtooltip(formBuy.elements['button_'+listcode+'_'+id+''], ErrorAjaxbaskettext, null, null,0)
					}else{
						fixedtooltip(document.getElementById('button_'+listcode+'_'+id+''), ErrorAjaxbaskettext, null, null,0)
					}
				}else{
					if (ajaxbuy == "1")
					{
						location.href=EshopDomin+""+ LangPath +"basket/post.asp?action=checkspecification&ajaxbuy=0&id="+id+"&pro_num="+pro_num+"&spname="+escape(spname)+"&spvalue="+escape(spvalue)+"&product_type="+product_type+"&listcode="+listcode+"&t="+Math.random();
					}else{
					webRequest(EshopDomin+"include/lebi_ajax/cart.asp?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+''], Ajaxbaskettext, null, null,1)
					}else{
						fixedtooltip(document.getElementById('button_'+listcode+'_'+id+''), Ajaxbaskettext, null, null,1)
					}
					}
				}
			}
		}, "");
	}
}
function select_sp(id,i,ib,values,price,listcode,nostockorder){
	var selectover = 1;
	var result = document.getElementById("result_"+listcode+"_"+id);
	list=document.getElementsByName("sv_n_"+id+"_"+i);
	for(var j=0;j<list.length;j++){
		if (list[j].className == "spva-img"||list[j].className == "spva-imgon"){list[j].className="spva-img";}else{list[j].className="spva";}
		//list[j].style.background="#fff";
	}
	if (document.getElementById("sv_"+id+"_"+i+"_"+ib).className=="spva-img"||document.getElementById("sv_"+id+"_"+i+"_"+ib).className=="spva-imgon"){document.getElementById("sv_"+id+"_"+i+"_"+ib).className="spva-imgon";}else{document.getElementById("sv_"+id+"_"+i+"_"+ib).className="spvaon";}
	document.getElementById("hidv_"+listcode+"_"+id+"_"+i).value=values;
//	document.getElementById("sv_"+id+"_"+i+"_"+ib).style.background="url("+EshopDomin+"images/select-on.gif) no-repeat right bottom";
	list_hid=document.getElementsByName("hidv_"+listcode+"_"+id);
	var spvalue="";
	for(var j=0;j<list_hid.length;j++){
		if (list_hid[j].value != "")
		{
			spvalue+=list_hid[j].value.split("|")[1];
			if (j<list_hid.length-1)
			{
				spvalue+=",";
			}
		}
	}
	for(var j=0;j<list_hid.length;j++){
		if (spvalue.split(",")[j] =="")
		{
			selectover = 0
		}
	}
	if (selectover == 1)
	{
		 var url=EshopDomin+""+ LangPath +"basket/post.asp?action=getspinfo&id="+id+"&name="+escape(spvalue)+"&price="+price+"&t="+Math.random();
		 webRequest(url, "", "GET", true, function() {
			var xmlhttp = arguments[0];
			var args = new Array();
			if (xmlhttp.readyState == 4) {
				var returntxt = xmlhttp.responseText;
				var stock = returntxt.split("|")[0];
				var price = returntxt.split("|")[1];
				var sprice = returntxt.split("|")[2];
				var itemnum = returntxt.split("|")[3];
				var mes = returntxt.split("|")[4];
				if(mes.length > 0)
				{
					result.style.display = 'block';
					result.innerHTML = mes;
				}
				else
				{
					result.style.display = 'none';
					result.innerHTML = "";
				}
				document.getElementById("p-sprice").innerHTML = sprice;
				document.getElementById("p-price").innerHTML = price;
				document.getElementById("p-itemnum").innerHTML = itemnum;
				if (stock < 1)
				{
					if (nostockorder == 0)
					{
						document.getElementById("button_"+listcode+"_"+id).disabled = true;
					}else{
						document.getElementById("button_"+listcode+"_"+id).disabled = false;
					}
				}else{
					document.getElementById("button_"+listcode+"_"+id).disabled = false;
				}
			}
		 }, "");
	}
}
function setCookie(name, value)  
{ 
	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)
{ 
	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[0];
				}else{
					compidstr = compidstr + "," + sArr[0];
				}
			}
		}
		location.href=EshopDomin+''+ LangPath +'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)
		{
			document.getElementById("carttocomp").innerHTML = tArr.length;
		}else
		{
			document.getElementById("carttocomp").innerHTML= "0";
		}
	}else{
		document.getElementById("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,autoclose){
	var _tooltips = document.getElementsByTagName('div');
	var classname = "fixedtipdiv";
	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');
	if (autoclose == 0)
	{
		classname = "fixedtipdiv-choose"
	}
	_tooltip.innerHTML = '<div id="'+ classname +'">'+c+'<iframe style="border:none; position:absolute; visibility:inherit; top:0px; left:0px; width:150px; height:100px; z-index:-1; filter=progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);"></iframe></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,autoclose){
	clearTimeout(simple_fixedtooltip_timer);
	var tooltip = market_tooltip(_tooltip_body,autoclose);
	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);
	}
	if (autoclose == 1)
	{
		setTimeout(function(){
			document.getElementById('fixedtipdiv').style.display = 'none';
		}, 5000);
	}
}
function Trim(str){
   if(str.charAt(0) == " "){
   str = str.slice(1);
   str = Trim(str); 
}
return str;
}
function isDigit(pObj,errMsg){
   var obj = eval(pObj);
   var patrn=/^[0-9]{1,20}$/;
   if (!patrn.exec(pObj.value))
   {
      alert(errMsg); 
      obj.focus(); 
      return false;
   }
   return true
}
function isEmpty(pObj,errMsg){
   var obj = eval(pObj);
   if( obj == null || Trim(obj.value) == ""){
   if (errMsg == null || errMsg =="")
      alert("输入为空!");
   else
      alert(errMsg); 
      obj.focus(); 
      return false;
   }
   return true;
}
function Empty(pObj){
   var obj = eval(pObj);
   if( obj == null || Trim(obj.value) == ""){
      return true;
   }else{}
   return false;
}
function ShowinnerHTML(pObj,iobj,errMsg){
   document.getElementById(iobj).innerHTML = "<img src=\""+EshopDomin+"images/err.gif\"> <font color=\"red\">"+errMsg+"</font>";
   pObj.focus(); 
}
function SinnerHTML(iobj,SucMsg){
   document.getElementById(iobj).innerHTML = "<img src=\""+EshopDomin+"images/suc.gif\"> <font color=\"red\">"+SucMsg+"</font>";
}
function usecoupon() {      
	var c_num = document.getElementById("c_num").value;
	if (c_num.length == 0)
	{
		alert(text2);
	}else{
		location="post.asp?action=coupon&c_num="+ c_num;  
	}
}
function confirmdel(){
   if (confirm(text1)) 
   window.location.href="post.asp?action=del_all"
}  