function $(objName){return(document.getElementById(objName));}  //转换ID

//建立AJAX对象
function CreateAjaxObject()
{
	XMLhttpRequest = false;
	if(window.XMLHttpRequest)
	{
		XMLhttpRequest = new XMLHttpRequest();
	}
	if(!XMLhttpRequest)
	{
		if(window.ActiveXObject)
		{
			try
			{
				XMLhttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				XMLhttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}
	return XMLhttpRequest;
}

//当前元素具顶端距离
function body_top(element)
{
	var anchor = document.getElementById(element);
	var top_i;
	//top_i = anchor.offsetTop;
	top_i = 0
	if (anchor.offsetParent)
	{
		while (anchor.offsetParent)
		{ 
			top_i += anchor.offsetTop; 
			anchor = anchor.offsetParent;
		}
	}
	return top_i;
}

//当前元素具左边距离
function body_left(element)
{
	var anchor = document.getElementById(element);
	var left_i;
	//left_i = anchor.offsetLeft;	
	left_i = 0;
	if (anchor.offsetParent)
	{
		while (anchor.offsetParent)
		{ 
			left_i += anchor.offsetLeft; 
			anchor = anchor.offsetParent;
		}
	}
	return left_i;
}


//首页书签转换
//i = 一级节点
//j = 二级节点
//num = 二级长度
//classname1 = 离开样式
//classname2 = 焦点样式
function index_sqzh(i,j,num,classname1,classname2)
{
	for(t=1;t<=num;t++)
	{
		$("index_sq_title_"+ i +"_"+ t).className = classname1;
		$("index_sq_text_"+ i +"_"+ t).style.display = "none";
	}
	$("index_sq_title_"+ i +"_"+ j).className = classname2;
	$("index_sq_text_"+ i +"_"+ j).style.display = "";
}

//首页侧边分类二级鼠标经过样式
function index_left_kindlist_onmouseover(id)
{
	$("skindid_text_"+ id).className = "slli1b";
	$("skindid_img_"+ id).innerHTML = "<img src='images/shop-b2.gif' width='5'>";
}

//首页侧边分类二级鼠标离开样式
function index_left_kindlist_onmouseout(id)
{
	$("skindid_text_"+ id).className = "slli1";
	$("skindid_img_"+ id).innerHTML = "<img src='images/shop-b1.gif' width='5'>";
}

//首页侧边分类二级读取
var index_left_kindlist_ajax_i = 0;//记录上次读取节点
function index_left_kindlist_ajax(kindid)
{
	if(index_left_kindlist_ajax_i != 0){$("kindid_html_"+ index_left_kindlist_ajax_i).innerHTML = "";}
	index_left_kindlist_ajax_i = kindid
	$("kindid_html_"+ kindid).innerHTML = "加载中...";
	var HttpAjax = CreateAjaxObject();
	HttpAjax.open("GET","index_left_skind.asp?kindid="+ kindid,false)
	HttpAjax.send(null)
	if(HttpAjax.readyState == 4 && HttpAjax.status == 200)
	{
		$("kindid_html_"+ kindid).innerHTML = HttpAjax.responseText;
	}
}

//头部分类一级鼠标经过样式
var index_top_kindlist_ajax_i = 0;//记录上次读取节点
var top_kind_px_top=0;//当前位置距离顶部距离
var top_kind_px_left=0;//当前位置距离左侧距离
function index_top_kindlist_onmouseover(id)
{
	clearTimeout(index_top_kindlist_onmouseout_time);
	
	top_kind_px_top = body_top("top_kind_"+id);//当前位置距离顶部距离
	top_kind_px_left = body_left("top_kind_"+id);//当前位置距离左侧距离
	
	//改变鼠标经过样式
	if(index_top_kindlist_ajax_i!=0){$("top_kind_"+index_top_kindlist_ajax_i).className="sflbg1";$("top_kind_a_"+index_top_kindlist_ajax_i).className="s_a1";}
	index_top_kindlist_ajax_i = id;
	$("top_kind_"+ id).className = "sflbg2";
	$("top_kind_a_"+ id).className = "s_a2";
	
	//改变箭头位置
	$("top_kind_img").style.marginTop = (top_kind_px_top+23)+"px";
	$("top_kind_img").style.marginLeft = (top_kind_px_left+20)+"px";
	
	//弹出层进行加载...
	$("top_kind_text").innerHTML = "<div class='shoplayer' onmouseover='clearTimeout(index_top_kindlist_onmouseout_time);' onmouseout='index_top_kindlist_onmouseout("+ id +")'>加载中...</div>";
	
	top_kind_text_Width = $("top_kind_text").scrollWidth;//检测层宽
	top_kind_text_Height = $("top_kind_text").scrollHeight;//检测层高
	
	top_kind_text_left = (top_kind_px_left-(top_kind_text_Width/2)+20);//定义弹出层距离左侧位置
	//检测是否到边
	if((top_kind_text_left+top_kind_text_Width)>=document.body.scrollWidth){top_kind_text_left = (document.body.scrollWidth-top_kind_text_Width-10)}
	//改变弹出层位置
	$("top_kind_text").style.marginTop = (top_kind_px_top+29)+"px";
	$("top_kind_text").style.marginLeft = top_kind_text_left+"px";
	//弹出透明IFRAME开始
	$("top_kind_iframe").style.width = top_kind_text_Width + "px";
	$("top_kind_iframe").style.height = top_kind_text_Height + "px";
	$("top_kind_iframe").style.marginTop = (top_kind_px_top+29) + "px";
	$("top_kind_iframe").style.marginLeft = top_kind_text_left + "px";
	//弹出透明IFRAME结束
	
	//加载弹出层真实数据
	var HttpAjax = CreateAjaxObject();
	HttpAjax.open("GET","index_top_skind.asp?kindid="+ id,false)
	HttpAjax.send(null)
	if(HttpAjax.readyState == 4 && HttpAjax.status == 200){top_kind_text_str = HttpAjax.responseText;}
	//将数据写入层内
	$("top_kind_text").innerHTML = "<div class='shoplayer' onmouseover='clearTimeout(index_top_kindlist_onmouseout_time);' onmouseout='index_top_kindlist_onmouseout("+ id +")'>"+ top_kind_text_str +"</div>";
	top_kind_text_Width = $("top_kind_text").scrollWidth;//检测层宽
	top_kind_text_Height = $("top_kind_text").scrollHeight;//检测层高
	top_kind_text_left = (top_kind_px_left-(top_kind_text_Width/2)+20);//定义弹出层距离左侧位置
	//检测是否到边
	if((top_kind_text_left+top_kind_text_Width)>=document.body.scrollWidth){top_kind_text_left = (document.body.scrollWidth-top_kind_text_Width-10)}
	//改变弹出层位置
	$("top_kind_text").style.marginTop = (top_kind_px_top+29)+"px";
	$("top_kind_text").style.marginLeft = top_kind_text_left+"px";
	//弹出透明IFRAME开始
	$("top_kind_iframe").style.width = top_kind_text_Width + "px";
	$("top_kind_iframe").style.height = top_kind_text_Height + "px";
	$("top_kind_iframe").style.marginTop = (top_kind_px_top+29) + "px";
	$("top_kind_iframe").style.marginLeft = top_kind_text_left + "px";
	//弹出透明IFRAME结束
	
}

//头部分类一级鼠标离开样式
var index_top_kindlist_onmouseout_time;
function index_top_kindlist_onmouseout(id)
{
	index_top_kindlist_onmouseout_time = setTimeout("index_top_kindlist_end("+ id +")",300)
}

//头部弹出层关闭
function index_top_kindlist_end(id)
{
	clearTimeout(index_top_kindlist_onmouseout_time);
	$("top_kind_img").style.marginTop = "-100px";
	$("top_kind_text").innerHTML = "";
	$("top_kind_iframe").style.width = "0px";
	$("top_kind_iframe").style.height = "0px";
	$("top_kind_"+ id).className = "sflbg1";
	$("top_kind_a_"+ id).className = "s_a1";
}

//正文加入购物车加载中
function shopcar_ajax(dsid)
{	
	$("shopcar_dsid_"+dsid).innerHTML = '<img src="images/shop-car1.jpg" height="27" width="92">';//写入载入图片
	setTimeout("shopcar_tcc_ajax('"+ dsid +"')",500)
}

//列表加入购物车弹出层
function shopcar_tcc_ajax(dsid)
{
	
	shopcar_px_top = body_top("shopcar_dsid_"+dsid);//当前位置距离顶部距离
	shopcar_px_left = body_left("shopcar_dsid_"+dsid);//当前位置距离左侧距离
	
	var HttpAjax = CreateAjaxObject();
	HttpAjax.open("GET","shopcar.asp?ds_id="+ dsid,false)
	HttpAjax.send(null)
	if(HttpAjax.readyState == 4 && HttpAjax.status == 200)
	{
		shopcar_text_str = HttpAjax.responseText
		$("shopcar_dsid_"+dsid).innerHTML = '<img src="images/shop-car.jpg" height="27" width="92">';//载入成功图片
		if(shopcar_text_str=="001"){alert("商品编号错误!");return false;}
		if(shopcar_text_str=="002"){alert("该商品已经加入过购物车!");return false;}
		//写入弹出层
		$("shopcar_text").innerHTML = shopcar_text_str;
	}
	shopcar_text_Width = $("shopcar_text").scrollWidth;//检测层宽
	shopcar_text_Height = $("shopcar_text").scrollHeight;//检测层高
	shopcar_text_left = (shopcar_px_left-(shopcar_text_Width/2)+46);//定义弹出层距离左侧位置
	//检测是否到边
	if((shopcar_text_left+shopcar_text_Width)>=document.body.scrollWidth){shopcar_text_left = (document.body.scrollWidth-shopcar_text_Width-10)}
	//改变弹出层位置
	$("shopcar_text").style.marginTop = (shopcar_px_top-45)+"px";
	$("shopcar_text").style.marginLeft = shopcar_text_left+"px";
	//弹出透明IFRAME开始
	$("shopcar_iframe").style.width = shopcar_text_Width + "px";
	$("shopcar_iframe").style.height = shopcar_text_Height + "px";
	$("shopcar_iframe").style.marginTop = (shopcar_px_top-45) + "px";
	$("shopcar_iframe").style.marginLeft = shopcar_text_left + "px";
	//弹出透明IFRAME结束
}

//正文加入购物车加载中
function shopcar_product_ajax(dsid)
{	
	$("shopcar_dsid_"+dsid).innerHTML = '<img src="images/shop-add.gif" height="37" width="134">';//写入载入图片
	setTimeout("shopcar_product_tcc_ajax('"+ dsid +"')",500)
}

//正文加入购物车弹出层
function shopcar_product_tcc_ajax(dsid)
{
	
	shopcar_px_top = body_top("shopcar_dsid_"+dsid);//当前位置距离顶部距离
	shopcar_px_left = body_left("shopcar_dsid_"+dsid);//当前位置距离左侧距离
	
	var HttpAjax = CreateAjaxObject();
	HttpAjax.open("GET","shopcar.asp?ds_id="+ dsid,false)
	HttpAjax.send(null)
	if(HttpAjax.readyState == 4 && HttpAjax.status == 200)
	{
		shopcar_text_str = HttpAjax.responseText
		$("shopcar_dsid_"+dsid).innerHTML = '<img src="images/shop-add.gif" height="37" width="134">';//载入成功图片
		if(shopcar_text_str=="001"){alert("商品编号错误!");return false;}
		if(shopcar_text_str=="002"){alert("该商品已经加入过购物车!");return false;}
		//写入弹出层
		$("shopcar_text").innerHTML = shopcar_text_str;
	}
	shopcar_text_Width = $("shopcar_text").scrollWidth;//检测层宽
	shopcar_text_Height = $("shopcar_text").scrollHeight;//检测层高
	shopcar_text_left = (shopcar_px_left-(shopcar_text_Width/2)+46);//定义弹出层距离左侧位置
	//检测是否到边
	if((shopcar_text_left+shopcar_text_Width)>=document.body.scrollWidth){shopcar_text_left = (document.body.scrollWidth-shopcar_text_Width-10)}
	//改变弹出层位置
	$("shopcar_text").style.marginTop = (shopcar_px_top-45)+"px";
	$("shopcar_text").style.marginLeft = shopcar_text_left+"px";
	//弹出透明IFRAME开始
	$("shopcar_iframe").style.width = shopcar_text_Width + "px";
	$("shopcar_iframe").style.height = shopcar_text_Height + "px";
	$("shopcar_iframe").style.marginTop = (shopcar_px_top-45) + "px";
	$("shopcar_iframe").style.marginLeft = shopcar_text_left + "px";
	//弹出透明IFRAME结束
}

//关闭加入购物车弹出层
function shopcar_end()
{
	$("shopcar_text").innerHTML = "";//写入弹出层空值
	//改变弹出层位置
	$("shopcar_text").style.marginTop = "-100px";
	$("shopcar_text").style.marginLeft = "-100px";
	//弹出透明IFRAME开始
	$("shopcar_iframe").style.width = "0px";
	$("shopcar_iframe").style.height = "0px";
	$("shopcar_iframe").style.marginTop = "-100px";
	$("shopcar_iframe").style.marginLeft = "-100px";
	//弹出透明IFRAME结束
}