/*
 * 网站基础类
 * CreatDate:08.09.05
 * Author:yangmy 
 */
var gov={
   htmldataHost:"http://tb.egdfc.com/HtmlData/GDFC/",
   HistoryData:"http://tb.egdfc.com/"
};
window.onerror=function(){return false};
if (typeof($) == 'undefined') {
  $ = function(elem) {
    if (arguments.length > 1) {
      for (var i = 0, elems = [], length = arguments.length; i < length; i++)
        elems.push($(arguments[i]));
      return elems;
    }
    if (typeof elem == 'string') {
      return document.getElementById(elem);
    } else {
      return elem;
    }
  };
}
var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

Object.extend = function(destination, source) {
  for (var property in source) {
    destination[property] = source[property];
  }
  return destination;
}

var StringBuilder = function(){
    this._buffer    = [];
}
StringBuilder.prototype.append = function(str){
    this._buffer[this._buffer.length] = String(str);
}
StringBuilder.prototype.toString = function(){
    return this._buffer.join('');
}
StringBuilder.prototype.add = StringBuilder.prototype.append;
StringBuilder.prototype.clear = function(){
    this._buffer = [];
}

gov.setCookie=function(str){
	var expires=new Date();
	expires.setTime(expires.getTime()+24*60*60*365*1000);
	document.cookie=str+" expires="+expires.toGMTString();
}

gov.readCookie=function(){
    var args=new Object();   
	var query=  document.cookie;
    var pairs=query.split("; ");  
    for(var i=0;i<pairs.length;i++)   
    {   
        var pos=pairs[i].split('=');  
        args[pos[0]]=unescape(pos[1]);  
    }
    return args;
}

var layerHide=function(obj){
    if(typeof(obj)=="object"){
	    obj.style.display="none";
	} 
	else if(typeof(obj)=="string"){
	    $(obj).style.display="none";
	}
}

var layerShow=function(obj){
     if(typeof(obj)=="object"){
	    obj.style.display="";
	} 
	else if(typeof(obj)=="string"){
	    $(obj).style.display="";
	}
}

gov.alert = function(msg, fnOk) {
     new parent.gov.config.alert(msg, fnOk).open();
};
gov.confirm = function(msg, fnOk, fnCancel ,btn1,btn2) {
     new parent.gov.config.confirm(msg, fnOk, fnCancel ,btn1,btn2).open();
};
gov.close = function(id){
    parent.gov.config.close(id);
};
gov.popClose = function(id){
    parent.gov.config.close(id);
};
gov.popOpen = function(src, title, className) {
    var pop;
    var __className;
    
    //default
    if(className != null && className != '')
        __className = className;
    else
        __className = "chipinpop";
    
    //special
//    if(title && title.indexOf('合买') != -1)
//        __className = "joinbuypop";
    
    pop=new parent.gov.config.chipinPop(src,title, __className);
    var obj=pop.open();
    if(obj){ 
        parent.gov.config.reIframe1(obj.id);
    } 
};


gov.config={
      close: function(id) {
            if(id!=null){
	  	        if($("pop_box"+id))  document.body.removeChild($("pop_box"+id));
                wincount--;
               	$("pop_bg").style.zIndex=820+wincount;  
               	if (!$("reinit_popiframe"+id)&typeof(window["reinit_popiframe"+id]) != "undefined") clearInterval(window["reinit_popiframe"+id]); 	
	
             }else{
                for(var i=0;i<=winid;i++){
	  	            if($("pop_box"+i))  document.body.removeChild($("pop_box"+i));
	  	            if (!$("reinit_popiframe"+i)&typeof(window["reinit_popiframe"+i]) != "undefined") clearInterval(window["reinit_popiframe"+i]); 	
                }
                wincount=0;
             } 
            if(wincount==0){ 
	  	   	    if($("pop_bg"))  layerHide("pop_bg"); 
	  	    }	
      }
};
gov.config.openLayer=function(){ winid=0; wincount=0;};
gov.config.openLayer.prototype={
      create: function(options) {
           winid++;
           wincount++; 
            if(!$("pop_bg")){
		        var win = document.createElement("DIV");
		        win.setAttribute("id", "pop_bg");
		        win.style.zIndex="820";
		        document.body.appendChild(win);
                var height=document.body.offsetHeight;
                win.style.height=height+"px";
		        win.innerHTML='<iframe src="" frameborder="0" style="position:absolute;  top:0px; left:0px; width:100%; height:'+height+'px; " ></iframe>';  
		    }
		    else{
		        $("pop_bg").style.zIndex=820+wincount*2-1; 
		        layerShow("pop_bg");
		    }
	        var box = document.createElement("DIV");
	        box.setAttribute("id", "pop_box"+winid);
	        box.style.zIndex=820+wincount*2;
	        document.body.appendChild(box);

		    $("pop_box"+winid).className=options.classname;
		    $("pop_box"+winid).innerHTML=options.info;
		    if($("chipinStep_box_btn2")) $("chipinStep_box_btn2").focus(); 
		   

		   if($("popiframe"+winid)){ 
            return $("popiframe"+winid);
           } 
      }
}
gov.config.alert = Class.create();
gov.config.alert.prototype = Object.extend(new gov.config.openLayer(),{
 	   initialize: function(text, fnOk) {
    	   this.classname = "alertpop";
    	   this.html='<h3>提示信息<a id="chipinStep_box_btn1" title="关闭" onclick="gov.close('+(winid+1)+');'+fnOk+';">关闭</a></h3>';
    	   this.html+='<div class="alertpop_info_e">'+text+'</div>' 
     	   this.html+='<div class="alertpop_info_e_bt"><input id="chipinStep_box_btn2" type="button" style="cursor:pointer" name="Submit" class="button3 firstButton" value="确 认" onclick="gov.close('+(winid+1)+');'+fnOk+'"></div>'; 
	   },
	   open:function(){
	       return this.create({
	            classname:this.classname,
	            info:this.html 
	       })
	   }
});

gov.config.confirm=Class.create();
gov.config.confirm.prototype= Object.extend(new gov.config.alert(),{
 	   initialize: function(text, fnOk, fnCancel ,btn1,btn2) {
    	   this.classname = "alertpop";
    	   var name1=btn1?btn1:"确 认";
    	   var name2=btn2?btn2:"取 消";
    	   this.html='<h3>提示信息<a  title="关闭" onclick="gov.close('+(winid+1)+');'+fnCancel+';return false">关闭</a></h3>';
    	   this.html+='<div class="alertpop_info_q">'+text+'</div>' 
    	   this.html+='<div class="alertpop_info_q_bt"><input type="button" id="chipinStep_box_btn2" name="Submit" class="button3 firstButton" style="cursor:pointer" value="'+name1+'" onclick="gov.close('+(winid+1)+');'+fnOk+'"><input type="button" name="clear" class="button3" style="cursor:pointer" value="'+name2+'" onclick="gov.close('+(winid+1)+');'+fnCancel+'"></div>';
	   }
});

gov.config.chipinPop=Class.create();
gov.config.chipinPop.prototype = Object.extend(new gov.config.alert(),{
 	   initialize: function(src,title, className) {
            this.ifrmid=winid+1;
            this.classname = className || "chipinpop";
           this.html=""; 
           if(title){
                      this.title=title;
                      this.html = '<h3><span id="title_chipinpop">'+this.title+'</span><a href="#" title="关闭" onclick="gov.close('+(winid+1)+');;return false">关闭</a></h3>'; 
           } 
            this.html += '<div ><iframe width=562  frameborder=0  marginwidth=0 marginheight=0 scrolling=no name=\"popiframe\" id=\"popiframe'+this.ifrmid+'\" src='+src+' allowTransparency></iframe></div>';   
	   }
});
gov.config.reIframe=function(dom){
    window["reinit_"+dom] =window.setInterval("gov.config.reinitIframe('"+dom+"')", 200);
}
gov.config.reinitIframe=function(dom){
	         var  iframe=$(dom);
             try{
                    var height =  iframe.contentWindow.document.documentElement.scrollHeight;
					if(!document.all){
						height= iframe.contentWindow.document.documentElement.offsetHeight;
					}
                    iframe.height=height;
					iframe.style.height=height+"px"
            }catch (ex){
          }
}

gov.getBrowser=function(){
	var browser=navigator.appName 
	var b_version=navigator.appVersion 
	var version=b_version.split(";"); 
	var trim_Version=version[1].replace(/[ ]/g,""); 
	if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0") 
	{ 
		return 7;
	} 
	else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") 
	{ 
		return 6;
	}else{
		return 8;	
	}

}

gov.config.reIframe1=function(dom){
    window["reinit_"+dom] =window.setInterval("gov.config.reinitIframe1('"+dom+"')", 200);
}
gov.config.reinitIframe1=function(dom){
	         var  iframe=$(dom);
             try{
                    var height =  iframe.contentWindow.document.documentElement.scrollHeight;
 
                    var width =  iframe.contentWindow.document.documentElement.scrollWidth;

                    iframe.height=height;
                    iframe.width=width;
                    if(height>=460){
                        iframe.parentNode.style.cssText="overflow-y:scroll;height:460px";
                        if(iframe.parentNode.parentNode.className=="joinbuypop"){
                            iframe.parentNode.parentNode.style.width="780px";

                        }else{
                            iframe.parentNode.parentNode.style.width=width+20+"px";
                            iframe.parentNode.parentNode.style.marginTop="10px"; 
							iframe.parentNode.parentNode.style.left=(document.documentElement.clientWidth-(width+20))/2+"px";
							iframe.parentNode.parentNode.style.top=document.documentElement.scrollTop+(document.documentElement.clientHeight-490)/2+"px";
                        }
                    }else{
                        iframe.parentNode.style.cssText="text-align:center";
                        if(iframe.parentNode.parentNode.className!="joinbuypop"){
							iframe.parentNode.parentNode.style.top=document.documentElement.scrollTop+(document.documentElement.clientHeight-height-20)/2+"px";
                          	iframe.parentNode.parentNode.style.left=(document.documentElement.clientWidth-(width+20))/2+"px";
                            iframe.parentNode.parentNode.style.width=width+"px";
						}
                    }

                    
            }catch (ex){
          }
}

gov.serviceBox=function(){
	this.Create = function()
	{
		var w =159;
		var h =60;
		var objbody= document.compatMode=="CSS1Compat"?document.documentElement:document.body;
		var l=objbody.scrollLeft+objbody.clientWidth-w;
		var t=objbody.scrollTop+(objbody.clientHeight-7);
		var mywin = document.createElement("DIV");
		mywin.setAttribute("id", "kf");
		mywin.style.cssText = "position:absolute;width:"+ w +"px;height:"+ h +"px;left:"+l+"px;top:"+t+"px";
		document.body.appendChild(mywin);
		$("kf").innerHTML='<iframe src="" frameborder="0" style="position:absolute;top:0px; left:0px; width:100%; height:100%; display:none"></iframe><div style="position:absolute;top:0px; left:0px;"><div style="position:absolute;top:0px; right:0px;width:25px;height:25px;"><img src="/CommLott/V1/images/close1.gif" style="cursor:pointer; width:25px; height:20px" align=right width=0 height=0 alt="关闭" onclick="MyWin.Close(\'kf\')" /></div><a href="http://service.egdfc.com/dialog/reg.asp" target="_blank"><img src="/CommLott/V1/images/kf.gif" border=0 style="filter: alpha(opacity=90)" /></a></div>';
		this.Move("kf",t);
	}
	this.Close = function(Id, Opacity)
    {
	    if (typeof(window["et"+ Id]) != "undefined") clearTimeout(window["et"+ Id]);
	    var o = $(Id);
	    document.body.removeChild(o);
    }
	
    this.Move = function(Id,t)
    {
		if (typeof(window["ct"+ Id]) != "undefined") clearTimeout(window["ct"+ Id]);
		var objbody= document.compatMode=="CSS1Compat"?document.documentElement:document.body;
        t0=objbody.scrollTop+(objbody.clientHeight-60);
	    var o = $(Id);
	    if (!o) {
			return;
			}
		tl=t-t0;
		if(t!=t0)
		{
		  if (Math.abs(tl) < 52)
		  {
			  if (Math.abs(tl) < 16)
		      {
			    tl = tl< 0 ? 1 : -1;
		      }
			  else
			  {
			    tl = tl< 0 ? 2 : -2;
			  }
		  }
		  else{
			  		  tl=(tl>0?-8:8);
			  }
		  o.style.top=t+tl+"px";
		}
		o.style.left=objbody.scrollLeft+objbody.clientWidth-159+"px";
	    window["ct"+ Id] = window.setTimeout("MyWin.Move('"+ Id +"',"+ (t+tl) +")", 1);
    }
}
gov.addJs=function(jsid,path){  
     var js;
     if(js=$(jsid)){
         js.parentNode.removeChild(js);
     } 
     var script= document.createElement("SCRIPT"); 
     script.defer= true;   
     script.type="text/javascript";
     script.src=path+"?j="+Math.random();
     script.id=jsid;   
     document.getElementsByTagName("HEAD")[0].appendChild(script);   
}

gov.ajax={};
gov.ajax.updater=function(id,url)
{
	Ajax.showLoading(id);
	new Ajax.Updater(
		id,
		url,
		{
			method: 'get',
			onComplete:function(){Ajax.hideLoading(id);
			}
		})

}
// 加载本站公告
gov.ajax.bindSiteinfo=function(url){
    var ivars = {
        url : url,
        errorcode :0,
        errorMessage:'',
        objArray:[],            
        getVars:function()
        {
            Ajax.showLoading("siteInfo");  
            ivars.objArray = [];
            new Ajax.Request(ivars.url, 
            {
                method: 'get',
                evalJS:false,
                encoding:'gb2312',
                onSuccess:function(transport){
                     eval(transport.responseText);
                     ivars.objArray = publicNotice;
                     ivars.generate();
                }
            });
        },
        generate:function(){
            var ret=new StringBuilder();
            ret.add('		  	<ul>');
            for(var i = 0; i < ivars.objArray.length;i++)
            {  
                ret.add(ivars.objArray[i].ToHtmlDd());
             }
            ret.add('		</ul>');       
            $("siteInfo").innerHTML = ret.toString();
                       Ajax.hideLoading("siteInfo");  
 
        }
    };
     ivars.getVars(); 
}
// 加载近十期开奖数据
gov.ajax.bindTenaward=function(url,num){
    var vars = {
        url : url,
        num:num||0, 
        errorcode :0,
        errorMessage:'',
        objArray:[],            
        getVars:function()
        {
            //alert(this.url);
            Ajax.showLoading("column_info_00"); 
            vars.objArray = [];
            new Ajax.Request(vars.url, 
            {
                method: 'get',
                evalJS:false,
                encoding:'gb2312',
                onSuccess:function(transport){
                    eval(transport.responseText);
                    vars.generate(num);
                }
            });
        },
        generate:function(num){
            var ret=new StringBuilder();
            if(num!=4)
            {
                ret.add(' <table width="100%" border="0" cellspacing="0">') 
                for(var i = 0 ; i < vars.objArray.length; i ++)
                {
                    ret.add(vars.objArray[i].ToHtmlTr(num));
                }
                ret.add('</table>');
            }
            else
            {
                ret.add('<div  class="awardHot" >');
                ret.add('<table width="195" cellspacing="0" border="0">');
                ret.add('<tbody>');
                for(var i = 0 ; i < vars.objArray.length; i ++)
                {
                    ret.add(vars.objArray[i].ToHtmlTr(num,i));
                }
                ret.add('</tbody></table></div>');
            }
           $('column_info_00_0').innerHTML = ret.toString();
		   $("column_info_00_0").style.display=""; 
           Ajax.hideLoading("column_info_00");  
        }
    };
    vars.getVars();
}
// 加载数据图表链接
gov.ajax.bindDatachart=function(url,num){
    var tbvars = {
        url : url,
        num:num||0, 
        errorcode :0,
        errorMessage:'',
        objArray:[],            
        getVars:function()
        {
            Ajax.showLoading("column_info_01");
            tbvars.objArray = [];
            new Ajax.Request(tbvars.url, 
            {
                method: 'get',
                evalJS:false,
                encoding:'gb2312',
                onSuccess:function(transport){
                    eval(transport.responseText);
                    tbvars.generate();
                }
            });
        },
        generate:function(){
            var ret=new StringBuilder();
            ret.add(' <ul>') 
            for(var i = 0 ; i < tbvars.objArray.length; i ++)
            {
                ret.add(tbvars.objArray[i].ToHtmlDd());
            }
           ret.add('</ul>');
          // $('column_info_01_'+this.num).innerHTML = '';
           $('column_info_01_'+this.num).innerHTML = ret.toString();
           for(var j=0;j<4;j++){
		        if($("column_info_01_"+j)) $("column_info_01_"+j).style.display="none";
		   }  
		   $("column_info_01_"+this.num).style.display="";  
           Ajax.hideLoading("column_info_01");   
        }
    };
    tbvars.getVars();
}

var Ajax = {
  getTransport: function() {
    var xmlhttp;
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
  },
    showLoading:function(element,type)
    {
            //alert(element)

        if(type){
            if(!$("pop_bg")){
		        var win = document.createElement("DIV");
		        win.setAttribute("id", "pop_bg");
		        win.style.zIndex="820";
		        document.body.appendChild(win);
                var height=document.body.offsetHeight;
                win.style.height=height+"px";
		        win.innerHTML='<iframe src="" frameborder="0" style="position:absolute;  top:0px; left:0px; width:100%; height:'+height+'px; " ></iframe>';
		    }else{
    	        layerShow("pop_bg");
		    }
		    var box=$(element+"_loading");
	        if(!box)
	        {
	    	    box = document.createElement("DIV");
	            box.id=element+"_loading";
                box.style.zIndex=822;
                box.className="alertpop";
                box.innerHTML="<div style='margin-left:80px' class='loading'>数据加载中...</div>" 
                document.body.appendChild(box);
            }
            layerShow(box);
        }else{
	        var element=$(element);
	        if(!element)
	        {
		        return;
	        }
	        var divLoading=$(element.id+"_loading");
	        if(!divLoading)
	        {
		        divLoading=document.createElement("div");
		        divLoading.id=element.id+"_loading";
		        divLoading.className="loading";
		        divLoading.style.position = "absolute";
		        divLoading.style.top ="10px";
		        divLoading.style.left = (element.offsetWidth - 120)/2+"px";
		        divLoading.innerHTML="数据加载中...";
                element.appendChild(divLoading);
	        }
	        layerShow(divLoading);
	   } 
    },
   hideLoading:function(element,type)
    {
        if(type){
            layerHide("pop_bg")
           	var divLoading=$(element+"_loading");
	        layerHide(divLoading);
        }else{
	        var divLoading=$(element+"_loading");
	        if(!divLoading)
	        {
		        return;
	        }
	        layerHide(divLoading);
	    }
    } 
}
Ajax.Base = function() {};
Ajax.Base.prototype = {
  setOptions: function(options) {
    this.options = {
      method:       'post',
      asynchronous: true,
      contentType:  'application/x-www-form-urlencoded',
      encoding:     'UTF-8',
      parameters:   ''
    }
    Object.extend(this.options, options || {});
  }
}
Ajax.Request = Class.create();
Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
 	initialize: function(url, options) {
    	this.transport = Ajax.getTransport();
    	this.setOptions(options);
   		this.request(url);
	},
	request:function(url){
		if(this.transport){
			var loader=this;
			this.transport.onreadystatechange=function(){
				loader.onReadyState.call(loader);
			}
			this.transport.open(this.options.method,url,this.options.asynchronous);
			this.transport.setRequestHeader('Content-type',this.options.contentType);
			this.transport.send(this.options.parameters);
		}
	},
	onReadyState:function(){
		if(this.transport.readyState==4){
				if (this.transport.status==200){
				    try{
					this.options.onSuccess(this.transport);}
					catch(e){}
				}
		}
	}
})
Ajax.Updater = Class.create();
Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
	 initialize: function(element,url, options) {
    	this.element = element;
    	this.transport = Ajax.getTransport();
    	this.setOptions(options);
   		this.request(url);
	},
	onReadyState:function(){
		if(this.transport.readyState==4){
				if (this.transport.status==200){
					$(this.element).innerHTML=this.transport.responseText;
					
					this.options.onComplete();
				}
		}
	}
})
Number.prototype.ToString = function (format)
{
    if(format == null)
    {
        return "" + this;
    }
    if(format == "00")
    {
        if(this >= 0 && this <= 9)
        {
            return "0" + this;
        }
    }
    return "" + this;
}
  var net=new Object();
net.tab={};
net.tab.objSelect=function(clickobj,obj,elem){
    for(var i=0;i<obj.length;i++)
    {
        obj[i].className="";
	    $(elem+"_"+i).style.display="none";
    }
    $(elem+"_"+clickobj.getAttribute("name")).style.display="";
    clickobj.className="selected"; 
}

net.tab.menuEvent=function(elem,num){
    var objs=$(elem).getElementsByTagName("li");
       objs[num].className="selected";

       var conobj=$(elem+"_"+num);
       conobj.style.display="";

        net.tab.addEvent(objs,function (){
            net.tab.objSelect(this,objs,elem);
        });
}

net.tab.addEvent=function(elems,fun){
    for (var i=0;i<elems.length;i++)
    {
        elems[i].setAttribute("name",i);
        elems[i].onclick=fun;
    }
}
