﻿

//写cookies函数 
function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//读取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}




/************************************************************************************/
/************************************************************************************/
//首页广告
/************************************************************************************/
function SetSize(obj, width, height)
{
    myImage = new Image();
    myImage.src = obj.src;
    if (myImage.width>0 && myImage.height>0)
    {
        var rate = 1;
        if (myImage.width>width || myImage.height>height)
        {
            if (width/myImage.width<height/myImage.height)
            {
                rate = width/myImage.width;
            }
            else
            {
                rate = height/myImage.height;
            }
        }
        if (window.navigator.appName == "Microsoft Internet Explorer")
        {
          obj.style.zoom = rate;
        }
        else
        {
          obj.width = myImage.width*rate;
          obj.height = myImage.height*rate;
        }
    }
}


/************************************************************************************/
//页头方法
/************************************************************************************/
function checkPrdouctAttributeValue(popup)
{

}

String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g, "")}


//清空一些隐藏框的数据
function JS_ClearHidden(currentID)
{
	var ids = new Array();
	ids.push ("Hid_GroupID");
	ids.push("Hid_ToCart");
	ids.push("Hid_RemoveCart");
	ids.push("Hid_ToWishList");
	ids.push("Hid_RemoveWishList");
	ids.push("Hid_IsUpdateQtys");
	ids.push("Hid_IsLogout");

	
	
	for(var i=0;i<ids.length;i++)
	{
		if (ids[i] != currentID)
		{
			document.getElementById(ids[i]).value = "";
		}
	}
	
	//document.getElementById("__VIEWSTATE").name = "__VIEWSTATE_REMOVE";
	//document.getElementById("__VIEWSTATE").id = "__VIEWSTATE_REMOVE";
	
	return true;
}

//启用分组显示
function JS_CartGroup(GroupID,targetPage)
{   if(targetPage.indexOf("?")==-1)
    window.location=document.getElementById("Hid_URL").value+ targetPage+"?ProductGroupID="+GroupID;
    else
    window.location= document.getElementById("Hid_URL").value+ targetPage+"&ProductGroupID="+GroupID;    
    
	//document.getElementById("Hid_GroupID").value = GroupID;
	
	//JS_ClearHidden("Hid_GroupID");
	//document.forms[0].submit();
}
//为购物车中的商品设置属性
  function Set_GS_ShoppingCartAttribute(HiddenID,ControlName)
  {
    var popup = document.getElementById(ControlName);
    if (popup.options[popup.selectedIndex].value != "")
     {
		var GetData=popup.options[popup.selectedIndex].value ;
		alert(GetData);
		var Hid1=document.getElementById (HiddenID);
		Hid1.value=GetData;
	}
  }
  


//添加商品到购物车中
function JS_AddToCart(productID,qty)
{   
    if (document.getElementById ("HidCount"+productID)!=undefined && document.getElementById ("HidCount"+productID).value!="0")
    {   var sAlert="";
		var has = 0;
		
		if( document.getElementById("Qty"+	productID + "L")!=undefined && document.getElementById("Qty"+	productID + "R")!=undefined)
		{
			if( document.getElementById("Qty"+	productID + "L").value =="" && document.getElementById("Qty"+	productID + "R").value=="")
			{
			alert("请确定你输入了商品的数量。");
			return false;
			}
			 if(document.getElementById("Qty"+	productID + "L").value=="")
			 
				document.getElementById("Qty"+	productID + "L").value=0;
				
			 if(document.getElementById("Qty"+	productID + "R").value=="")
				document.getElementById("Qty"+	productID + "R").value=0;
				
			var l=	document.getElementById("Qty"+	productID + "L").value;
			var r=	document.getElementById("Qty"+	productID + "R").value;
			document.getElementById("Hid_ToCartQty").value =parseInt(l)+parseInt(r);
			if(	document.getElementById("Hid_ToCartQty").value==0)
			{
			  alert("请确定你输入了商品的数量。");
			  return false;
			}
			var SubmjectMethod="";
			if(document.getElementById("Qty"+	productID + "L").value!="0")
			{
				for(var i=0;i<=document.getElementById ("HidCount"+productID).value;i++)
				{ 
					var hid="DDL_"+productID+"_" + i+"_L" ; //获是每一个下拉列表
					var popup = document.getElementById(hid);
					if (popup!=undefined && popup.options[popup.selectedIndex].value.substring(0,2) == "-1")
					{     
						has=1; 
					
						sAlert += popup.options[0].value.substring(2,popup.options[0].value.length)+",";
					}
				
				}
			}

			if(document.getElementById("Qty"+	productID + "R").value!="0")
			{
				for(var i=0;i<=document.getElementById ("HidCount"+productID).value;i++)
				{ 
					var hid="DDL_"+productID+"_" + i+"_R" ; //获是每一个下拉列表
					var popup = document.getElementById(hid);
					if (popup!=undefined && popup.options[popup.selectedIndex].value.substring(0,2) == "-1")
					{     
						has=1; 
					
					  sAlert += popup.options[0].value.substring(2,popup.options[0].value.length)+",";
					 }
				}
			}

		}
		else  //没有QTY属性时
		{
			for(var i=1;i<=document.getElementById ("HidCount"+productID).value;i++)
			{ 
				var hid="DDL_"+productID+"_" + i ; //获是每一个下拉列表
				var popup = document.getElementById(hid);
				if (popup.options[popup.selectedIndex].value.substring(0,2) == "-1")
				{     
					has=1; 
					sAlert += popup.options[0].value.substring(2,popup.options[popup.selectedIndex].value.length)+",";
				}
				
			}

        
		}
		
		if(has==1)
			{
				alert("请选择 " + sAlert.substring(0,sAlert.length-1) + "!" );
				return false;
			}
    }
    
    document.getElementById("Hid_ToCart").value = productID;
    
     
    if(document.getElementById("Hid_ToCartQty").value=="")
    {
	  if (qty != undefined && qty.value != "")
		document.getElementById("Hid_ToCartQty").value = qty.value;
	  if(qty==undefined || qty==null|| qty.value=="")
		document.getElementById("Hid_ToCartQty").value = 1;
   }
	JS_ClearHidden("Hid_ToCart");
	if(document.getElementById ("goShoppingCart")!=undefined)
	{
		
		document.getElementById ("goShoppingCart").value="1";
	}
	
			document.getElementById("__VIEWSTATE").value = "";
	document.forms[0].action="ViewCart.aspx";
	document.forms[0].submit();

}

//从购物车中删去商品
function JS_RemoveCart(productID)
{   if(window.confirm("你确定要从购物车里清除此商品吗？"))
	{
		document.getElementById("Hid_RemoveCart").value = productID;
		JS_ClearHidden("Hid_RemoveCart");
		
		document.forms[0].submit();
	}
}

//修改购物车
function JS_UpdateCart(productID,CartID)
{

 if (document.getElementById ("HidCount"+productID)!=undefined && document.getElementById ("HidCount"+productID).value!="0")
    {   var sAlert="";
		var has = 0;
		if( document.getElementById("Qty"+	productID + "L")!=undefined && document.getElementById("Qty"+	productID + "R")!=undefined)
		{
			if( document.getElementById("Qty"+	productID + "L").value =="" && document.getElementById("Qty"+	productID + "R").value=="")
			{
			alert("请输入你要购买商品的数量。");
			return false;
			}
			 if(document.getElementById("Qty"+	productID + "L").value=="")
			 
				document.getElementById("Qty"+	productID + "L").value=0;
				
			 if(document.getElementById("Qty"+	productID + "R").value=="")
				document.getElementById("Qty"+	productID + "R").value=0;
				
			var l=	document.getElementById("Qty"+	productID + "L").value;
			var r=	document.getElementById("Qty"+	productID + "R").value;
			
			document.getElementById("Hid_ToCartQty").value =parseInt(l)+parseInt(r);
			if(	document.getElementById("Hid_ToCartQty").value==0)
			{
			  alert("请输入你要购买商品的数量。");
			  return false;
			}
			if(document.getElementById("Qty"+	productID + "L").value!="0")
			{
				for(var i=0;i<=document.getElementById ("HidCount"+productID).value;i++)
				{ 
					var hid="DDL_"+productID+"_" + i+"_L" ; //获是每一个下拉列表
					var popup = document.getElementById(hid);
					if (popup!=undefined && popup.options[popup.selectedIndex].value.substring(0,2) == "-1")
					{     
						has=1; 
					
						sAlert += popup.options[0].value.substring(2,popup.options[0].value.length)+",";
					}
				}
			}

			if(document.getElementById("Qty"+	productID + "R").value!="0")
			{
				for(var i=0;i<=document.getElementById ("HidCount"+productID).value;i++)
				{ 
					var hid="DDL_"+productID+"_" + i+"_R" ; //获是每一个下拉列表
					var popup = document.getElementById(hid);
					if (popup!=undefined && popup.options[popup.selectedIndex].value.substring(0,2) == "-1")
					{     
						has=1; 
					
					  sAlert += popup.options[0].value.substring(2,popup.options[0].value.length)+",";
					 }
				}
			}

		}
		else  //没有QTY属性时
		{
			for(var i=1;i<=document.getElementById ("HidCount"+productID).value;i++)
			{ 
				var hid="DDL_"+productID+"_" + i ; //获是每一个下拉列表
				var popup = document.getElementById(hid);
				if (popup.options[popup.selectedIndex].value.substring(0,2) == "-1")
				{     
					has=1; 
					sAlert += popup.options[0].value.substring(2,popup.options[popup.selectedIndex].value.length)+",";
				}
				
	   
			}

        
		}
		if(has==1)
			{
				alert("请选择 " + sAlert.substring(0,sAlert.length-1) + "。" );
				return false;
			}
    }
    
    document.getElementById("Hid_ToCart").value = productID;	
    
	JS_ClearHidden("Hid_ToCart");

	document.forms[0].submit();
	

}

//从收藏夹中移除商品
function JS_RemoveWishList(productID)
{
  if(window.confirm("你确定要从收藏夹里清除此商品吗？"))
	{
		document.getElementById("Hid_RemoveWishList").value = productID;
		
		JS_ClearHidden("Hid_RemoveWishList");

		document.forms[0].submit();
	}
}


//添加商品从收藏夹增加到购物车中
  function Fun_addtoCart(productID) 
  { 
	if (document.getElementById ("HidCount"+productID)!=undefined && document.getElementById ("HidCount"+productID).value!="0")
		{   
			var sAlert="";
			var has = 0;
			for(var i=1;i<=document.getElementById ("HidCount"+productID).value;i++)
			{ 
				var hid="DDL_"+productID+"_" + i ; //获是每一个下拉列表
				var popup = document.getElementById(hid);
				
				if (popup.options[popup.selectedIndex].value.substring(0,2) == "-1")
				{      
					has=1; 
					//alert("Please select the product Attribute with " + document.getElementById ("HidCount"+productID).value + " SelectBox first" );
					//alert("Please select the " + popup.options[popup.selectedIndex].value.substring(2,popup.options[popup.selectedIndex].value.length) + "!" );
					//return false;
				}
				sAlert += popup.options[0].value.substring(2,popup.options[popup.selectedIndex].value.length)+",";
			}
			 if(has==1)
			{
				alert("请选择 " + sAlert.substring(0,sAlert.length-1) + "。" );
				return false;
			}
		}
	    
	document.getElementById("Hidden_ProdcutID").value=productID; 
	document.forms[0].action=document.getElementById("Hid_URL").value+ "WishList.aspx?IsAddToCart=1"; 
	document.forms[0].submit();
  }
  
//添加商品到收藏夹中
function JS_ToWishList(productID)
{
	document.getElementById("Hid_ToWishList").value = productID;
	JS_ClearHidden("Hid_ToWishList");
	document.forms[0].action="WishList.aspx";
	document.forms[0].submit();
}


//跳转到一个页面.并传递商品ID过去.
function ToProductID(productID,targetPage)
{
	
	 window.location= "ProductInfo"+ productID +".aspx" ;
	
}

//跳转到Emailt to Friend..
function EmailToFriend(productID,targetPage)
{
	document.getElementById("Hid_ProductID").value = productID;
	if (targetPage != null && targetPage != undefined)
	{
		document.getElementById("Hid_TargetPage").value = document.getElementById("Hid_URL").value+ targetPage;
		JS_ClearHidden("Hid_ProductID");
		//document.forms[0].action=targetPage;
		
	}
	//alert(document.getElementById("Hid_URL").value+ targetPage+"?Hid_ProductID="+productID);
	window.location =document.getElementById("Hid_URL").value+ targetPage+"?Hid_ProductID="+productID;
	//document.forms[0].submit();

}
//商品类别浏览ID
function JS_BrowseCategory(categoryID,targetPage)
{  
     if(targetPage != null || targetPage != undefined)
     { 
       if(targetPage.indexOf("?")==-1)
       {
		window.location = "CategoryInfo" + categoryID + ".aspx";
		//window.location= targetPage+"?Hid_BrowseCategoryID="+categoryID;
		}
	   else
	   {
		window.location = "CategoryInfo" + categoryID + ".aspx";
		//window.location= targetPage+"&Hid_BrowseCategoryID="+categoryID;
		}
     }

}
//Qty 商品　数量相加
function JS_AddQty(id)
{
  id="Qty_" + id;
  var l=0;
  var r=0;
 // alert(document.getElementById(id+"_L").value + "  " + document.getElementById(id+"_R").value);
 
  if(document.getElementById(id+"_L")!=undefined && document.getElementById(id+"_L").value>0)
  {
	l=document.getElementById(id+"_L").value;
	
  }
  else
  {
	document.getElementById(id+"_L").value=0;
	 l=0;
  }
    if(document.getElementById(id+"_R")!=undefined && document.getElementById(id+"_R").value>0)
  {
	r=document.getElementById(id+"_R").value;
	
  }
  else
  {
  document.getElementById(id+"_R").value=0;
	 r=0;
  }
  if(parseInt(l)>=0 || parseInt(r)>=0)
  {
    document.getElementById(id).value=parseInt(l)+parseInt(r);
  }
}
//更新商品购物的数量
function JS_UpdateQtys(subTotal)
{
	if (subTotal <= 0)
	{
		alert("您的购物车为空。");
		return false;
	}
	else
	{
		document.getElementById("Hid_IsUpdateQtys").value = "1";
		JS_ClearHidden("Hid_IsUpdateQtys");
		document.forms[0].submit();
	}
}

//注销用户登录
function JS_CustomerLogout()
{
	document.getElementById("Hid_IsLogout").value = "1";
	JS_ClearHidden("Hid_IsLogout");
	document.forms[0].submit();
}

//去登录页面
//targetPage:登录成功后跳转的页面
function JS_GoLogin(targetPage,dirPage)
{
	//如果为空.默认为首页(Index.aspx)
	if (targetPage == null || targetPage == undefined)
		targetPage = "index.aspx";
	if (dirPage != true)
	{
		document.getElementById("Hid_TargetPage").value = document.getElementById("Hid_URL").value+ targetPage;
		
		if(document.getElementById("__VIEWSTATE")!=undefined)document.getElementById("__VIEWSTATE").value = "";
		if(targetPage.toLowerCase().indexOf("order.aspx")==-1)
		
		    document.forms[0].action = document.getElementById("Hid_URL").value+"Login.aspx";
		else
		    document.forms[0].action = document.getElementById("Hid_URL").value+"Login.aspx?IsGoPayment=1";
		document.forms[0].submit();
	}
	else
	{
		if(document.getElementById("Hid_URL")!=undefined)
			location.href = document.getElementById("Hid_URL").value+ targetPage;
		else
			location.href =targetPage;
	}
	return true;
}

//查询验证
function JS_GoSearch()
{
	if(document.getElementById("txbSearch").value.trim().length==0)
	{
		alert("请输入搜索条件.");
		document.getElementById("txbSearch").focus();
		document.getElementById("txbSearch").select();
		return void(0);
	}
	else
	{
		location.href=document.getElementById("Hid_URL").value+ "SearchResult.aspx?SearchCondition=" + document.getElementById("txbSearch").value.trim();
		return true;
	}
}

//去下订单
function JS_GoCheckOut(isLogin,subTotal)
{   
	JS_ClearHidden();
	if (subTotal <= 0)
	{
		alert("您的购物车为空。");
		return void(0);
	}
	else
	{
		if (isLogin)
		{
			location.href=document.getElementById("Hid_URL").value+"Order.aspx";
		}
		else
		{
			return JS_GoLogin("Order.aspx");
		}
	
		return false;
	}
	
}

//验证数量输入 函数1
function JS_QtyKeyPressValidate(e)
{
	var c=(navigator.appName=="Netscape")?e.which:e.keyCode;
	
	if(c>31&&(c<48||c>57))
	{
		if(!(c==45||c==46))
		{
			status="这里只允许输入数字。";
			return false;
		}
	}
	return true;
}


function JS_Qty_Text(txbID)
{
  if( txbID.value!="")
  {
	if ( !_IntE(txbID.value) )
		{
			txbID.value = "";
			alert("这里只允许输入数字。");
			return false;
		}
	 if(parseInt( txbID.value)>10000)
	{  
	   
	
		alert("商品的数量不能超过10000.");
		txbID.value = "";
	   return false;
	}
		 if(parseInt( txbID.value)<0)
	{  
	 
		alert("商品数量不能低于0.");
		txbID.value = "";
		 return false;
	}
}
}
//验证数量输入 函数2
function JS_QtyOnBlurValidate(txbID)
{
	if (parseInt( document.getElementById(txbID).value ) <= 0)
	{
		
		alert("购买数量不能小于 1.");
		document.getElementById(txbID).value = "";
		return false;
	}
	else if ( !_IntE(document.getElementById(txbID).value) )
	{
		document.getElementById(txbID).value = "1";
		return false;
	}
	else if(parseInt( document.getElementById(txbID).value )>10000)
	{  
	   
	  
		alert("商品的数量不能超过10000.");
		document.getElementById(txbID).value = "1";
	   return false;
	}
}

//按Tab键跳转到下一个焦点
function TabToNextFocus(nextCtlId)
{
	if (event.keyCode == 9)
	{
		document.getElementById(nextCtlId).focus();
	}
}
//按回车键执行下一个控件的事件
function EnterToNextEvent(nextctlId)
{
	if (event.keyCode == 13)
	{
	    if(document.getElementById(nextctlId))
	    {
	        document.getElementById(nextctlId).focus();
	    	document.getElementById(nextctlId).click();
	    }
	    else 
	    {   
	        document.getElementById("prd_button").focus();
	    	document.getElementById("prd_button").click();
	    }
	}
}

function _IntE(v){return(v.search(/^[0-9]+$/)!=-1)||(v.search(/^-[0-9]+$/)!=-1)?1:0}


/************************************************************************************/
//首页模版用到
/************************************************************************************/
function ChangeCustomerCategory(index)
			{
				var page =document.getElementById("ddl_CustomerCategory").options[index].text;
				if(page!='select')
				{
					sUrl="";
					//document.getElementById("div_"+page).style.display ="";
					document.getElementById("selectCategory").value = page;
					document.getElementById("selectCategoryID").value = document.getElementById("ddl_CustomerCategory").options[index].value;
				}
			}
function AddCategory()
{
	//document.getElementById("div_"+page).style.display ="";
	var page = document.getElementById("selectCategory").value;
	if(page!="0")
	{
		if(document.getElementById("select_Save").value.indexOf(document.getElementById("selectCategoryID").value)== -1)
		{
			document.getElementById("div_"+page).style.display ="";
			document.getElementById("select_Save").value = document.getElementById("select_Save").value + document.getElementById("selectCategoryID").value+",";
		}
	}
	else
	{
		alert("请首先选择一种模式。");
	}
}
function DeleteCategoryID(name,id)
{
	document.getElementById("div_"+name).style.display="none";
	if (document.getElementById("select_Save").value.indexOf(id)!= -1)
	{ 
		document.getElementById("select_Save").value.substring(0,document.getElementById("select_Save").value.length-1);   
		var start = document.getElementById("select_Save").value.indexOf(id);
		if(start!=0)
		{
			document.getElementById("select_Save").value = document.getElementById("select_Save").value.substring(0,start)+
			document.getElementById("select_Save").value.substring(start+id.length+1);
		}
		else
		{
			document.getElementById("select_Save").value = document.getElementById("select_Save").value.substring(start+id.length+1);
		}
	}
	document.forms[0].submit();
}
function SaveCategory()
{
	document.forms[0].submit();
}




/************************************************************************************/
//发送Emial给好友
/************************************************************************************/
function clearInfo()
{
	document.getElementById("TextFriendEmail").value = "";
	document.getElementById("TextFriendName").value = "";
	document.getElementById("TextEmailTitle").value = "";
}


function _MailE(v){var s,r=/(\w+@\w+\.\w+)(\.{0,1}\w*)(\.{0,1}\w*)/i;	r.exec(v);if(RegExp.$3!=""&&RegExp.$3!="."&&RegExp.$2!=".")s=RegExp.$1+RegExp.$2+RegExp.$3;else if(RegExp.$2!=""&&RegExp.$2!=".")s=RegExp.$1+RegExp.$2;else s=RegExp.$1;if(s!=v)return 0;return 1}


function MailFormatValidate(emailAddress,id)
{
	
	if (_MailE(emailAddress) == 0 && document.getElementById(id).value!="")
	{
		alert("请输入一个有效的电子邮件地址。");
		document.getElementById(id).select();
		return false;
	}
	return true;
	
}
function checkdata()
{
  	if (document.getElementById("TextFriendEmail").value=="") 
	{ 
		alert("电子邮件地址不能为空。");
		document.getElementById("TextFriendEmail").focus();
		document.getElementById("TextFriendEmail").select();
		return false;
	}
	else
	{
		if(_MailE(document.getElementById("TextFriendEmail").value) == 0)
		{
		alert("请输入一个有效的电子邮件地址。");
		document.getElementById("TextFriendEmail").focus();
		document.getElementById("TextFriendEmail").select();
		return false;
		}

	}
	if (document.getElementById("TextFriendName") && document.getElementById("TextFriendName").value=="") 
	{ 
		alert("好友姓名不能为空。");
		document.getElementById("TextFriendName").focus();
		document.getElementById("TextFriendName").select();
		return false;
	}
	if (document.getElementById("TextEmailTitle") && document.getElementById("TextEmailTitle").value=="") 
	{ 
		alert("邮件标题不能为空。");
		document.getElementById("TextEmailTitle").focus();
		document.getElementById("TextEmailTitle").select();
		return false;
	}
	else
	{
		document.getElementById("hid_btSend").value="1";
		document.forms[0].submit();
		return true;
	}
}
function CheckValid()
{
	var ddl=document.getElementById("Category");
	document.getElementById("SearchHid").value="Search";
	
	if( document.getElementById("txtProductName").value == "")
	{
		if((document.getElementById("txtPrice01")!=undefined  &&  document.getElementById("txtPrice01").value=="") && (document.getElementById("txtPrice02")!=undefined &&  document.getElementById("txtPrice02").value==""))
		{	
			document.getElementById("txtProductName").focus();
			alert("请输入商品名称信息。");
			return false;
		}
	}
	
	
	if(document.getElementById("txtProductName").value != "")
	{
	    var b =document.getElementById("txtProductName").value.replace("'","").replace("&","").replace("^","").replace("$","").replace("#","");
	    document.getElementById("txtProductName").value=b;
	}
	return true;
}
function ChangePage(pageIndex)
{
    var a=	CheckValid();
    if(!a)
    return false;
     document.getElementById("SearchHid").value="Search";
     document.getElementById("hidPageIndex").value=pageIndex;
     
      document.forms[0].action="SearchResult.aspx";
      
     document.forms[0].submit();
 
}
 function ChangeSelect()
{
 document.getElementById("SearchHid").value="Category";

 document.forms[0].submit();
 
}

//查询分页操作
function JS_SearchBrowseCategory(PageID,ControlID)
{
	document.getElementById("Hid_CurrentPageID").value = PageID;
	if(document.getElementById("Butcategorysearch")!=undefined)
		document.getElementById("Butcategorysearch").click();
	else
		document.forms[0].submit();

}

//排序操作
function CategoryBrowseOrder(Name,OrderBy)
{
	document.getElementById("HidOrderEventName").value=Name;
	 
	 if(OrderBy=="ASC")
	   OrderBy="DESC";
	 else
	  OrderBy="ASC";
	  
		document.getElementById("HidOrderAsc").value=OrderBy;
  
 
	if(document.getElementById("Butcategorysearch"))
	{	
	   
		if(document.getElementById("Hid_CurrentPageID"))
		{
			document.getElementById("Hid_CurrentPageID").value = "0";
		}
		document.getElementById("Butcategorysearch").click();
	}
	else
	{
		document.forms[0].submit();
	}
}


function ClearData()
{ 
 
 document.getElementById("Category").selectedIndex = 0;
 document.getElementById("txtProductName").value="";
 if(document.getElementById("txtPrice01"))
    document.getElementById("txtPrice01").value="";
  if(document.getElementById("txtPrice02"))
 document.getElementById("txtPrice02").value="";
}



/************************************************************************************/
//新闻文章评论
/************************************************************************************/
function jsAjax(ContentID)
{
               var actionUrl="SaveComment.aspx?ContentID="+ ContentID + "&SaveComment=1";;
               var title="";
               if( document.getElementById("txtTitleID"))
            
               title=document.getElementById("txtTitleID").value;
               
               var  st="txtTitleID="+ title + "&txtBodyID="+ document.getElementById("txtBodyID").value ;


               var url = actionUrl ;
                var pars = st;
                    
                        var myAjax = new Ajax.Updater(
                                {success: ''},
                                url,
                                {method: 'post', parameters: pars, onFailure: reportError,onSuccess:reportSuccess}); 
            
         

}



function reportError(request)
 {
    alert('通信失败!');
}

function reportSuccess(request)
{
  alert("提交成功");
  document.getElementById("divCommentList").innerHTML="";
  document.getElementById("divCommentList").innerHTML= request.responseText;
  
   if( document.getElementById("txtTitleID"))
         document.getElementById("txtTitleID").value ="";
   document.getElementById("txtBodyID").value ="";
    
}
function GetCommentList(ContentID,PageNumber)
{

var actionUrl="SaveComment.aspx?ContentID="+ ContentID ;
                
            
               var  st="LoadPage="+PageNumber; ;


               var url = actionUrl ;
                var pars = st;
                    
                        var myAjax = new Ajax.Updater(
                                {success: ''},
                                url,
                                {method: 'post', parameters: pars, onFailure: reportError,onSuccess:reportSuccess}); 
    
}


function CommentSubmitEvent(ContentID)
{
    if(!document.getElementById("divUser"))
    {
      alert("请先登录，再进行评论!");

       return ;
    }
   if(document.getElementById("txtTitleID") && document.getElementById("txtTitleID").value.trim()=="")
    {
     alert("请输入标题");
     document.getElementById("txtTitleID").focus();
     document.getElementById("txtTitleID").select();
       return ;
    }
    if(document.getElementById("txtBodyID") && document.getElementById("txtBodyID").value.trim()=="")
    {
     document.getElementById("txtBodyID").focus();
     document.getElementById("txtBodyID").select();
     alert("请输入你的评论!");
     return;
    }
   
    
    
    jsAjax(ContentID);
}

            function DoAjaxLoginSubmit(filepath)
            {
                 AjaxLoginSubmit(document.getElementById("txb_LoginUser").value,document.getElementById("txb_LoginPwd").value,filepath);
            }
            var XMLHttpReq;
            var redirectURL;
            function createXMLHttpRequest()
            {   
                if (window.XMLHttpRequest)  
                {
                    XMLHttpReq = new XMLHttpRequest();   
                }
                 else if (window.ActiveXObject)  
                {
                    try {
                        XMLHttpReq = new ActiveXObject('Msxml2.XMLHTTP');     
                    } catch (e1)  
                    {  
                        try {
                            XMLHttpReq = new ActiveXObject('Microsoft.XMLHTTP'); 
                        } catch (e2) {}         
                    }  
                } 
                return XMLHttpReq; 
            } 

            function AjaxLoginSubmit(txtuserid,txtpwd,redirecturl)//url操作页面,data是要post的数据。
            {
                if(txtuserid.replace(/^\s+|\s+$/g,'')!= '')
                {
                    if(txtpwd!= '')
                    {
                    
                        redirectURL=redirecturl;
                        createXMLHttpRequest();

                        var url="checkPwd.aspx?act=login&email="+txtuserid+"&pwd="+ txtpwd;
                   
                         var  data ="txb_LoginUser=" + escape(txtuserid)+"@txb_LoginPwd="+escape(txtpwd);
                        XMLHttpReq.open("post",url,true);
                        XMLHttpReq.setRequestHeader("content-length",data.length);
                        XMLHttpReq.setRequestHeader("Content-Type", 'application/x-www-form-urlencoded');
                        XMLHttpReq.send(data);
                       
                        XMLHttpReq.onreadystatechange = processResponse;//响应请求函数 
                        
                    }
                    else
                    {
                        alert('登陆密码不能为空.');
                    }
                 }
                 else
                 {
                    alert('登陆Email不能为空');
                 }
              }
              function processResponse()
              {              
                    if (XMLHttpReq.readyState == 4)
                    {
                        try
                        {
                               if(XMLHttpReq.responseText=='False')
                                  alert('你输入的登陆Email或登陆密码有误,请重新输入.');
                                else          
                                 {
                            
                                    location.href=redirectURL ;
                                   }
                        }
                        catch(e)
                        {
                            alert('Error:异步出错.');
                        }
                    }
              }
              
              ///反对
             function  NewsCommentOppose(NewsCommentID,NewsID)
             { 
             if(!document.getElementById("divUser"))
                {
                  alert("请先登录，再进行评论!");

                   return ;
                }
                var actionUrl="SaveComment.aspx?NewsCommentID="+ NewsCommentID + "&Type=1&NewsID="+NewsID;
         
               
               var  st="NewsCommentID="+ NewsCommentID + "&Type=1&NewsID="+NewsID;


               var url = actionUrl ;
                var pars = st;
                    
                        var myAjax = new Ajax.Updater(
                                {success: ''},
                                url,
                                {method: 'post', parameters: pars, onFailure: reportError,onSuccess:reportSuccess}); 
             }
               
              ///支持
             function  NewsCommentSupport(NewsCommentID,NewsID)
             { 
                if(!document.getElementById("divUser"))
                {
                  alert("请先登录，再进行评论!");

                   return ;
                }
                     var actionUrl="SaveComment.aspx?NewsCommentID="+ NewsCommentID + "&Type=2&NewsID="+NewsID;
         
               
                 var  st="NewsCommentID="+ NewsCommentID + "&Type=2&NewsID="+NewsID;


                 var url = actionUrl ;
                 var pars = st;
                    
                        var myAjax = new Ajax.Updater(
                                {success: ''},
                                url,
                                {method: 'post', parameters: pars, onFailure: reportError,onSuccess:reportSuccess}); 
             }