﻿/*
*author:刘惦惦
*email:9146797@qq.com
*started at 2009-9-22
*@fileoverview 全站统一Ajax
*version:1.0
*/
var Config_Domain="52huapai.com";
var Config_SiteDefault="http://www."+Config_Domain;
var Config_SiteBBS="http://bbs."+Config_Domain;
var Config_Ajax=Config_SiteDefault+"/admin/Ajax/";
var UserData={id:0,username:"",cid:"",ctype:0};
//优化setTimeout
var _st = window.setTimeout;
if(!window.setTimeout.constructor)
window.setTimeout = function(fRef, mDelay) {
    if(typeof fRef == 'function'){
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){ fRef.apply(null, argu); });
        return _st(f, mDelay);
    }
    return _st(fRef,mDelay);
};
//优化setInterval
var _int = window.setInterval;
if(!window.setInterval.constructor)
window.setInterval = function(fRef, mDelay) {
    if(typeof fRef == 'function'){
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){ fRef.apply(null, argu); });
        return _int(f, mDelay);
    }
    return _int(fRef,mDelay);
};
String.prototype.ReplaceHtml=function()
{
   var str=this.valueOf();
    var re=new RegExp("<(.[^><]*)>","ig");
    str=str.replace(re,"");
    return str;
};
String.prototype.RemoveUnsafeHtml=function()
{
    var RegScript=new RegExp("<script(.|\n)*?>(.|\n)*?<\/script>","ig");
    var RegIframe=new RegExp("<iframe(.|\n)*?>(.|\n)*?<\/iframe>","ig");
    var RegInput=new RegExp("<input(.|\n)*?>","ig"); 
    var RegForm=new RegExp("<form(.|\n)*?>(.|\n)*?<\/form>","ig");
    var RegStyle=new RegExp("<style(.|\n)*?>(.|\n)*?<\/style>","ig");
    var RegFrameset=new RegExp("<frameset(.|\n)*?>(.|\n)*?<\/frameset>","ig");
    var str=this.valueOf();
    str=str.replace(RegScript,"");
    str=str.replace(RegIframe,"");
    str=str.replace(RegInput,"");
    str=str.replace(RegForm,"");
    str=str.replace(RegStyle,"");
    str=str.replace(RegFrameset,"");
    return str;
};
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
};
var Fid=function(obj)
{
    return document.getElementById(obj);
};
//是否空值
function Fempty(v){return((""==v||undefined==v||null==v)?true:false);};
//优化字符串
var StringBuffer=function()
{this._string=new Array;};
StringBuffer.prototype.append=function(str)
{
  this._string.push(str);
};
StringBuffer.prototype.toString=function()
{
  return this._string.join("");
};
//基类
var HuaSys={};

//显示/隐藏htmlselect控件
HuaSys.HtmlSelect=
{
    show:function()
    {
        $("select").each(function(){$(this).css("visibility","visible");});
    },
    hide:function()
    {
        $("select").each(function(){$(this).css("visibility","hidden");});
    }
    
};
HuaSys.Ajax=
{
    getscript:function(url,data,iscatch)
    {
       if(!Fempty(data))
       {
          if(url.indexOf("?")>0)
              {
                 url=url+"&"+data;
              }
              else
              {
                 url=url+"?"+data;
              }
       }
       if(!Fempty(iscatch))
       {
          if(iscatch==false)
          {
              if(url.indexOf("?")>0)
              {
                 url=url+"&r="+Math.random();
              }
              else
              {
                 url=url+"?r="+Math.random();
              }
          }
       }
       $.getScript(url,function()
       {
          if(typeof _CallBack!="undefined")
          {
             HuaSys.DisposeInfo(_CallBack);
          }
          else
          {
             HuaSys.PopWindow.error();
          }
       }
       );
    },
   ajax:function(method,url,data)
   {
      $.ajax({
        type:method,
        url:url,
        data:data,
        dataType:"text",
        success:function(json)
        {
           if(typeof json !="undefined")
           {
              _CallBack={SignInfo:json};
              HuaSys.DisposeInfo(_CallBack);
           }
           else
           {
              HuaSys.PopWindow.error();
           }
        },
        error:function()
        {
           HuaSys.PopWindow.error();
        }
      });
   },
   param:function(a)
   {
     var s = [];
		if ( a.constructor == Array || a.jquery )
			jQuery.each( a, function(){
				s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
			});
		else
			for ( var j in a )
				if ( a[j] && a[j].constructor == Array )
					jQuery.each( a[j], function(){
						s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
					});
				else
					s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
		return s.join("&").replace(/%20/g, "+");
   }
};
//弹出效果
HuaSys.PopWindow={
    careatePanl:function(title,noclose)
    {
       if(noclose)
       {
            HuaTemplate.WindowsPanl.PopWindowNoClose();
       }
       else
       {
            HuaTemplate.WindowsPanl.PopWindow();
       }
       
        $("#WindowBackGround").css("display","block");
        $("#WindowBackGround").width(document.body.clientWidth);
        $("#WindowBackGround").height(document.body.clientHeight);
        $("#Window_Msg_Container").css("display","block");
        if($.browser.msie) 
        {
            $("#Window_Msg_Container").css("marginLeft",-220); 
        }
        else 
        {
            $("#Window_Msg_Container").css("marginLeft",-220)
        }
       
        
        $("#Window_Msg_Container").css("marginTop",-50+document.documentElement.scrollTop);
        $("#Window_Title").html(title);
        HuaSys.HtmlSelect.hide();
       
    },
    show:function(strform,title,width,noclose)
    {
       HuaSys.PopWindow.careatePanl(title,noclose);
//       if(UserData.id==0)
//       {
//          HuaSys.PopWindow.error(HuaSys.ErrInfo.notlogin);
//          return ;
//       }
       if(typeof width !="undefined")
       {
           $("#Window_Msg_Container").width(width);
           $("#Window_Msg_Container").css("marginLeft",-220);
           $("#Window_Msg_Container").css("marginTop",-150+document.documentElement.scrollTop);
       }
       else
       {
          $("#Window_Msg_Container").width(440);
       }
       $("#Window_Msg_Info").css("display","block");
       $("#Window_Msg_Info").html(strform);
        
    },
    hide:function()
    {
      $("#WindowBackGround").css("display","none");
      $("#Window_Msg_Container").css("display","none");
      $("#Window_Msg_Info").css("display","none");
      //$("#Window_Msg_Info").html("");
      $("#Window_Msg").css("display","none");
      
      //$("#Window_Msg").html("");
      HuaSys.HtmlSelect.show();
    },
     hideparent:function()
    {
      parent.$("#WindowBackGround").css("display","none");
      parent.$("#Window_Msg_Container").css("display","none");
      parent.$("#Window_Msg_Info").css("display","none");
      //$("#Window_Msg_Info").html("");
      parent.$("#Window_Msg").css("display","none");
      
      //$("#Window_Msg").html("");
      HuaSys.HtmlSelect.show();
    },
    error:function(errinfo)
    {
       if(typeof errinfo=='undefined')
       {
           errinfo="系统忙,请稍候再操作！";
       }
       $("#Window_Msg_Info").css("display","none");
       $("#Window_Msg").css("display","block");
       $("#Window_Msg").html("<img src='"+Config_SiteDefault+"/images/msg/error.gif' alt=''/> "+errinfo);
       //setTimeout("HuaSys.PopWindow.hide()",1500);
       $("#Window_Msg_Container").fadeOut(3000);
       setTimeout("HuaSys.PopWindow.hide()",3050);
        
    },
    posting:function(msg)
    {
       if(typeof msg=='undefined')
       {
           msg="Loading...";
       }
       $("#Window_Msg_Info").css("display","none");
       $("#Window_Msg").css("display","block");
      // $("#Window_Msg").html("<img src=Config_SiteDefault+'/images/msg/LoadingLit.gif' alt=''/> "+msg);
    },
    loading:function(msg)
    {
       if(typeof msg=='undefined')
       {
           msg="Loading...";
       }
       $("#Window_Msg_Info").css("display","none");
       $("#Window_Msg").css("display","block");
       $("#Window_Msg").html("<img src='"+ Config_SiteDefault+"/images/msg/LoadingLit.gif' alt=''/> "+msg);
    },
    success:function(msg,callback)
    {
       if(typeof msg=='undefined')
       {
           msg="successfully";
       }
       $("#Window_Msg_Info").css("display","none");
       $("#Window_Msg").css("display","block");
       $("#Window_Msg").html("<img src='"+ Config_SiteDefault+"/images/msg/LoadingLit.gif' alt=''/> "+msg);
       //setTimeout("HuaSys.PopWindow.hide();"+callback,1500);
        $("#Window_Msg_Container").fadeOut(3000);
       setTimeout("HuaSys.PopWindow.hide();"+callback,3050);
    },
    successref:function(msg)
    {
       if(typeof msg=='undefined')
       {
           msg="successfully";
       }
       $("#Window_Msg_Info").css("display","none");
       $("#Window_Msg").css("display","block");
       $("#Window_Msg").html("<img src='"+ Config_SiteDefault+"/images/msg/LoadingLit.gif' alt=''/> "+msg);
       setTimeout("location.replace(location.href.replace(new RegExp('#\w+','ig'),''));",1500);
    }
    
};
//错误信息
HuaSys.ErrInfo={
//    notlogin:"您还没有登陆,请登陆后再操作",
//    busy:"服务器忙，请稍候再操作！",
//    extpost:"禁止外部提交",
//    parameter:"参数错误",
//    collection:"收藏成功",
//    collectionrepeat:"您已经收藏了该信息",
//    collectionself:"您不需要收藏自己发表的信息"

    notlogin:"您还没有登陆,请登陆后再操作",
    busy:"服务器忙，请稍候再操作",
    extpost:"禁止外部提交",
    parameter:"参数错误",
    collection:"收藏成功",
    collectionrepeat:"您已经收藏了该信息",
    collectionself:"您不需要收藏自己发表的信息",
    outsuccess:"退出成功",
    LoginedSuccess:"登陆成功",
    Logonfailure:"用户名密码错误"
};
//消息处理
HuaSys.DisposeInfo=function(_callback)
{
   if(typeof _callback!="undefined")
   {
       switch(_callback.SignInfo)
       {
          case "NotLogin":
              HuaSys.PopWindow.error(HuaSys.ErrInfo.notlogin);
              break;
        
          case "CollectionSuccess":
              HuaSys.PopWindow.success(HuaSys.ErrInfo.collection);
              break;
          case "CollectionRepeat":
              HuaSys.PopWindow.error(HuaSys.ErrInfo.collectionrepeat);
              break;
          case "CollectionSelf":
              HuaSys.PopWindow.error(HuaSys.ErrInfo.collectionself);
              break;
          case "CatchError":
              HuaSys.PopWindow.error(HuaSys.ErrInfo.busy);
              break;
          case "Par":
              HuaSys.PopWindow.error(HuaSys.ErrInfo.parameter);
              break;
           case "OutSuccess":
              HuaSys.PopWindow.success(HuaSys.ErrInfo.outsuccess);
              break; 
          case "LoginedSuccess":  
              HuaSys.Index.SetUserDate(_CallBack);
              HuaSys.Index.setloginpanl();
              //window.location.reload();
              break; 
          case "LoginedSuccessNew":  
              HuaSys.Index.SetUserDate(_CallBack);
              //HuaSys.Index.setloginpanl();
              window.location.reload();
              break;
          case "Logonfailure":
              alert(HuaSys.ErrInfo.Logonfailure);
              break;  
              
       }
   }
   else
   {
       HuaSys.PopWindow.error(HuaSys.ErrInfo.catcherror);
   }
};


//收藏
HuaSys.Collection=
{
    add:function(channel,infoid,authorid,title,url)
    {
        HuaSys.PopWindow.show('','收藏');
        HuaSys.PopWindow.posting("收藏提交中，请稍侯...");
        HuaSys.Ajax.getscript(Config_Ajax+"Collection.aspx","infoid="+infoid+"&channel="+channel+"&authorid="+authorid+"&title="+title+"&url="+url,false);
    }
    
};
//收藏
HuaSys.CollectionEn=
{
    add:function(channel,infoid,authorid,title,url)
    {
        HuaSys.PopWindow.show('','Favorites');
        HuaSys.PopWindow.posting("Adding to my collection,wait a moment please...");
        HuaSys.Ajax.getscript(Config_Ajax+"Collection.aspx","infoid="+infoid+"&channel="+channel+"&authorid="+authorid+"&title="+title+"&url="+url,false);
    }
    
};

//收藏
HuaSys.Map=
{
    add:function()
    {
        HuaSys.PopWindow.show(HuaTemplate.Map.Flush(),'地图选择',600,false);     
    }
    
};
//上传文件类型
HuaSys.UploadFile=
{
     activity:function(id)
     {
         HuaSys.UploadFile.catchvalue[0]=id;
         HuaSys.PopWindow.show(HuaTemplate.UploadFile.Activity(),"上传图片");
     },
     catchvalue:[0]
};


HuaSys.Delete=
{
    init:function(channel,mainId,replyId)
    {
       HuaSys.PopWindow.show("","删除内容");
       HuaSys.PopWindow.posting("删除中，请稍候...");
       HuaSys.Ajax.getscript(Config_Ajax+"DeleteData.aspx","channel="+channel+"&mid=" + mainId + "&id="+replyId,false);
    }
};

HuaSys.FrpEnCode=
{
    Hex:function(n)
    {   
     c = n;
     execScript("c = Hex(c)", "vbscript");
     return c;
    },
    //返回文字的AscaII编码, 调用的是vbscript的Asc函数
    Asc:function(s)
    {
     c = s;
     execScript("c = Asc(c)", "vbscript");
     return c;
    },

    //获取文字的gb2312编码
    gb2312Encode:function(str)
    {
     var string = "";
     c = s = "";
     var high = "";
     var low = "";
     for(var i = 0; i < str.length; i++)
     {
      c = HuaSys.FrpEnCode.Asc(str.charAt(i));
      if(Math.abs(c) < 0xFF)
       string += str.charAt(i);
      else
      {
       if(c < 0) c += 0x10000;
       high = ((c & 0xFF00) >> 8) & 0x00FF;
       low = c & 0xFF;
       string += "%" + HuaSys.FrpEnCode.Hex(high) + "%" + HuaSys.FrpEnCode.Hex(low);
      }
     }
     return string;
    },
    
    //将收到的gb2312编码进行解码
    gb2312Decode:function(data)
    {
     string = "";
     str = "";
     d = data;
     n = "";
     c = "";
     execScript("l = LenB(d)", "vbscript");
     execScript("d = MidB(d, 1)", "vbscript");
     for( i = 1; i <= l; i++)
     {
      execScript("c = AscB(MidB(d, i, 1))", "vbscript");
      if( c < 0x80)
      {
       execScript("str = Chr(c)", "vbscript");
       string += str;
      }
      else
      {
       execScript("n = AscB(MidB(d, i + 1, 1))", "vbscript");
       execScript("str = Chr(CLng(c) * &H100 + CInt(n))", "vbscript");
       string += str;
       i = i + 1;
      }
     }
     return string;
    }
};

HuaSys.Index=
{
    AddFavorites:function (sURL, sTitle) 
    { 
        try 
        { 
            window.external.AddFavorite(sURL, sTitle); 
            
        } 
        catch (e) 
        { 
            try 
            { 
                window.sidebar.addPanel(sTitle, sURL, ""); 
            } 
            catch (e) 
            { 
                alert("加入收藏失败，请使用Ctrl+D进行添加"); 
            } 
        } 
    },
    
    SetHome:function (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("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [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); 
                     } 
            } 
    },
    HeadLoginKeyDown:function (e)
    {
         e=e||event;
        if(e.keyCode == 13)
       {
         //执行登录操作
         HuaSys.Index.UserLogin();
         return false;
        }else{
        return true;
        }
    },
    UserLogin:function ()
    {
        if($("#username").val().trim()=="用户名"||$("#password").val().trim()=="***")
        {
            alert("用户名密码不能为空");
            return false;
        }
        if($("#username").val().trim()==""||$("#password").val().trim()=="")
        {
            alert("用户名密码不能为空");
            return false;
        }
        else
        {
            u=$("#username").val();
            p=$("#password").val();
           HuaSys.Ajax.getscript(Config_Ajax+"UserLoginin.aspx","U="+u+"&P="+p,false);
        }      
    },
    UserLoginOut:function ()
    {
      
            $.getScript(Config_Ajax+"UserLoginOut.aspx",function()
            {
                
                if(typeof _CallBack!="undefined")
                {
                    
                   HuaSys.Index.SetUserDate(_CallBack);
                    
                    if(_CallBack.SignInfo=="OutSuccess")
                    {
                        window.location.reload();
                    }
                    return;
                }
                
            });
       
    },
    SetUserDate:function(_CallBack)
    {
        UserData.id=_CallBack.id;
        UserData.username=_CallBack.username;
        UserData.cid=_CallBack.cid;
       // UserData.ctype=_CallBack.ctype;
        
    },
    setloginpanl:function()
    {
        if(parseInt(UserData.id)==0)
         {
              $("#LoginOut").hide();
              $("#LoginIn").show();
         }
         else
         {
            $("#LoginIn").hide();
            $("#LoginOut").show();
            $("#usernamespan").html(UserData.username);
           
         }
         
    },
    Init:function ()
    {
         HuaSys.Ajax.getscript(Config_Ajax+"UserLoginin.aspx","",false);
    }
};

HuaSys.Pages=
{
    PageInit:function()
    {
       for(i=$(".cutpage").length;i>0;i--)
       {
           var spanpage="<a class=\"page_n\" style=\"cursor:pointer;\" onclick='HuaSys.Pages.PageChange("+i+")'>"+i+"</a>&nbsp;";
           $("#pages").prepend(spanpage);
       }
       HuaSys.Pages.PageChange(1);
       
    },
    PageChange:function(i)
    {
       $(".cutpage").hide();
       $(".cutpage").eq(i-1).show(); 
        $("#pages>a").attr("class","page_n")
       $("#pages>a").eq(i-1).attr("class","page_a")
    } 
};
//cet
HuaSys.Cet=
{
    add:function(imgsrc)
    {
        
         HuaSys.PopWindow.show(SpaceCreateGroup(imgsrc),"资质证书",620,false );
      
    }
    
};
HuaSys.Code=
{
    GetCode:function()
    {
 
    $("#gifcode").load("/Admin/Ajax/GetCode.aspx");

    },
    GetCardCode:function()
    {
    $("#gifcode1").load("/Admin/Ajax/GetCode1.aspx");

    }
};

SpaceCreateGroup=function(pic)
{
      var buffer=new StringBuffer();
       buffer.append("<div id=\"Window_Msg_Info_Content\"  style=\"text-align:center;\">");
       buffer.append("<img src='"+pic+"'onload=\"setnum(this,'600','1000');\" />");
       buffer.append("</div>");
       return buffer.toString();
};
HuaSys.inquire=
{
        add:function(ProductID,FromID,CompanyName)
        {
            HuaSys.PopWindow.show(HuaTemplate.Inquire.InquireSpaceCreateGroup(ProductID,FromID),CompanyName,650,false);
        }

};

