﻿var Browser={};
var _ua_ = navigator.userAgent.toLowerCase();
Browser.isFirefox = (_ua_.indexOf("firefox")!=-1);
Browser.ie6 = Browser.ie&&/msie [6]/.test(_ua_);
Browser.ie7 = Browser.ie&&/msie [7]/.test(_ua_);
Browser.ieBox = Browser.ie&&(document.compatMode==null||document.compatMode!="CSS1Compat");

/*
window.onload=function(){
	var _left = document.body.clientWidth>800?(document.body.clientWidth-745)/2:23;
	for(var i=0;true;i++){
		var _item = document.getElementById("bpsM_top_"+i+"_0");
		if(_item==null)
			break;
			
		_item.style.left = _left + "px";
	}
}

window.onresize=function(){
	var _left = document.body.clientWidth>800?(document.body.clientWidth-745)/2:23;
	for(var i=0;true;i++){
		var _item = document.getElementById("bpsM_top_"+i+"_0");
		if(_item==null)
			break;
			
		_item.style.left = _left + "px";
	}
}
*/

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

function rnd() {
	return (new Date().getTime().toString());
}

function getScrollTop() {
	if(window.pageYOffset)
		return window.pageYOffset;
	else if(document.documentElement&&document.documentElement.scrollTop)
		return bodyST=document.documentElement.scrollTop;
	else if(document.body)
		return bodyST=document.body.scrollTop;
}

function getScrollLeft() {
	if(window.pageXOffset)
		return window.pageXOffset;
	else if(document.documentElement&&document.documentElement.scrollLeft)
		return document.documentElement.scrollLeft;
	else if(document.body)
		return document.body.scrollLeft;
}

function getWinHeight() {
	if(window.innerHeight)
		return window.innerHeight;
	else if(document.documentElement&&document.documentElement.clientHeight)
		return document.documentElement.clientHeight; 
	else if(document.body)
		return document.body.clientHeight;
}

function getWinWidth() {
	if(window.innerWidth)
		return window.innerWidth;
	else if(document.documentElement&&document.documentElement.clientWidth)
		return document.documentElement.clientWidth;
	else if(document.body)
		return document.body.clientWidth;
}

function getPageHeight() {
	if (window.innerHeight && window.scrollMaxY)
		return window.innerHeight + window.scrollMaxY;
	else if (document.body.scrollHeight > document.body.offsetHeight)
		return document.body.scrollHeight;
	else
		return document.body.offsetHeight;
}

function setAbsCenter(objCenter) {
	objCenter.style.left = ((getWinWidth()/2)-(objCenter.offsetWidth/2)) + "px";
	objCenter.style.top = (getScrollTop() + (getWinHeight()/2)-(objCenter.offsetHeight/2)) + "px";
}

function getPosY(o, v) {
	if (!o || !o.style) return ;
	if (v) {
		o.style.top = parseInt(v) + "px";
	} else {
		return o.style.top;
	}
}

function getPosX(o, v) {
	if (!o || !o.style) return ;
	if (v) {
		o.style.left = parseInt(v) + "px";
	} else {
		return o.style.left;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function atoi(s) {
	var r = parseInt(s);
	return isNaN(r) ? 0 : r;
}

function setSearchBoxText(inputForm) {
	if($("searchOption").options[0].selected) {
		if ($("hvarSearchString").value == "关键字 " || $("hvarSearchString").value == "") {
			$("hvarSearchString").value = "关键字或商品编号 #";
		}
	}
	else if ($("searchOption").options[1].selected) {
		if ($("hvarSearchString").value == "关键字或商品编号 #" || $("hvarSearchString").value == "") {
			$("hvarSearchString").value = "关键字 ";
		}
	}
	else {
		$("hvarSearchString").value = "关键字 ";
	}
}

function clearSearchBoxText(inputForm) {
	if ($("hvarSearchString").value == "关键字 " || $("hvarSearchString").value == "关键字或商品编号 #") {
			$("hvarSearchString").value = "";
	}
}

function checkSearchBoxText(inputForm) {
	if ($("hvarSearchString").value == "关键字 ") {
			alert("请输入一个关键字进行搜索.");
			return false;	
	} else if ($("hvarSearchString").value == "关键字或商品编号 #") {
			alert("请输入一个关键字或商品编号进行搜索.");
			return false;
	} else {
		return true;
	}
}

	
function bowserObject() {
	this.owner = navigator.userAgent.toLowerCase();
	if(document.getElementById)	this.domCapable = 1;
		else this.domCapable =  0;
	if(!this.domCapable  &&  document.layers) this.netscape4 = 1;
		else this.netscape4 = 0;
	this.opera = window.opera;
	if(this.owner.indexOf("gecko") > -1 || window.sidebar) this.mozilla = 1;
		else this.mozilla = 0;
	if(this.owner.indexOf("msie") > -1 && !this.opera) this.msie = 1;
		else this.msie = 0;
	if(this.opera) {
		if(this.owner.indexOf("opera 5") > -1 || this.owner.indexOf("opera/5") > -1) this.opera5 = 1;
			else this.opera5 = 0;
		this.opera6 = (this.owner.indexOf("opera 6") > -1 || this.owner.indexOf("opera/6") > -1);
		this.opera7 = this.domCapable && !this.opera5 && !this.opera6;
	} else if(this.mozilla) {
		this.netscape6 = 1;
	} else if(this.msie) {
		if(!this.domCapable && document.all) this.msie4 = 1; else this.msie4 = 0;
		if(this.owner.indexOf("msie 5") > -1) this.msie5 = 1; else this.msie5 = 0;
		if(this.msie5 && this.owner.indexOf("msie 5.5") > -1) this.msie55 = 1; else this.msie55 = 0;
		if(this.domCapable && !this.msie4 && !this.msie5 && ! this.msie55) this.msie6 = 1; else this.msie6 = 0;
	}
	if(this.owner.indexOf("mac") > -1) this.mac = 1; else this.mac = 0;
	if(this.msie6 || this.msie5 || this.msie4 || this.netscape4 || this.netscape6 || this.opera5 || this.opera6 || this.opera7)	this.bowser = 1; else this.bowser = 0;
	if(this.netscape6 || this.opera7) this.docObjModel = 1;	else this.docObjModel = 0;
	if(this.msie || this.opera7 || this.docObjModel) this.recycle = 1;else this.recycle = 0;
	if(this.domCapable && !this.opera5) this.px = "px"; else this.px = "";
	return this;
}
var bowser = new bowserObject();

function iniBpsH(){
	bpsH.addItem('bpsH_home','','<div align="center"><strong>首頁</strong></div>','index.aspx','',60,'');
	bpsH.addItem('bpsH_subHome','bpsH_home','首頁','index.aspx','',120,20);

	bpsH.addItem('bpsH_storeLocations','','<div align="center"><strong>商店位置</strong></div>','#','',90,'');
	bpsH.addItem('bpsH_subStoreLocations','bpsH_storeLocations','商店位置','#','',130,20);

	bpsH.addItem('bpsH_yourAccount','','<div align="center"><strong>帐户</strong></div>','#','',60,'');
	bpsH.addItem('bpsH_accountInfo','bpsH_yourAccount','帐户信息','login.aspx','',130,'');
	bpsH.addItem('bpsH_rewards','bpsH_yourAccount','奖励积分','#','',130,'');
	bpsH.addItem('bpsH_orderHistory','bpsH_yourAccount','历史记录','#','',130,'');
	bpsH.addItem('bpsH_wishList','bpsH_yourAccount','收藏列表','#','',130,'');
	bpsH.addItem('bpsH_FAQ','bpsH_yourAccount','帮助','#','',130,'');
	bpsH.addItem('bpsH_emailNewsLetter','bpsH_yourAccount','联系方式','#','',130,'');
	bpsH.addItem('bpsH_LogOff','bpsH_yourAccount','注销','UserRegistrationAdd.aspx?type=clear','',130,20);

	bpsH.addItem('bpsH_Catalog','','<div align="center"><strong>目录</strong></div>','#','',60,'');
	bpsH.addItem('bpsH_subCatalogs','bpsH_Catalog','分类目录','#','',130,'');

	bpsH.addItem('bpsH_SiteMap','','<div align="center"><strong>网站地图</strong></div>','Site_Map.aspx','',90,'');
	bpsH.addItem('bpsH_subSiteMap','bpsH_SiteMap','网站地图','Site_Map.aspx','',130,20);

	bpsH.addItem('bpsH_giftCards','','<div align="center"><strong>赠品</strong></div>','#','',60,'');
	bpsH.addItem('bpsH_subGiftCards','bpsH_giftCards','购买礼物卡片','#','',130,20);
	bpsH.addItem('bpsH_subGiftCardsCheckBalance','bpsH_giftCards','查询余额','#','',130,20);

	bpsH.addItem('bpsH_clearance','','<div align="center"><span class="topClearanceLink"><strong>打折商品</strong></span></div>','#','',90,'');
	bpsH.addItem('bpsH_subClearance','bpsH_clearance','打折商品','#','',130,20);
}
function HandleAutopaySubmit(){
	$("payinfo").style.display = "";
	setTimeout("autoSubmit();",5000);
}
function autoSubmit(){
	document.form1.submit();
}
function HandleChangeShipInfo(){
	$("form1").action = "";
	document.form1.submit();
}
function HandledoContinue2(){
	$("form1").action = "CheckOut2.aspx";
	document.form1.submit();
}
function HandlecmTotalCartOrders(){
	var subTotal = 0;
	var subBouns = 0;
	var Total  = 0;
	var count = $("count").value;
	for(var i = 0; i<parseInt(count);i++){
		subTotal = parseFloat(subTotal) + toMoney($("subtotal_"+i).value);
	}
	try{
		if($("g_count")){
			count = $("g_count").value;
			for(var j = 0; j<parseInt(count);j++){
				subBouns = parseFloat(subBouns) + toMoney($("g_subBonus_"+j).value);
			}
		}
	}catch(e){}
	subTotal = (parseInt(subTotal*100))/100;
	$("subtotal").innerHTML = "￥"+subTotal;
	$("sub_Bouns").innerHTML = subBouns;
	$("total").innerHTML = "￥"+subTotal;
}

function toMoney(num)
{
	str= Math.round(num*Math.pow(10,2))/Math.pow(10,2);
	return str;
}

function HandleUpdateCart(){
	var Parm = getParm();
	var option={
		parameters:"s="+Math.random()+"&oper=updatecart&"+Parm,
		method:"get",
		onSuccess:function(transport){
			if(transport.responseText=="TEMPSUCCESS"){
				HandlecmTotalCartOrders();
				alert("临时购物车更新成功！");
				window.location.href="ViewCart.aspx";
			}else{
				$("ProductList").innerHTML = transport.responseText;
				HandlecmTotalCartOrders();
				alert("购物车更新成功！");
			}
		},
		onFailure:function(transport){
			alert("购物车更新失败，请检查网络!");
		}
	}
	var request=new Ajax.Request("Product/AjaxProduct.aspx",option);
}
function getParm(){
	var parm1 = "";
	var parm2  = "";
	var parm3 = "";
	var parm4 = "";
	var count = $("count").value;
	for( var i=0; i< parseInt(count); i++){
		if( $("remove_"+i).checked){
			parm1 = parm1 + $("remove_"+i).value+",";
		}else{
			parm2 = parm2 + $("product_"+i).value+","+$("quantity_"+i).value+"|";
		}
	}
	if( parm1 != "" ) parm1 = parm1.substr(0,parm1.length - 1);
	if( parm2 != "" ) parm2 = parm2.substr(0,parm2.length - 1);
	///
	try{
		if($("g_count")){
			count = $("g_count").value;
			for( var i=0; i< parseInt(count); i++){
				if( $("g_remove_"+i).checked){
					parm3 = parm3 + $("g_remove_"+i).value+",";
				}else{
					parm4 = parm4 + $("g_product_"+i).value+","+$("g_quantity_"+i).value+"|";
				}
			}
			if( parm3 != "" ) parm3 = parm3.substr(0,parm3.length - 1);
			if( parm4 != "" ) parm4 = parm4.substr(0,parm4.length - 1);
		}
	}catch(e){}
	///
	return "parm1="+parm1+"&parm2="+parm2+"&parm3="+parm3+"&parm4="+parm4;
}

function closefloatadt() {
	if ($("floatad_tl")) {
		$("floatad_tl").style.display = "none";
	}
	if ($("floatad_tr")) {
		$("floatad_tr").style.display = "none";
	}
}

function onBodyScroll() {
	floatAdScroll();
}

function closefloatadb() {
	if ($("floatad_bl")) {
		$("floatad_bl").style.display = "none";
	}
	if ($("floatad_br")) {
		$("floatad_br").style.display = "none";
	}
}

function floatAdScroll() {
	var obj1 = $("floatad_bl");
	var obj2 = $("floatad_br");
	var t1 = (getWinHeight() + getScrollTop() - 10);
	if (obj1) {
		obj1.style.top = (t1 - obj1.offsetHeight) + "px";
	}
	if (obj2) {
		obj2.style.top = (t1 - obj2.offsetHeight) + "px";
	}
	return true;
}

function HandleDeleteOrder(obj,name,action){
	var count = $F("listcount");
	var total = 0;
	for(var i = 0; i< count ; i++){
		if($(obj+i)){
			if( $(obj+i).checked){
				total++;
			}		
		}
	}
	if(total>0){
		if(confirm("您是否确认"+name+"?"))
		{
			$("optForm").action=action;
			$("optForm").submit();
		}
	}else{
		alert("请选择要"+name+"！")
	}
}
function checkAll(ths,obj){
	var count = $F("listcount");
	if( ths.checked ){
		for(var i = 0; i< count ; i++){
			if($(obj+i)){
				$(obj+i).checked = true;
			}
		}
	}else{
		for(var i = 0; i< count ; i++){
			if($(obj+i)){
				$(obj+i).checked = false;
			}
		}
	}
}

//////////////////////////////////////////////////
/*
var dragy=0,dragx=0;
var dragapproved=false;

function moveF(e)
{
	if (e.button==0)
	{
		window.scrollBy(dragx-e.pageX,dragy-e.pageY);
		dragy=e.pageY;
		dragx=e.pageX;
	}
}

function downF(e)
{
	dragy=e.pageY;
	dragx=e.pageX;
}


if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
	document.onmousedown=function(e)
	{
		document.onmousemove=function(e)
		{
			moveF(e);
		}  
	}
	document.onmouseup=function()
	{
		document.onmousemove=null;
	}
}
else
{
	document.onmousemove=function()
	{
		if ((event.button==0 || event.button==1)&&dragapproved)
		{
			window.scrollBy(dragx-event.clientX,dragy-event.clientY);
			dragy=event.clientY;
			dragx=event.clientX;
			return false;
		}
	}
	document.onmousedown=function()
	{
		dragy=event.clientY;
		dragx=event.clientX;
		dragapproved=true;
	}
	document.onmouseup=function()
	{
		dragapproved=false;
	}
}

*/


function suitImage(img,w,h)
{
	
	var image=new Image();
    image.src=img.src;

	var iw=image.width;
	var ih=image.height;
	var iratio=iw/ih;
    
    if(iw>w)
	{
            iw=w;
			ih=w/iratio;
    }
    if(ih>h)
	{
            ih=h;
            iw=h*iratio;
    }  
	img.width=iw;
	img.height=ih;
}
/////////////////////////////////////////

var orderListTimeout = null;

var orderListOpenObj = null;

function orderListIn() {
	clearTimeout(orderListTimeout);
}

function orderListOut() {
	orderListTimeout = setTimeout("orderListClose()",1000);
}

function orderListClose() {
	if (orderListOpenObj) {
		orderListOpenObj.style.display = "none";
		orderListOpenObj = null;
	}
}

function orderCtlshow(id)
{
	orderListClose();
	orderListOpenObj = $("orderCtl" + id);
	if (orderListOpenObj) {
		orderListOpenObj.style.display =  "";
	}
}

function orderCtldown(id,code)
{
   document.getElementById("orderCtl"+id).style.display="none";
   if (code==2)
   {
      window.location="Account.aspx?op=memo&id="+id;
   }
   else
   {
       var  truthBeTold=window.confirm("是否确认操作。");
       if  (truthBeTold)
       {   
           window.location="UserRegistrationAdd.aspx?type=orderlistcode&id="+id+"&code="+code;
       };
   };
   
}

function getProductReviews(pid,pg) {
	var option={
		parameters:"&op=getreviews&pid=" + pid + "&pg=" + pg + "&rnd=" + rnd(),
		method:"get",
		onSuccess:function(transport){
			$("ProductReviews").innerHTML = transport.responseText;
		},
		onFailure:function(transport){
			//alert("数据获取失败，请检查网络!");
		}
	}
	var request=new Ajax.Request("ajaxProductReviews.aspx",option);
}

function HandleOnlinePay(url){
	$("form1").action = url;
	$("form1").submit();
}


function writeLeftNavItem(altText, urlLocation, displayText, displayText2, highlight){
	var retHtml = "";
	retHtml += "<tr>\n";
	retHtml += "	<td width='1' class='colorThemeBG6'><img src=\"images/spacer.gif\" alt=\"c\" width=\"1\" /></td>\n";
	if(displayText2.length > 0) {
		retHtml += "	<td height='38' ";
	} else {
		retHtml += "	<td height='18' ";
	}
	retHtml += " width='148' title='" + altText + "' class='colorThemeBG2' style='cursor:hand;' onMouseover=\"this.className='colorThemeBG7';\" onMouseout=\"this.className='colorThemeBG2';\" onclick=\"document.location.href='" + urlLocation + "'\">\n";
	if(displayText2.length > 0){
		retHtml += "		&nbsp;&nbsp;&nbsp;<a href='"+ urlLocation +"' class='leftNav'>"+ displayText +"</a><br />\n";
		retHtml += "		&nbsp;&nbsp;&nbsp;<a href='"+ urlLocation +"' class='leftNav'>"+ displayText2 +"</a></td>\n";
	} else {
		retHtml += "		&nbsp;&nbsp;&nbsp;<a href='"+ urlLocation +"' class='leftNav'>"+ displayText +"</a></td>\n";
	}
	retHtml += "	<td width='1' class='colorThemeBG6'><img src=\"images/spacer.gif\" alt=\"c\" width=\"1\" /></td>\n";
	retHtml += "</tr>\n";

	document.write(retHtml);
}


function imgResize(_obj) {
	var _width = 100;
	var _height = 100;
	if (arguments[1]){
		if (typeof(arguments[1])=="number"){
			_width = arguments[1];
			if (arguments[2]){
				if (typeof(arguments[2])=="number"){
					_height = arguments[2];
				} else {
					_height = arguments[1];
				}
			} else {
				_height = arguments[1];
			}
		}
	}
	if ( _obj.width > _width || _obj.height > _height ){
		var scale = _obj.width / _obj.height ;
		var _scale = _width / _height;
		if ( scale >= _scale ){
			_obj.width = _width ;
			_obj.height = _obj.width / scale ;
		} else {
			_obj.height = _height ;
			_obj.width = _obj.height * scale ;
		}
	}
}

function ProductTagAdd() {
	if (($("TagAdd"))&&($("TagAddPid"))) {
		var tagname = $("TagAdd").value;
		var pid = $("TagAddPid").value;
		var option={
			parameters:"s=" + Math.random() + "&oper=tagadd&tag=" +  encodeURIComponent(tagname) + "&pid=" + pid ,
			method:"get",
			onSuccess:function(transport){
				if($("TagList")) {
					$("TagAddBtn").style.display = "";
					$("TagAddBox").style.display = "none";
					$("TagList").innerHTML = transport.responseText;
				}
			},
			onFailure:function(transport){
				alert("添加失败，请稍候再试");
			}
		}
		var request=new Ajax.Request("Product/AjaxProduct.aspx",option);
	}
}

