var sLoading = "<img src='/images/loading.gif' />正在加载中...";

//兼容ie,ff 
function AddFavorite(sURL, sTitle)  
{  
   try  
   {  
       window.external.addFavorite(sURL, sTitle);  
   }  
   catch (e)  
   {  
       try  
       {  
            window.sidebar.addPanel(sTitle, sURL, "");  
        }  
        catch (e)  
        {  
            alert("加入收藏失败，请使用Ctrl+D进行添加");  
        }  
   }  
}  
  
function SetHome(obj,vrl){  
    try{  
        obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);  
    }  
    catch(e){  
        if(window.netscape) {  
            try {  
                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            }  
            catch (e)   {  
                alert("此操作被浏览器拒绝！请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");  
            }  
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);  
            prefs.setCharPref('browser.startup.homepage',vrl);  
        }  
   }  
}  

function mouseImage(elem,image,type) {
	switch(type){
	case 'over':
		image=image.substring(0,image.length-4);
		elem.src=image + '_over.gif';
		break;
		
	case 'out':	
		image=image.substring(0,image.length-9);
		image=image+'.gif';
		elem.src=image;
		break;
	}
}

function isNumber(s){
	var patrn=/^[0-9]{1,20}$/;
	if (!patrn.exec(s)) return false
	return true
}

//trim()
String.prototype.trim = function(){
    //用正则表达式将前后空格
    //用空字符串替代。
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//<--地区联动
var cldobj = "";
function getarealist(parentid,objcld)
{
	if(parentid == null || parentid == "")
	{
		return;
	}
	else if(parentid == "0")
	{
		return;
	}
	else
	{
		if(objcld != null && objcld != "") cldobj = objcld;
		AjaxObject.GetAreaList("","",parentid,areadatabind);
	}
}
function areadatabind(response)
{
	if (response.error != null)
	{
		return;
	}
	
	var obj = document.getElementById(cldobj);
	if (obj == null)
	{
		return;
	}
	var tb = response.value;
	if (tb == null || typeof(tb) != "object")
	{
		return;
	}
	
	var rowCount = tb.Rows.length;
	//alert(rowCount);
	obj.options.length = 0;
	if (rowCount>0)
	{
		obj.options[obj.options.length] = new Option("请选择", "");
		for (var i = 0; i < rowCount; i++)
		{
			obj.options[obj.options.length] = new Option(tb.Rows[i].text, tb.Rows[i].value);
			if(i == 0) {
			    obj.options[1].selected = true;
			}
		}
	}	
}
//-->

/*
//分类联动
var cldobj2 = "";
var cid = "";
function getcategorylist(parentid,objcld,objName)
{
	if(parentid == null || parentid == "")
	{
		return;
	}
	else if(parentid == "0")
	{
		return;
	}
	else
	{
		if(objcld != null && objcld != "") cldobj2 = objcld;
		cid = parentid;
        //var show_type_id = "show_"+objcld;
        //alert(document.getElementById(show_type_id).innerHTML);
        //document.getElementById(show_type_id).innerHTML='<select name="'+objName+'" name="'+objcld+'" size="15"><option value="">正在读取数据....</option></select>';
		AjaxObject.GetCategoryList(parentid,categorydatabind);
	}
}

function categorydatabind(response)
{
	if (response.error != null)
	{
		return;
	}
	
	var obj = document.getElementById(cldobj2);
	if (obj == null)
	{
		return;
	}
	var tb = response.value;
	if (tb == null || typeof(tb) != "object")
	{
		return;
	}
	
	var rowCount = tb.Rows.length;
	if(rowCount == 0)
	{
	    obj.style.display = "none";
	    //alert(cid);
	    getbrandlist(cid, 'brandList');
	    document.getElementById('brandList').style.display = "";
	}
	else
	{
	    obj.style.display = "";
	    //document.getElementById('brand_add1_brandList').style.display = "none";
	}
	//alert(rowCount);
	obj.options.length = 0;
	if (rowCount>0)
	{
		obj.options[obj.options.length] = new Option("-请选择子类-", "");
		for (var i = 0; i < rowCount; i++)
		{
			obj.options[obj.options.length] = new Option(tb.Rows[i].Name, tb.Rows[i].ID);
			if(i == 0) {
			    //obj.options[1].selected = true;
			}
		}
	}	
}
//end

//品牌
function getbrandlist(categoryid,objcld,objName)
{
	if(categoryid == null || categoryid == "")
	{
		return;
	}
	else if(categoryid == "0")
	{
		return;
	}
	else
	{
		if(objcld != null && objcld != "") cldobj2 = objcld;
        
		AjaxObject.GetBrandList(categoryid,branddatabind);
	}
}

function branddatabind(response)
{
	if (response.error != null)
	{
		return;
	}
	
	var obj = document.getElementById(cldobj2);
	if (obj == null)
	{
		return;
	}
	var tb = response.value;
	if (tb == null || typeof(tb) != "object")
	{
		return;
	}
	
	var rowCount = tb.Rows.length;
	//alert(rowCount);
	obj.options.length = 0;
	if (rowCount>0)
	{
		obj.options[obj.options.length] = new Option("-请选择品牌-", "");
		for (var i = 0; i < rowCount; i++)
		{
			obj.options[obj.options.length] = new Option(tb.Rows[i].Name, tb.Rows[i].ID);
			if(i == 0) {
			    //obj.options[0].selected = true;
			}
		}
	}	
}
//end
*/

function checkAll(chk)
{
	objckb = document.getElementsByName("ckb");
	for(var i=0; i<objckb.length; i++)
	{
		objckb[i].checked = chk;
	}
}

function getchecked(objname,val){
    if(val != "")
    {
        var obj = document.getElementsByName(objname);
        for(var i=0; i<obj.length; i++)
        {
            if(val.indexOf(","+obj[i].value+",")>=0){
                obj[i].checked = true;
            }
        }
    }
}

function newValidateNumber(digits){var validatePIC=document.getElementById("validatePIC");if(!digits)validatePIC.src="/ValidateCode.aspx?cnt=4&n="+Math.random();else validatePIC.src="/ValidateCode.aspx?cnt="+digits+"&n="+Math.random()}

function ValidateNumber(digits)
{
    var code = AjaxObject.GetCheckCode(digits).value;
    document.getElementById("checkCode").value = code;
    var validatePIC=document.getElementById("validatePIC");
    validatePIC.src="/ValidateCode.aspx?code=" + code; 
    
}
//关键字
function ShowKeywords(topNum)
{
    var submitData = "action=showkeyword&topNum=" + topNum;
    $.ajax({
	    type: "GET",
	    url: "/handler.aspx",
	    data: submitData,
	    //dataType: "xml",
	    cache:false,
	    success: function(result) {
		    $("#hot_keys").html(result);
	    },
	    error: function(){
		    //请求出错处理
		    //alert('加载错误！');
		    $("#hot_keys").html('加载错误！');
	    }
    });
}
//阅读数
function ShowHits(id)
{
    var submitData = "action=showhits&id=" + id;
    $.ajax({
	    type: "GET",
	    url: "/handler.aspx",
	    data: submitData,
	    //dataType: "xml",
	    cache:false,
	    success: function(result) {
		    $("#hits").html(result);
	    },
	    error: function(){
		    //请求出错处理
		    //alert('加载错误！');
		    $("#hits").html('加载错误！');
	    }
    });
}
//评论数
function ShowCommentCount(p_id)
{
    var submitData = "action=showcommentcount&p_id=" + p_id;
    $.ajax({
	    type: "GET",
	    url: "/handler.aspx",
	    data: submitData,
	    //dataType: "xml",
	    cache:false,
	    success: function(result) {
		    $("#comments").html(result);
	    },
	    error: function(){
		    //请求出错处理
		    //alert('加载错误！');
		    $("#comments").html('加载错误！');
	    }
    });
}
//本周热门信息
function ShowHotInfo(groupID,topNum)
{
    var submitData = "action=showhotinfo&groupID=" + groupID + "&topNum=" + topNum;
    $.ajax({
	    type: "GET",
	    url: "/handler.aspx",
	    data: submitData,
	    //dataType: "xml",
	    cache:false,
	    success: function(result) {
		    $("#list1").html(result);
	    },
	    error: function(){
		    //请求出错处理
		    //alert('加载错误！');
		    $("#list1").html('加载错误！');
	    }
    });
}

//广告信息
function ShowAdsInfo(groupID,type,divID,defImg)
{
    var submitData = "action=showadsinfo&groupID=" + groupID + "&type=" + type + "&defImg=" + defImg;
    //document.write(submitData);
    //alert(submitData);
    $.ajax({
	    type: "GET",
	    url: "/handler.aspx",
	    data: submitData,
	    //dataType: "xml",
	    cache:false,
	    success: function(result) {
		    $("#"+divID).html(result);
	    },
	    error: function(){
		    //请求出错处理
		    //alert('加载错误！');
		    $("#"+divID).html('加载错误！');
	    }
    });
}

function imageAutoSize(width,height)
{
    $("img").each(function()
    {
        if(this.width>width)
        {
            this.width = width;
            this.height = width/this.width*this.height;
        }
//        if(this.height>height)
//        {
//            this.height = height;
//            this.width = height/this.height*this.width;
//        } 
    });
}
//品牌列表
function ShowBrandList(page,pageSize)
{
    var result = AjaxObject.ShowBrandList(page,pageSize).value;
    //alert(result);
    $("#brandList").html(result);
    //分页
    ShowBrandPagination(page,pageSize);
}

function ShowBrandPagination(page,pageSize)
{   
    var result = AjaxObject.ShowBrandPagination(page,pageSize).value;
    //alert(result);
    $("#paginationList").html(result);
}
//新闻列表
function ShowNewsList(cid,page,pageSize,model)
{
    var result = AjaxObject.ShowNewsList(cid,page,pageSize,model).value;
    //alert(result);
    $("#newsList").html(result);
    //分页
    ShowNewsPagination(cid,page,pageSize,model);
}

function ShowNewsPagination(cid,page,pageSize,model)
{   
    var result = AjaxObject.ShowNewsPagination(cid,page,pageSize,model).value;
    //alert(result);
    $("#paginationList").html(result);
}

function ShowHomeNewsList()
{
    var result = AjaxObject.ShowHomeNewsList().value;
    $("#homeNewsList").html(result);
}
//分类显示
function ShowCategoryNav(categoryID,code)
{
    $("#category_list").html(sLoading);
    AjaxObject.GetCategoryNav(categoryID,code,categoryNavCallBack);
    
}
function categoryNavCallBack(result)
{
    $("#category_list").html(result.value);
}
//热门产品排行榜
function ShowHotCommodityListByCategory(categoryID)
{
    $("#hot_prolist").html(sLoading);
    AjaxObject.ShowHotCommodityListByCategory(categoryID,hotCategoryNavCallBack);
    
}
function hotCategoryNavCallBack(result)
{
    $("#hot_prolist").html(result.value);
}

//最具人气商品
function ShowHotCommodityList()
{
    $("#pro_hotlist").html(sLoading);
    AjaxObject.ShowHotCommodityList(hotCommodityCallBack);
}
function hotCommodityCallBack(result)
{
    $("#pro_hotlist").html(result.value);
}
//最新商品
function ShowNewCommodityList()
{
    $("#newest_list").html(sLoading);
    AjaxObject.ShowNewCommodityList(newCommodityCallBack);
}
function newCommodityCallBack(result)
{
    $("#newest_list").html(result.value);
}
//满意度商品
function ShowSatisCommodityList()
{
    $("#satis_list").html(sLoading);
    AjaxObject.ShowSatisCommodityList(satisCommodityCallBack);
}
function satisCommodityCallBack(result)
{
    $("#satis_list").html(result.value);
}
//价格指数商情
function ShowPriceCommodityList()
{
    $("#pro_price_content").html(sLoading);
    AjaxObject.ShowPriceCommodityList(priceCommodityCallBack);
}
function priceCommodityCallBack(result)
{
    $("#pro_price_content").html(result.value);
}
//重点推荐商品
function ShowRecommendCommodityList()
{
    $("#recommend_list").html(sLoading);
    AjaxObject.ShowRecommendCommodityList(recommendCommodityCallBack);
}
function recommendCommodityCallBack(result)
{
    $("#recommend_list").html(result.value);
}
//商品参数
function ShowCommodityParamList(categoryID,commodityID)
{
    $("#nav_content").html(sLoading);
    AjaxObject.ShowCommodityParamList(categoryID,commodityID,commodityParamCallBack);
}
function commodityParamCallBack(result)
{
    $("#nav_content").html(result.value);
}

//
function ShowCategorySearchList(minPrice,maxPrice,keyword,categoryID)
{
    $("#categorylist").html(sLoading);
    AjaxObject.ShowCategorySearchList(minPrice,maxPrice,keyword,categoryID,categorySearchCallBack);
}
function categorySearchCallBack(result)
{
    $("#categorylist").html(result.value);
}


//调整图片宽度和高度
//调用:<img onload="ResizeImage(this,80,80);" />
var imageObject;
function ResizeImage2(obj, MaxW, MaxH)
{
    if (obj != null) imageObject = obj;
    var state=imageObject.readyState;
	if(state!='complete') {
        setTimeout("ResizeImage2(null,"+MaxW+","+MaxH+")",50);
		return;
    }
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW=oldImage.width; var dH=oldImage.height;
    if(dW>MaxW || dH>MaxH) {
        a=dW/MaxW;
        if(MaxH>0){b=dH/MaxH;}else{b=1;}
        if(b>a) a=b;
        dW=dW/a; dH=dH/a;
        if(oldImage.width>MaxW && MaxH==0){imageObject.style.cursor="pointer",imageObject.alt="点击'+oldImage.width+'查看原图！",imageObject.onclick=function(){window.open(imageObject.src)}}
    }
    if(dW > 0 && dH > 0) {
        imageObject.width=dW;
		imageObject.height=dH;
	}
}

// <img src="xx.gif" width="xxx" height="yyy" onerror="this.src='zz.gif'" 
//      onload="resizeImage(this,xxx,yyy)" border="0">

function resizeImage(prmImageElement,prmLenLong,prmLenShort){
  var imgobj = new Image();
  imgobj.src = prmImageElement.src;
  var len_long = prmLenLong;
  var len_short = prmLenShort;
  var w = imgobj.width;
  var h = imgobj.height;
  if (w >= h) {
    if(w < len_long){
      prmImageElement.width = w;
      prmImageElement.height = h;
    } else {
      prmImageElement.width = len_long;
      if(h == 0){
        prmImageElement.height = len_short;
      } else {
        prmImageElement.height = len_long * h / w;
      }
    }
  } else {
    if(h < len_long){
      prmImageElement.width = w;
      prmImageElement.height = h;
    } else {
      prmImageElement.height = len_long;
      if(w == 0){
        prmImageElement.width = len_short;
      } else {
        prmImageElement.width = len_long * w / h;
      }
    }
  }
}


function ImageLoading(src,divID,url)
{
    var img = new EnhancedImage(src,onImageLoad,divID,url);
    img.load();
}
function onImageLoad(image,divID,url){
    //document.body.appendChild(image.image);
    document.getElementById(divID).innerHTML = url;
    //alert("image loaded and the size is " + image.width + "*" + image.height);
}

function EnhancedImage(src,onLoaded,divID,url){
    var self = this;
    this.src = src;
    this.width = 0;
    this.height = 0;
    this.onLoaded = onLoaded;
    this.loaded = false;
    this.image = null;
    
    this.load = function(){
        if(this.loaded)
            return;
        this.image = new Image();
        this.image.src = this.src;
        function loadImage(){
            if(self.width != 0 && self.height != 0){
                clearInterval(interval);
                self.loaded = true;
                self.onLoaded(self,divID,url);//将实例传入回调函数
            }
            else
            {
                document.getElementById(divID).innerHTML = "加载中...";
            }
            self.width = self.image.width;//是number类型
            self.height = self.image.height;
        }
        var interval = setInterval(loadImage,100);
    }
}

function onSearch()
{
    var keyword;
    keyword = $('#keyword').val();
    if(keyword == "")
    {
        alert('请输入搜索关键字！');
        $('#keyword').focus();
        return;
    }
    keyword = encodeURI(keyword);

    var cid;
    cid = $('#searchBox1_ddlCategory').val()
    if(typeof(cid) == "undefined")
        cid = "";

    //alert("/search/" + keyword + "-" + tp + "-1");
    window.location.href= "/search_price1_1_" + cid + "_0-0/" + keyword;
}

function onSearch2(divID)
{
    var keyword,minprice=0,maxprice=0;
    keyword = $(divID).val();
    if(keyword == "")
    {
        alert('请输入搜索关键字！');
        $(divID).focus();
        return false;
    }
    keyword = encodeURIComponent(keyword);
    
    minprice = $('#minprice').val();
    maxprice = $('#maxprice').val();
    if(minprice == null || minprice == '')
        minprice = 0;
    if(maxprice == null || maxprice == '')
        maxprice = 0; 

    //alert("/search/" + keyword + "-" + tp + "-1");
    window.location.href= "/search_price1_1__" + minprice + "-" + maxprice + "/" + keyword;
}

function onDealerSearch(divID)
{
    var keyword,minprice=0,maxprice=0,sortby='price1';
    keyword = $(divID).val();
    if(keyword == "")
    {
        alert('请输入搜索关键字！');
        $(divID).focus();
        return false;
    }
    keyword = encodeURI(keyword);
    
    minprice = $('#minprice').val();
    maxprice = $('#maxprice').val();
    if(minprice == null || minprice == '')
        minprice = 0;
    if(maxprice == null || maxprice == '')
        maxprice = 0;    
    
    sortby = $('#sortby').val();
    
    //alert("/search_" + sortby + "_1__" + minprice + "-" + maxprice + "/" + keyword);
    //window.location.href= "/search_" + sortby + "_1__" + minprice + "-" + maxprice + "/" + keyword;
    window.open("/search_" + sortby + "_1__" + minprice + "-" + maxprice + "/" + keyword);
}

function selectTab(val, categorycd){
  if(val == "" || val > 6){
    val = 1;
  }
  
  for(var i = 1; i <= 6; i++){
    var elem = document.getElementById("li" + i);
    if(elem == null) continue;
    if(elem.className != "none"){
      if(i == val){
        elem.className="now";
        document.getElementById("toggle_tab" + i).style.display = "block";
        $.cookie("ItemList_tab", val);
        
        //alert($.cookie("ItemList_tab") + "=" + i);
      } else {
        elem.className="off";
        document.getElementById("toggle_tab" + i).style.display = "none";
      }
    }
  }
  
  //alert($.cookie("ItemList_tab"));
}

function Toggle_close(){
  document.getElementById('itembox').style.display="none";
  document.getElementById('tr03').style.display="none";
  document.getElementById('tr04').style.display="none";
  document.getElementById('tr05').style.display="none";
  document.getElementById('tr07').style.display="block";
  document.getElementById('tr06').style.display="block";
  document.getElementById('toggle1').style.display="none";
  document.getElementById('toggle2').style.display="block";
  $.cookie("ItemList_toggle", "close");
}

function Toggle_open(){
  document.getElementById('itembox').style.display="block";
  document.getElementById('tr03').style.display="block";
  document.getElementById('tr04').style.display="block";
  document.getElementById('tr05').style.display="block";
  document.getElementById('tr06').style.display="none";
  document.getElementById('tr07').style.display="none";
  document.getElementById('toggle1').style.display="block";
  document.getElementById('toggle2').style.display="none";
  $.cookie("ItemList_toggle", "open");
}

function toggleComment(val)
{
    if(val==0)
    {
        $('#isAnonymous').val('1');
    }
    else
    {
        $('#isAnonymous').val('0');
    }
}
/*经销商留言*/
function submitDealerGuestbook(dealerID)
{
    var content = "", contact = ""
    
    content = $('#content').val();
    if(content == '')
    {
        alert('请输入评论内容！');
        $('#content').focus();
        return;
    }
    
    if(content.length > 2000)
    {
        alert('评论内容字数应不大于2000！');
        $('#content').focus();
        return;
    }
    
    contact = $('#contact').val();
    if(contact == '')
    {
        alert('请输入联系方式！');
        $('#contact').focus();
        return;
    }

    var result = AjaxObject.AddDealerGuestbook(content,contact,dealerID).value;
    if(result == "")
    {
        alert('发布成功！');
        $('#content').val('');
        $('#contact').val('');
        //ValidateNumber(4);
        window.location.reload();
    }
    else
    {
        alert('发布失败！' + result);
    }
}

//回复经销商留言
function replyDealerGuestbook()
{
    var content = "",id = "0";
    
    content = $('#replycontent').val();
    if(content == '')
    {
        alert('请输入回复内容！');
        $('#replycontent').focus();
        return;
    }
    
    if(content.length > 2000)
    {
        alert('回复内容字数应不大于2000！');
        $('#replycontent').focus();
        return;
    }
    
    id = $('#hdnID').val();
    if(parseInt(id) <= 0)
    {
        alert('错误！');
        return;   
    }
    
    var result = AjaxObject.ReplyDealerGuestbook(id,content).value;
    if(result == "")
    {
        alert('回复留言成功！');
        window.location.reload();
    }
    else
    {
        alert('发布失败！' + result);
    }
}

//经销商发布QQ
function submitDealerQQ()
{
    var cnt = $('#hdnCounts').val();
    if(cnt >= 4)
    {
        alert('最多可以添加4个QQ号码!');
        return;
    }
    
    var codeName = "", remark = "", orderID = "0", id = "0";
    
    codeName = $('#codeName').val();
    if(codeName == '')
    {
        alert('请输入QQ号！');
        $('#codeName').focus();
        return;
    }
    
    orderID = $('#orderID').val();
    if(!isNumber(orderID))
    {
        alert('顺序为数字！');
        return false;
    }
    remark = $('#remark').val();
    id = $('#hdnID').val();
    
    var result = AjaxObject.SetDealerQQ(id,codeName,remark,orderID).value;
    if(result == "")
    {
        alert('提交成功！');
        window.location.reload();
    }
    else
    {
        alert('提交失败！' + result);
    }
}

//经销商友情链接
function submitDealerLink()
{
    var cnt = $('#hdnCounts').val();
    if(cnt >= 15)
    {
        alert('最多可以添加15个友情链接!');
        return;
    }
    
    var title = "", url = "", orderID = "0", id = "0";
    
    title = $('#title').val();
    if(title == '')
    {
        alert('请输入网站名称！');
        $('#title').focus();
        return;
    }
    url = $('#url').val();
    if(url == '')
    {
        alert('请输入网站地址！');
        $('#url').focus();
        return;
    }
    
    orderID = $('#orderID').val();
    if(!isNumber(orderID))
    {
        alert('顺序为数字！');
        return false;
    }
    
    id = $('#hdnID').val();
    
    var result = AjaxObject.SetDealerLink(id,title,url,orderID).value;
    if(result == "")
    {
        alert('提交成功！');
        window.location.reload();
    }
    else
    {
        alert('提交失败！' + result);
    }
}

//经销商模块设置
function dealerModuleSet(dealerID,name,isShow,param)
{
    var result = "";
    result = AjaxObject.DealerModuleSet(dealerID,name,isShow,param).value;
        
    if(result == "")
    {
        alert('设置成功！');
        top.location.reload();
    }
    else
    {
        alert('设置失败！' + result);
    }
}

function dealerModulesSet(dealerID,showlist,orderlist)
{
    var result = "";
    result = AjaxObject.DealerModulesSet(dealerID,showlist,orderlist).value;
        
    if(result == "")
    {
        alert('设置成功！');
        top.location.reload();
    }
    else
    {
        alert('设置失败！' + result);
    }
}

//字体设置
function dealerFontSet(dealerID,fontFamily,fontColor,fontSize)
{
    var result = AjaxObject.DealerFontSet(dealerID,fontFamily,fontColor,fontSize).value;
    
    if(result == "")
    {
        alert('设置成功！');
        top.location.reload();
    }
    else
    {
        alert('设置失败！' + result);
    }
}

//模板设置
function dealerTemplateSet(dealerID,tempID)
{
    var result = AjaxObject.DealerTemplateSet(dealerID,tempID).value;
    
    if(result == "")
    {
        alert('设置成功！');
        top.location.reload();
    }
    else
    {
        alert('设置失败！' + result);
    }
}

//删除经销商留言
function delDealerGuestbook(id)
{
    var result = AjaxObject.DelDealerGuestbook(id).value;
    
    if(result == "")
    {
        alert('删除成功！');
        top.location.reload();
    }
    else
    {
        alert('删除失败！' + result);
    }
}

/*商品留言*/
//m =1 会员
function submitCommodityComment(categoryID,commodityID,m,options)
{
    var content = "", ratings = "", fieldCodeName = "";
    var isMember = false;
    var isAnony = 0;
    
    for(var i=1; i<options+1; i++)
    {
        if(ratings == "")
            ratings += $('#stars-wrapper' + i).data('stars').options.value;
        else
            ratings += "," + $('#stars-wrapper' + i).data('stars').options.value;
    }
    fieldCodeName = $('#fieldCodeName').val();
    //alert(ratings + fieldCodeName);
    isAnony = $('#isAnonymous').val();
    content = $('#content').val();
    if(content == '')
    {
        alert('请输入评论内容！');
        $('#content').focus();
        return;
    }
    
    if(content.length > 2000)
    {
        alert('评论内容字数应不大于2000！');
        $('#content').focus();
        return;
    }
    
    if($('#validateNumber').val() == '' || $('#validateNumber').val().length < 0)
    {
        alert('请输入验证码！');
        $('#validateNumber').focus();
        return;
    }
    
    if($('#validateNumber').val().toLowerCase() != $('#checkCode').val().toLowerCase())
    {
        alert('验证码不匹配！');
        $('#validateNumber').focus();
        return;
    }
    
    isMember = m==1?true:false;
    
    //alert(commodityID+"="+isMember+"="+isAnony+"="+content+"="+ratings+"="+fieldCodeName);
    var result = AjaxObject.SaveCommodityComment(categoryID,commodityID,isMember,isAnony,content,ratings,fieldCodeName).value;
    if(result == "")
    {
        alert('发布成功！');
        $('#content').val('');
        $('#validateNumber').val('');
        ValidateNumber(4);
        ShowCommodityCommentList(categoryID,commodityID,1,5);
        //window.parent.location.reload();
    }
    else if(result == "请先登录！")
    {
        alert("请先登录！");
    }
    else
    {
        alert('发布失败！' + result);
    }
}

function ShowCommodityCommentList(categoryID,commodityID,page,pageSize)
{
    if(page == "" || page == null)
        page = 1;
        
    if(pageSize == "" || pageSize == null)
        pageSize = 10;
    
    //$("#comment_list").html("<img src='/images/loading.gif' \/>正在加载中...");
    
    //alert(p_id+"="+page);    
    var result = AjaxObject.ShowCommodityCommentList(categoryID,commodityID,page,pageSize).value;
    //alert(result);
    $("#comment_list").html(result);
    //分页
    ShowCommodityCommentPagination(categoryID,commodityID,page,pageSize);
}

function ShowCommodityCommentPagination(categoryID,commodityID,page,pageSize)
{   
    var result = AjaxObject.ShowCommodityCommentPagination(categoryID,commodityID,page,pageSize).value;
    //alert(result);
    $("#commentPageList").html(result);
}

/*首页会员登录*/
function fncDealerLogin()
{
    var record = false;
    var dealerName = $("#dealerName").val();
	var dealerPass = $("#dealerPass").val();
	
	if(dealerName == null || dealerName == "")
	{
	    alert('请输入登录名！');
	    $("#dealerName").focus();
	    return false;
	}
	
	if(dealerPass == null || dealerPass == "")
	{
	    alert('请输入密码！');
	    $("#dealerPass").focus();
	    return false;
	}
	
	var result = AjaxObject.CheckDealerLogin(dealerName,dealerPass,record).value;
    if(result)
        window.location.href='/dealer/manage/';
    else
    {
        alert('登陆失败！');
        $("#dealerName").focus();
    }
}

function fncPersonLogin()
{
    var record = false;
    var userName = $("#userName").val();
	var userPass = $("#userPass").val();
	
	if(userName == null || userName == "")
	{
	    alert('请输入登录名！');
	    $("#userName").focus();
	    return false;
	}
	
	if(userPass == null || userPass == "")
	{
	    alert('请输入密码！');
	    $("#userPass").focus();
	    return false;
	}
	
	var result = AjaxObject.CheckPersonLogin(userName,userPass,record).value;
    if(result)
        window.location.href='/';
    else
    {
        alert('登陆失败！');
        $("#userName").focus();
    }
}

/*article*/
//热门信息
function ShowHotArticleList(categoryID,topNum)
{
    var submitData = "action=showhotarticlelist&categoryID=" + categoryID + "&topNum=" + topNum;
    $.ajax({
	    type: "GET",
	    url: "/handler.aspx",
	    data: submitData,
	    //dataType: "xml",
	    cache:false,
	    success: function(result) {
		    $("#hot_content").html(result);
	    },
	    error: function(){
		    //请求出错处理
		    //alert('加载错误！');
		    $("#hot_content").html('加载错误！');
	    }
    });
}
