﻿// JScript 文件

//有选中时的打勾DIV
var selectedDIV = '<div  class="selected" >√</div>';

//过滤［］“等字符
var reg=/\[|\]|"/g;

var curTime = new Date().getTime();
var operateSep = 1000; //控制鼠标操作频率1.5秒

$(document).ready(function(){ 
        $("#menu1_ul1").find("li").each(function(i){
			$(this).click(function(){			   
			    ShowProductCate(i,this);
			     
		   });
		});   

		InitPageInfo();
});

//############################# 显示头部的子标题####################################


//#############################################################   页面初始化方法开始  #################################################################

//初始化页面显示
function InitPageInfo()
{
        //读取COOKIE数据
        GetCookieData();

        //显示产品类别
        DisplayLeft_ProductCate();
        DisplayRight_ProductCateData(); 
        
        //显示国家
        DisplayLeft_Country();
        DisplayRight_CountryData();
        
        //显示KEYWORD
        DisplayLeft_Keyword();
        DisplayRight_Keyword()
        
        //显示business nature
        DisplayLeft_BN();
        
}


//显示右边产品类别数据
function DisplayRight_ProductCateData()
{ 
        $.ajax({
             type: "POST",
             url: "doRequest.ashx",
             data: {t:4,strid:strCateIDList},
             dataType:"json",
             timeout:10000,
             beforeSend:function(){
                                    $("#divCategoryUL").append("<div id='divCateRightStatus'><img src='images/loading_small.gif' border='0' id='imgLoadingRightCate'/></div>");
                        },
             complete:function(res,msg){ 
                                   $("#imgLoadingRightCate").remove();
                                   if(res.status == 0)//请求超时
                                   {
                                        $("#divCateRightStatus").append(strTimeOut);
                                   }
                                   else if(res.status == 200)//请求成功
                                   {    
                                        $("#divCateRightStatus").remove();
                                        var resAry = null;
                                        var tmp = '';
                                        eval("resAry = "+ res.responseText);
                                        if(resAry !=null)
                                        {
                                          
                                            for(i=0;i<resAry.data.length;i++)
                                            {
                                                tmp ="";
                                                if($("#liCategory"+resAry.data[i].CateChar).find(".selected").size()<=0)
                                                {                
                                                    //显示打勾
                                                    $("#liCategory"+resAry.data[i].CateChar).find("span").before(selectedDIV);
                                                }
                                                if(document.getElementById("C"+resAry.data[i].CCID).checked != true)
                                                {
                                                    //子类打勾             
                                                    //$("#C"+resAry.data[i].CCID).trigger("click"); 
                                                    $("#C"+resAry.data[i].CCID).attr("checked",true);
                                                    GetSubCategory(resAry.data[i].CCID,resAry.data[i].CCName,lang , resAry.data[i].CateChar , document.getElementById("C"+resAry.data[i].CCID),false);
                                                }
                                            }
                                            if(resAry.data.length > 0)
                                            {
                                                $("#liCategory"+resAry.data[0].CateChar).trigger("click");
                                                $("#divSubCategory"+resAry.data[0].CateChar).show();
                                            }
                                            else
                                            {
                                                $("#divCheckAllA").hide();
                                                $("#divCheckAllB").hide();
                                                $("#divCheckAllC").hide();
                                                $("#divCheckAllD").hide();
                                                $("#divCheckAllE").hide();
                                                $("#ulBigCategoryA").hide();
                                                $("#ulBigCategoryB").hide();
                                                $("#ulBigCategoryC").hide();
                                                $("#ulBigCategoryD").hide();
                                                $("#ulBigCategoryE").hide();
                                                
                                                $("#divCategoryUL").find(".nonDisplay").hide();
                                                $("#menu1_ul1").find("li .selected").remove();
                                            }
                                        }
                                   }
                                   else//发生错误
                                   {
                                       $("#productservice").show();
                                       $("#divCateRightStatus").append(strError);
                                       
                                   }
                      }
      });
}

//显示右边国家
function DisplayRight_CountryData()
{
   //默认参数设为2(英文)
     if(arguments.length==0){   
          pLang   =   2;   
      }    
    
     $.ajax({
             type: "POST",
             url: "doRequest.ashx",
             data: {t:5,strid:strCountryIDList},
             dataType:"json",
             timeout:10000,
             beforeSend:function(){
                                    $("#divCountryContain").find(".AreaCountry").hide();
                                    $("#divCountryContain").append("<div id='divCountryRightStatus'><img src='images/loading_small.gif' border='0' id='imgLoadingRightCountry'/></div>");
                        },
             complete:function(res,msg){ 
                                   $("#imgLoadingRightCountry").remove();
                                   
                                   if(res.status == 0)//请求超时
                                   {
                                        $("#divCountryRightStatus").append(strTimeOut);
                                   }
                                   else if(res.status == 200)//请求成功
                                   {
                                        var resAry = null;
                                        eval("resAry = "+ res.responseText);
                                        if(resAry !=null)
                                        {                                            
                                            for(i=0;i<resAry.data.length;i++)
                                            {           
                                                 if($("#liArea"+resAry.data[i].AreaUID).find(".selected").size()<=0)
                                                 {                
                                                      //显示打勾
                                                      $("#liArea"+resAry.data[i].AreaUID).find("span").before(selectedDIV);
                                                 }
                                            }
                                            if(resAry.data.length > 0)
                                            {
                                                $("#liArea"+resAry.data[0].AreaUID).trigger("click");
                                            }
                                            else
                                            {
                                                $(".AreaCountry").hide();
                                                $("#menu1_ul2").find("li .selected").remove();
                                            }
                                        }
                                   }
                                   else//发生错误
                                   {
                                       $("#divCountryRightStatus").append(strError);
                                   }
                      }
      }); 
   
}
//显示KEYWORD
function DisplayRight_Keyword()
{   
    if(aryKeyword != null)
    {  
            if(aryKeyword[0].indexOf(SepKeywordChar) > 0)
            {
                var aryKey = aryKeyword[0].split(SepKeywordChar);
                $("#selSearchType").val(aryKey[0]);
                $("#txtSearchKey").val(aryKey[2]);
            }  
    }
}



//#############################################################   页面初始化方法结束  #################################################################


//#############################################################   产品类别方法开始  #################################################################

//显示产品类别,菜单
function ShowProductCate(i,li)
{
    var curIndex = i+1;
    $("#menu1_ul1").find("li").not(".li"+curIndex).children("span").removeAttr("class");    
    
    $("#divCheckAllA").hide();
    $("#divCheckAllB").hide();
    $("#divCheckAllC").hide();
    $("#divCheckAllD").hide();
    $("#divCheckAllE").hide();
    $("#ulBigCategoryA").hide();
    $("#ulBigCategoryB").hide();
    $("#ulBigCategoryC").hide();
    $("#ulBigCategoryD").hide();
    $("#ulBigCategoryE").hide();
    $("#divCategoryUL").find(".nonDisplay").hide();
      
    $(li).children("span").toggleClass("span"+(i+1));
    var css=$(li).children("span").attr("css");
   //有钩钩就显示标题 
    if(css==null)
      { $("#productservice").hide();}
      else
      {$("#productservice").show();}  
    
    if($(li).children("span").attr("class") != "")
    {
        $("#ulBigCategory"+String.fromCharCode(65+i)).show();
        $("#divCheckAll"+String.fromCharCode(65+i)).show();
        $("#divSubCategory"+String.fromCharCode(65+i)).show();
        $("#productservice").show(); 
        //有钩钩就显示标题 
       
    }
    else
    {
        $("#ulBigCategory"+String.fromCharCode(65+i)).hide();
        $("#divCheckAll"+String.fromCharCode(65+i)).hide();
        $("#divSubCategory"+String.fromCharCode(65+i)).hide(); 
    }
}

//获得子类
//Cid:父类ID，CName：父类名，Language：1代表中文，2代表英文,CategoryChar:类别ID中开头字母,bFly:是否调用特效
function GetSubCategory(Cid,CName,Language,CategoryChar,ckb,bFly)
{
    var i = 0;
    var sum =0;
    if(ckb.checked)
    {
        //$("#divSubCategory" + CategoryChar).append("<img src='images/loading.gif' border='0' id='imgLoading"+Cid+"'/>").show();
        //$.post("doRequest.ashx",{t:"2",cid:Cid,cname:CName,lang:Language,categorychar:CategoryChar},GetSubCategoryResponse,'json');
        $.ajax({
             type: "POST",
             url: "doRequest.ashx",
             data: {t:"2",cid:Cid,cname:CName,lang:Language,categorychar:CategoryChar},
             dataType:"json",
             timeout:10000,
             beforeSend:function(){
                                    $("#divSubCategory" + CategoryChar).append("<img src='images/loading.gif' border='0' id='imgLoading"+Cid+"'/>").show();    
                        },
             complete:function(res,msg){ 
                                   $("#divSubCategory" + CategoryChar).find("img").not(".imgSubCategoryTitle").remove(); 
                                   if(res.status == 0)//请求超时
                                   {
                                        $("#divSubCategory" + CategoryChar).append(strTimeOut);
                                   }
                                   else if(res.status == 200)//请求成功
                                   {
                                        var resAry = null;
                                        eval("resAry = "+ res.responseText);
                                        if(resAry != null)
                                        {
                                            //显示子子类
                                            GetSubCategoryResponse(resAry);
                                            
                                            //子子类打勾特效
                                            if(bFly)
                                            {
                                                Fly(3,CategoryChar,Cid,"");
                                            }
                                        }
                                   }
                                   else//发生错误
                                   {
                                        $("#divSubCategory" + CategoryChar).append(strError);
                                   }
                      }
        });        
    }
    else
    {
        $("#imgLoading" + Cid).remove();
        $("#ct"+Cid).remove();
        $("#ul"+Cid).remove();
        $("#divSubCategoryCheckAll"+Cid).remove();
        
        //如果没有选中的子类，子子类清空
        if($("#divSubCategory"+CategoryChar).find("ul").size()==0) 
            $("#divSubCategory"+CategoryChar).empty();
            
        Fly(2,CategoryChar,Cid,"");  
     }
     $("#ulBigCategory"+CategoryChar).find("li input").each(function(){
            if($(this).attr("checked"))
            {
                i++;
            }
            sum++;
    });
    if(i == sum)
    {
        $("#all"+CategoryChar).attr("checked",true);
    }
    else
    {
        $("#all"+CategoryChar).removeAttr("checked");
    }
}

//获得子类
function GetSubCategoryResponse(res)
{
    $("#imgLoading" + res.cid).remove();
    if(res.data!="" && $("#C"+res.cid).attr("checked")==true)
    {
        var cateItem = '';
        var cateName = '';
        var strChecked = '';
        var htmlCate = '<h3 class="checked_title_black" id="ct' + res.cid + '">' + res.cname + '</h3>';
        var htmlCate = '<div class="title_all_wrap" id="ct' + res.cid + '"><h3 class="checked_title_black">' + res.cname + '</h3>'+
                       '<div class="check_all_r"><input type="checkbox" id="allSubCategory' + res.cid + '" name="allSubCategory' + res.cid + '" onclick="return selectAll(this,\''+ res.categorychar +'\',\''+res.cid+'\');" value="' + res.cid + '"/><label for="allSubCategory' + res.cid + '">'+strAll+'</label></div></div>';
  
        htmlCate += '\n<ul class="check_big_category" id="ul' + res.cid + '">';
        var aryIdList = null;
        eval("aryIdList = ["+strCateIDList+"];");
        
        var checkNum = 0;
        var flag = false;
        for(i=0;i<res.data.length;i++)
        {
            if(res.lang == 1)
                cateName = res.data[i].CName_Chi;
            else
                cateName = res.data[i].CName_Eng;                

            //判断是否选中
            if(aryIdList != null)
            {
                flag = false;
                for(j=0;j<aryIdList.length;j++)
                {
                    if(res.data[i].CID == aryIdList[j])
                    {
                         flag = true;
                         break;
                    }
                }
            }
            if(flag)
            {
                strChecked = ' checked="checked"';
                checkNum++;
            }
            else
            {
                strChecked = '';
            }

            htmlCate += '<li><input type="checkbox" id="SC' + res.data[i].CID +'" name="SC' + res.data[i].CID  +'"' + strChecked + ' value="' + res.data[i].CID + '" onclick="return ProductCateCheckClick(this,\''+ res.categorychar +'\','+res.cid+','+res.data[i].CID+');"/><label id="CateLabel2_' + res.data[i].CID +'" for="SC' + res.data[i].CID + '">' + cateName +'</label></li>';
         }
         htmlCate += '</ul>';
         
         if($("#divSubCategory"+res.categorychar).html() == '') 
            $("#divSubCategory"+res.categorychar).append(subCategoryTitle);
         $("#divSubCategory"+res.categorychar).append(htmlCate);
         
         //子类checkall 是否打勾
         if(checkNum == $("#ul"+ res.cid).find("li").size() || checkNum == 0)
         {
            $("#allSubCategory"+res.cid).attr("checked",true);
         }
         //令子子类全选
         if(checkNum == 0)
         {
            $("#ul"+ res.cid).find("input[type=checkbox]").attr("checked",true);
         }
    }
}
//点击产品子子类复选框事件
//obj:复选框对象，CategoryCahr:大类首字母，ccid:子类ID，ccname:子类名，cccid:子子类ID，cccname:子子类名
function ProductCateCheckClick(obj,CategoryChar,ccid,cccid)
{   
    var $divStop = $('<div id="divCateStop'+cccid+'" style="display: none; background-color: #bbb; border:1px solid #aaa;z-index: 9999;border:solid 1px blue;"> </div>').prependTo("body");
    var $parent = $("#divCategoryUL");
    $divStop.css({
                'width' : $parent.width(),
                'height': $parent.height(),
                'position' : 'absolute',
                'top' : $parent.offset().top,
                'left' : $parent.offset().left,
                'opacity' : 0                 
             }).show();     
    if(obj.checked == true)
    {
        Fly(1,CategoryChar,ccid,cccid);    
        
        var i = 0;
        var sum = 0;
        $("#ul"+ccid).find("li input").each(function(){
                if($(this).attr("checked"))
                    i++;
                sum++;
        });
        if(i==sum)
            $("#allSubCategory"+ccid).attr("checked",true);
    }   
    else
    {
        Fly(0,CategoryChar,ccid,cccid);
        
        $("#allSubCategory"+ccid).removeAttr("checked");
    } 
}
//特效:t:1代表增加单个类别，0代表删减单个类别，2代表删减整个子类下的子子类,
//       3子类全选复选框打勾，4子类全选复选框去勾
function Fly(t,CateChar,ccid,cccid)
{
      var $from = null;
      var $to = null;
      //增加单个类别
      if(t==1)
      {
            $from = $("#SC"+cccid);
              
            if(!document.getElementById("LeftCate_" + CateChar + "_" + ccid))
            {
                $("#LeftCate_" + CateChar).show();
                $to = $("#LeftCate_" + CateChar);
            }
            else
            {
                $to = $("#LeftCate_" + CateChar + "_" + ccid);
            }

      }
      else if(t==0)//删减单个类别
      {
            $from = $("#LeftCate_" + CateChar + "_" + ccid);
            $to = $("#SC"+cccid);
      }
      else if(t==2)//删减整个子类下的子子类
      {
            if(!document.getElementById("LeftCate_" + CateChar + "_" + ccid))
                return;
            $from = $("#LeftCate_" + CateChar + "_" + ccid);
            $to = $("#C"+ccid);
      }
      else if(t==3)//子类全选打勾
      {
            $from = $("#ul"+ccid);
            if(!document.getElementById("LeftCate_" + CateChar + "_" + ccid))
            {
                $("#LeftCate_" + CateChar).show();
                $to = $("#LeftCate_" + CateChar);
            }
            else
            {
                $to = $("#LeftCate_" + CateChar + "_" + ccid);
            }
      }
      else if(t==4)//子类全选去勾
      {
            $from = $("#LeftCate_" + CateChar + "_" + ccid);
            $to = $("#ul"+ccid);
      }
      
      //删除页面中已经有的 阴影
      $("#fly_shadow").remove();
      
      //创建阴影div
      var $shadow = $(flyDiv).prependTo("body");    
      
      //利用img标签的宽度，高度，上边距等属性来设置阴影div
      $shadow.css({
                'width' : $from.css('width'),
                'height': $from.css('height') ,
                'position' : 'absolute',
                'top' : $from.offset().top,
                'left' : $from.offset().left,
                'opacity' : 0.6                 
             })
             .show();
       
      $shadow.animate({ 
                  width: $to.innerWidth(), 
                  height: $to.innerHeight(), 
                  top: $to.offset().top, 
                  left: $to.offset().left,
                  opacity: 0
             },  { duration: 600 , complete: function(){    

                    if(t==1)
                    {
                        //添加产品到COOKIE并显示      
                        AddProductCate(CateChar,ccid,cccid);
                    }
                    else if(t==0)
                    {
                        //添加产品到COOKIE并显示      
                        DelProductCate(CateChar,ccid,cccid);
                    }   
                    else if(t==2)
                    {                  
                        //清空其在aryProductCate中的子子类
                        ClearSubCategory(ccid,CateChar);
                    }
                    else if(t==3 || t==4)
                    {
                        var index = -1;
                        var ckb = document.getElementById("allSubCategory"+ccid);
                        $("#ul"+ccid).find("input[type=checkbox]").each(function(){
                            this.checked = ckb.checked;
                            if(ckb.checked)
                            {
                                AddProductCate(CateChar,ccid,$(this).val());
                            }
                            else
                            {
                                index = IsInArray(aryProductCate.idList,$(this).val());
                                if(index >= 0)
                                {
                                    aryProductCate.idList.splice(index,1);
                                    aryProductCate.objList.splice(index,1);   
                                }
                             }
                        });                                           
                    }
                    
                    //更新strCateIDList变量
                    FreshStrCateIDList();
                    
                    //更新左边显示
                    DisplayLeftCate(t,CateChar,ccid,cccid);
                    
                  
                    //设置菜单打勾
                    SetMenuSelected(CateChar);
                    
                    //删除特效DIV
                    $(this).remove();
                    
                    $("#divCateStop"+cccid).remove();
                    
                 } 
             });     
}

//勾选子子类
function AddProductCate(CategoryChar,ccid,cccid)
{ 
    if(IsInArray(aryProductCate.idList,cccid) < 0)
    {
        aryProductCate.idList.push(cccid);
        var bigCate = {CateChar:CategoryChar,CCID:ccid,CCCID:cccid}
        aryProductCate.objList.push(bigCate);
         
        if($("#liCategory"+CategoryChar).find(".selected").size() == 0)
        {
            $("#liCategory"+CategoryChar).find("span").before(selectedDIV);
        }
    }
}
//更新左边显示:t:1代表增加单个类别，0代表删减单个类别，2代表删减整个子类下的子子类
function DisplayLeftCate(t,CateChar,ccid,cccid)
{
    var tmpHtml = '';
    if(t==1)//增加单个类别
    {
            if(!document.getElementById("LeftCate_"+CateChar+"_"+ccid))
            {
                tmpHtml = '<dl id="LeftCate_' + CateChar + '_' + ccid + '" class="dl_search">';
                tmpHtml +='<dt class="dl_title">'+$("#CateLabel_"+ccid).html();
                tmpHtml +='</dt><dd id="LeftCate_'+CateChar+'_'+ccid+'_'+cccid+'">';
                tmpHtml += $("#CateLabel2_"+cccid).html();
                tmpHtml +='</dd></dl>';
                $("#LeftCate_"+CateChar).append(tmpHtml);
            }
            else
            {
                tmpHtml ='<dd id="LeftCate_'+CateChar+'_'+ccid+'_'+cccid+'">';
                tmpHtml += $("#CateLabel2_"+cccid).html();
                tmpHtml +='</dd>';
                $("#LeftCate_"+CateChar+"_"+ccid).append(tmpHtml);
            }
    }
    else if(t==0)//删减单个类别
    {
        $("#LeftCate_" + CateChar + "_" + ccid + "_" + cccid).remove();
        if($("#LeftCate_" + CateChar + "_" + ccid).find("dd").size() <= 0)
        {
            $("#LeftCate_" + CateChar + "_" + ccid).remove();
        }
        if($("#LeftCate_" + CateChar).find("dl").size() <= 0)
        {
            $("#LeftCate_" + CateChar).hide();
        }
    }
    else if(t==2||t==4)//删减整个子类下的子子类 || 去掉子子类中全选勾
    {
        $("#LeftCate_" + CateChar + "_" + ccid).remove();
        if($("#LeftCate_" + CateChar).find("dl").size() <= 0)
        {
            $("#LeftCate_" + CateChar).hide();
        }
    }
    else if(t==3)//子子类中全选打勾
    {
        var tmp = '';
        $("#ul"+ccid).find("li").each(function(){
            tmp += '<dd id="LeftCate_'+CateChar+'_'+ccid+'_'+ $(this).find("input").attr("value") +'">';
            tmp += $(this).find("label").html();
            tmp += '</dd>';
        });
        
        if(!document.getElementById("LeftCate_"+CateChar+"_"+ccid))
        {
            tmpHtml = '<dl id="LeftCate_'+CateChar+'_'+ccid+'" class="dl_search">';
            tmpHtml +='<dt class="dl_title">'+$("#CateLabel_"+ccid).html();
            tmpHtml +='</dt>';
            tmpHtml += tmp;
            tmpHtml +='</dl>';
            $("#LeftCate_"+CateChar).append(tmpHtml);
        }
        else
        {
            tmpHtml ='<dt class="dl_title">'+$("#CateLabel_"+ccid).html();
            tmpHtml +='</dt>'+tmp;
            
            $("#LeftCate_"+CateChar+"_"+ccid).html(tmpHtml);
        }
        
        $("#LeftCate_"+CateChar+"_"+ccid).show();       
        
    }
}
//去除子子类
function DelProductCate(CategoryChar,ccid,cccid)
{
    var aryIndex = IsInArray(aryProductCate.idList,cccid);
    if(aryIndex >= 0)
    {
        aryProductCate.idList.splice(aryIndex,1);           
        aryProductCate.objList.splice(aryIndex,1);
    }
}
//设置是否在产品菜单上打勾
function SetMenuSelected(CategoryChar)
{
    var flag = false;
    for(i=0;i< aryProductCate.objList.length;i++)
    {
        if(aryProductCate.objList[i].CateChar == CategoryChar)
        {
            flag=true;
            break;
        }
    }
    if(!flag && $("#liCategory"+CategoryChar).find(".selected").size() > 0)
    {
        $("#liCategory"+CategoryChar).find(".selected").remove();
    }
}
//清除aryProductCate中某一子类下的子类
function ClearSubCategory(ccid,CategoryChar)
{
    var i = 0;
    while(i < aryProductCate.objList.length)
    {
        if(aryProductCate.objList[i].CCID == ccid)
        {
           aryProductCate.idList.splice(i,1); 
           aryProductCate.objList.splice(i,1);
        }
        else
        {
            i++;
        }
    }
}

//大类全选
function BigCateSelectAll(ckb)
{
    var preTime = curTime;
    curTime = new Date().getTime();
    
    if(curTime - preTime <= operateSep)
    {
        alert(strOperate);
        return false;
    }
             
    if(ckb.checked)
    {
        $("#ulBigCategory"+$(ckb).val()).find("input[type=checkbox]").each(function(){
            if(this.checked!=true)
            {
                $(this).trigger("click") ;
            }
        });
    }
    else
    {
        $("#ulBigCategory"+$(ckb).val()).find("input[type=checkbox]").each(function(){
            if(this.checked==true)
                $(this).trigger("click") ;
        });
    }
    $("#divBigCateStop" + $(ckb).val()).remove();
}

//子类全选
function selectAll(ckb,CategoryChar,ccid)
{ 
    var preTime = curTime;
    curTime = new Date().getTime();
    
    if(curTime - preTime <= operateSep)
    {
        alert(strOperate);
        return false;
    }
    
    var t= ckb.checked ? 3: 4;
    Fly(t,CategoryChar,ccid,"");        
}


//#############################################################   产品类别方法结束  #################################################################


//#############################################################   市场方法开始  #####################################################################

//获取国家列表：AreaID:地区ID，IndexNum:显示DIV索引号，Language：1代表中文，2代表英文
function GetCountryByAreaID(AreaID,IndexNum,Language)
{
    //初始菜单
    $(".AreaCountry").find("img").remove();
    $("#menu1_ul2").find("li").not("#liArea"+AreaID).children("span").removeAttr("class");
    $(".AreaCountry").not("#divCountry"+AreaID).hide();
    $("#liArea"+AreaID).children("span").toggleClass("span"+IndexNum);  
    
    //设置对应显示隐藏
    if($("#divCountry"+AreaID).is(":hidden"))
    {
        $("#divCountry"+AreaID).show(); 
         
        //第一次时请求数据
        if($("#divCountry"+AreaID).html() == "")
        {
            $.ajax({
             type: "POST",
             url: "doRequest.ashx",
             data: {t:"3",aid:AreaID,lang:Language,index:IndexNum},
             dataType:"json",
             timeout:10000,
             beforeSend:function(){
                                  $("#divCountry"+AreaID).append("<img src='images/loading.gif' border='0' id='imgLoadingArea"+AreaID+"'/>");  
                        },
             complete:function(res,msg){ 
             
                                   $("#divCountry"+AreaID).find("img").remove(); 
                                   
                                   if(res.status == 0)//请求超时
                                   {
                                          $("#divCountry"+AreaID).html(strTimeOut);   
                                   }
                                   else if(res.status == 200)//请求成功
                                   {
                                          var resAry = null;
                                               eval("resAry = "+ res.responseText);
                                          if(resAry != null)
                                                GetCountryByAreaIDResponse(resAry);
                                   }
                                   else//发生错误
                                   {
                                          $("#divCountry"+AreaID).html(strError);   
                                   }
                      }
             });//end of $.ajax
        }//end of if($("#divCountry"+AreaID).html() == "")
    }
    else
    {
        $("#divCountry"+AreaID).hide(); 
    }
}
//显示国家
function GetCountryByAreaIDResponse(res)
{
    $("#imgLoadingArea"+res.aid).remove();
    if(res.data!="")
    {
        var countryName = '';
        var strChecked = '';
        var htmlAreaCountry = '<div class="check_all" id="divArea' + res.aid + '"><input type="checkbox" id="allArea' + res.aid + '"  name="allArea' + res.aid + '" onclick="return SelectAllCountry('+ res.aid + ',this);" value="' + res.aid + '"/><label for="allArea' + res.aid + '" >'+strAll+'</label></div>  ';
        htmlAreaCountry += '\n<ul class="check_big_category" id="ulArea' + res.aid + '">';
        
        //用来判断是否已选
        //var strIdList = Serialize(aryCountry.idList);        
        var iChecked = 0;   
             
        var aryIdList = null;
        eval("aryIdList = ["+strCountryIDList+"];");
        var flag = false;
        
        for(i=0;i<res.data.length;i++)
        {
            if(res.lang == 1)
                countryName = res.data[i].CName_Chi;
            else
                countryName = res.data[i].CName_Eng;
             
            //判断是否选中   
            if(aryIdList != null)
            {
                flag = false;
                for(j=0;j<aryIdList.length;j++)
                {
                    if(res.data[i].CID == aryIdList[j])
                    {
                         flag = true;
                         break;
                    }
                }
            }
            if(flag)
            {
                strChecked = ' checked="checked"';
                iChecked++;
            }
            else
            {
                strChecked = '';
            }

                
            htmlAreaCountry += '<li><input type="checkbox" id="Country' + res.data[i].CID + '" name="Country' + res.data[i].CID + '"' + strChecked + ' value="' + res.data[i].CID + '" onclick="CountryCheckClick(this,' + res.aid + ',' + res.data[i].CID + ','+ res.index + ');"/><label id="labelCountry'+res.data[i].CID+'" for="Country' + res.data[i].CID + '">' + countryName + '</label></li>';
         }
         htmlAreaCountry += '</ul>';
         
         if($("#divCountry"+res.aid).html() == '') 
            $("#divCountry"+res.aid).html(htmlAreaCountry).show();     
            
         if(iChecked == res.data.length)
            $("#allArea"+res.aid).attr("checked",true);       
    }
}
//点击产品子子类复选框事件
//obj:复选框对象，adi:地区ID，cid:国家ID，index:DIV序号
function CountryCheckClick(obj,aid,cid,index)
{
    var $divCountryStop = $('<div id="divCountryStop'+cid+'" style="display: none; background-color: #bbb; border:1px solid #aaa;z-index: 9999;border:solid 1px blue;"> </div>').prependTo("body");
    var $parent = $("#divCountryContain");
    $divCountryStop.css({
                'width' : $parent.width(),
                'height': $parent.height(),
                'position' : 'absolute',
                'top' : $parent.offset().top,
                'left' : $parent.offset().left,
                'opacity' : 0                 
             }).show(); 


    if(obj.checked == true)
    {
        Fly2(1,aid,cid,index);  
        
        var i = 0;
        var sum = 0;
        $("#ulArea"+aid).find("li input").each(function(){
                if($(this).attr("checked"))
                    i++;
                sum++;
        });
        if(i==sum)
            $("#allArea"+aid).attr("checked",true);
    }   
    else
    {
        Fly2(0,aid,cid,index);
        
        $("#allArea"+aid).removeAttr("checked");
    } 
}
//特效:t:1代表增加单个类别，0代表删减单个类别，2代表删减整个子类下的子子类,
//       3子类全选复选框打勾，4子类全选复选框去勾
function Fly2(t,aid,cid,index)
{
      var $from = null;
      var $to = null;
      
      if(t==1)//增加单个国家
      {
              $from = $("#Country"+cid);
              
              if(!document.getElementById("LeftCountry_" + aid))
              {
                    $to = $("#divLeftCountry");
              }
              else
              {
                    $to = $("#LeftCountry_" + aid);
              }
      }
      else if(t==0)//删减单个国家
      {
            $from = $("#LeftCountry_" + aid + "_" + cid);
            $to = $("#Country"+cid);
      }
      else if(t==2)//增加整个地区下国家
      {
            $from = $("#divCountry"+aid);
            if(!document.getElementById("LeftCountry_" + aid))
            {
                $to = $("#divLeftCountry");
            }
            else
            {
                $to = $("#LeftCountry_" + aid);
            }
      }
      else if(t==3)//删减整个地区下国家
      {
            if(!document.getElementById("divLeftCountry_" + aid))
                return;
            $from = $("#LeftCountry_" + aid);
            $to = $("#divCountry"+aid);
      }
      
      
      //删除页面中已经有的 阴影
      $("#country_shadow").remove();
      
      //创建阴影div
      var $shadow = $(flyDiv).prependTo("body");    
      
      //利用img标签的宽度，高度，上边距等属性来设置阴影div
      $shadow.css({
                'width' : $from.css('width'),
                'height': $from.css('height') ,
                'position' : 'absolute',
                'top' : $from.offset().top,
                'left' : $from.offset().left,
                'opacity' : 0.6                 
             })
             .show();
       
      $shadow.animate({ 
                  width: $to.innerWidth(), 
                  height: $to.innerHeight(), 
                  top: $to.offset().top, 
                  left: $to.offset().left,
                  opacity: 0
             },  { duration: 600 , complete: function(){    
                    
                    if(t==1)
                    {
                        //勾选国家到COOKIE并显示      
                        AddCountry(aid,cid,index);
                    }
                    else if(t==0)
                    {
                        //勾选国家到COOKIE并显示      
                        DelCountry(aid,cid,index);
                    }   
                    else if(t==2)//增加整个地区下国家
                    { 
                        $("#ulArea"+aid).find("input[type=checkbox]").each(function(){
                            if(this.checked !=true)
                            {
                                AddCountry(aid,$(this).val(),index);
                                this.checked = true;
                            }
                        });
                    } 
                    else if(t==3)//删减整个地区下国家
                    { 
                        var aryIndex = -1;
                        $("#ulArea"+aid).find("input[type=checkbox]").each(function(){
                            if(this.checked ==true)
                            {
                                aryIndex = IsInArray(aryCountry.idList,$(this).val());
                                if(aryIndex >= 0)
                                {
                                    aryCountry.idList.splice(aryIndex,1);
                                    aryCountry.objList.splice(aryIndex,1);   
                                }
                                this.checked = false;
                            }
                        });
                    }
                    //更新左边显示
                    DisplayLeftCountry(t,aid,cid,index);
                    
                    //设置菜单打勾
                    SetAreaMenuSelected(index,aid);
                    
                    //删除特效DIV
                    $(this).remove();
                    
                    $("#divCountryStop"+cid).remove();
                 } 
             });     
}
//更新左边国家显示,特效后显示
function DisplayLeftCountry(t,aid,cid,index)
{
    var tmp = '';
    if(t==1)//增加单个国家
    {
        if(!document.getElementById("divLeftCountry_" + aid))
        {
            tmp +='<div id="divLeftCountry_' + aid + '"><h3 class="h3_search2" id="h3Country_' + aid + '">'+ $("#liArea"+aid).find("span").text() +'</h3>';
            tmp +='<dl id="LeftCountry_' + aid + '" class="dl_search">';
			tmp +='<dd id="LeftCountry_' + aid + '_' + cid + '">' + $("#labelCountry"+cid).text() +'</dd>';
            tmp +='</dl></div>';
            $("#divLeftCountry").append(tmp);
        }
        else
        {
            tmp += '<dd id="LeftCountry_' + aid + '_' + cid + '">' + $("#labelCountry"+cid).text() +'</dd>';
            $("#LeftCountry_" + aid).append(tmp);
        }
    }
    else if(t==0)//删减单个国家
    {
        $("#LeftCountry_" + aid + "_" + cid).remove();
        if($("#LeftCountry_" + aid).find("dd").size() <= 0)
        {
            $("#divLeftCountry_" + aid).remove();
        }
    }
    else if(t==2)//增加整个地区下国家
    {
        var tmpHtml = '';
        $("#ulArea"+aid).find("li").each(function(){
            tmpHtml += '<dd id="LeftCountry_' + aid + '_' + $(this).find("input").attr("value") + '">' + $(this).find("label").text() +'</dd>';
        });
        if(!document.getElementById("divLeftCountry_" + aid))
        {
            tmp +='<div id="divLeftCountry_' + aid + '"><h3 class="h3_search2" id="h3Country_' + aid + '">'+ $("#liArea"+aid).find("span").text() +'</h3>';
            tmp +='<dl id="LeftCountry_' + aid + '" class="dl_search">';
			tmp +=tmpHtml;
            tmp +='</dl></div>';
            $("#divLeftCountry").append(tmp);
        }
        else
        {
            $("#LeftCountry_" + aid).html(tmpHtml);
        }
    }
    else if(t==3)//删减整个地区下国家
    {
        $("#divLeftCountry_" + aid).remove();
    }
}

//勾选国家
function AddCountry(aid,cid,index)
{
    if(IsInArray(aryCountry.idList,cid)< 0)
    {
        aryCountry.idList.push(cid);
           
        var country = {AID:aid,CID:cid}
        aryCountry.objList.push(country);
         
        if($("#liArea"+aid).find(".selected").size() == 0)
        {
            $("#liArea"+aid).find("span").before(selectedDIV);
        }
    }
}
//去除子子类
function DelCountry(aid,cid,index)
{
    var aryIndex = IsInArray(aryCountry.idList,cid);
    if(aryIndex >= 0)
    {
        aryCountry.idList.splice(aryIndex,1);
        aryCountry.objList.splice(aryIndex,1);
        
        var flag = false;
        for(i=0;i< aryCountry.objList.length;i++)
        {
            if(aryCountry.objList[i].AID == aid)
            {
                flag=true;
                break;
            }
        }
        if(!flag && $("#liArea"+aid).find(".selected").size() > 0)
        {
            $("#liArea"+aid).find(".selected").remove();
        }
    }
}

//所有国家全选
function SelectAllCountry(cid,ckb)
{
    var preTime = curTime;
    curTime = new Date().getTime();
    if(curTime - preTime <= operateSep)
    {
        alert(strOperate);
        return false;
    }
    
    if(ckb.checked)
    {
        Fly2(2,ckb.value,cid,"");
    }
    else
    {
        Fly2(3,ckb.value,cid,""); 
    }
    return true;
}
//设置是否在地区菜单上打勾
function SetAreaMenuSelected(IndexNum,aid)
{
    var flag = false;
    for(i=0;i< aryCountry.objList.length;i++)
    {
        if(aryCountry.objList[i].AID == aid)
        {
            flag=true;
            break;
        }
    }
    if(!flag && $("#liArea"+aid).find(".selected").size() > 0)
    {
        $("#liArea"+aid).find(".selected").remove();
    }
}

//#############################################################   市场方法结束  #####################################################################


//点击搜索(英文）
function SearchClick_Eng()
{
    var sel= parseInt($("#selSearchType").val()) ;
    
    //如果填了关键字但未选类型则提示
    if(sel == 0 && $.trim($("#txtSearchKey").val()) != "")
    {
        alert(strSelectKeywordType);
        $("#selSearchType").focus();
        return;
    }
    
    var strKeyValue = sel > 0 ? $("#txtSearchKey").val() : "";
    
    if((aryProductCate == null ||aryProductCate.idList.length ==0) && (aryCountry == null ||aryCountry.idList.length ==0) && (sel == 0 || $.trim(strKeyValue) == ""))
    {
        alert(strBasicSearchAlert);
    }
    else
    {
        WritePageInfoToCookie();
    
        window.location.href = "MD_SearchResult.aspx?t=b";
    }
    
}

//点击搜索（中文）
function SearchClick_Cht()
{
    var sel= parseInt($("#selSearchType").val()) ;
    
    //如果填了关键字但未选类型则提示
    if(sel == 0 && $.trim($("#txtSearchKey").val()) != "")
    {
        alert(strSelectKeywordType);
        $("#selSearchType").focus();
        return;
    }
    
    var strKeyValue = sel > 0 ? $("#txtSearchKey").val() : "";
    
    if((aryProductCate == null ||aryProductCate.idList.length ==0) && (aryCountry == null ||aryCountry.idList.length ==0) && (sel == 0 || $.trim(strKeyValue) == ""))
    {
        alert(strBasicSearchAlert);
    }
    else
    {
        
        WritePageInfoToCookie();
    
        window.location.href = "MD_SearchResult_cht.aspx?t=b";
    }
}

//重置
function ResetClick()
{   
    $("#selSearchType").val("0");
    $("#txtSearchKey").val("");
  
    //数组清空
    aryProductCate.idList.splice(0,aryProductCate.idList.length);
    aryProductCate.objList.splice(0,aryProductCate.objList.length);
    aryCountry.idList.splice(0,aryCountry.idList.length);
    aryCountry.objList.splice(0,aryCountry.objList.length);    
    
    //将TAB中上折放下
    $("#menu1_ul1").find("li span").removeAttr("class");
    $("#menu1_ul2").find("li span").removeAttr("class");
    
    //还原JS变量
    preAreaSelected = -1;
    preCateSelected = -1;
    
    //重置页面表单
    $(".AreaCountry").find("input").removeAttr("checked");
    $("#divCategoryUL").find("input").removeAttr("checked");
    $("#divCategoryUL").find(".nonDisplay").html("");
    
    
    //将页面数据定进COOKIE  
    WritePageInfoToCookie();  
    InitPageInfo()

}

function WritePageInfoToCookie()
{   
    var sel= parseInt($("#selSearchType").val()) ;
    var selText = sel > 0 ? $("#selSearchType option[@selected]").text() : "";
    var txtKeyValue = sel > 0 ? $("#txtSearchKey").val() : "";
    
    if(aryKeyword != null)
    {
         strKeyword = sel + SepKeywordChar + selText + SepKeywordChar + txtKeyValue +"|" + aryKeyword[1] + "|" + aryKeyword[2] + "|" + aryKeyword[3];
    }
    else
    {
        strKeyword =  sel + SepKeywordChar + selText + SepKeywordChar + txtKeyValue + "| | | ";  
    }
    
    //刷新三个字符串变量
    FreshStrCateIDList();
    FreshStrCountryIDList();
    FreshStrBNIDList();
    
    //business nature的ID,在页面中OTHER是很多ID的集合,所以在存储到COOKIE的时候要分别作下判断再组合
    if(strBNIDList != "")
    {
        if(aryBN.oidList !="") strBNIDList += ","+aryBN.oidList;
    }
    else
    {
        strBNIDList = aryBN.oidList == "" ? " " : aryBN.oidList;
    }
    
    DelCookie(ckMD);
    SetCookie(ckMD,strCateIDList + SepString + strCountryIDList + SepString + strBNIDList + SepString + strKeyword);
}

//刷新strCateIDList变量
function FreshStrCateIDList()
{
    strCateIDList = Serialize(aryProductCate.idList).replace(reg,"")=="" ? "  ":Serialize(aryProductCate.idList).replace(reg,"");
}
//刷新strCountryIDList变量
function FreshStrCountryIDList()
{
    strCountryIDList = Serialize(aryCountry.idList).replace(reg,"")=="" ? "  ":Serialize(aryCountry.idList).replace(reg,"");
}
//刷新strBNIDList变量
function FreshStrBNIDList()
{
    strBNIDList = Serialize(aryBN.idList).replace(reg,"")=="" ? "  ":Serialize(aryBN.idList).replace(reg,"");
}

