function $(d)
{
	return document.getElementById(d);
}

function gs(d)
{
	var t=$(d);
	if (t)
	{
		return t.style;
	}
	else
	{
		return null;
	}
}

function gs2(d,a)
{
	if (d.currentStyle){ 
	var curVal=d.currentStyle[a]
	}else{ 
	  var curVal=document.defaultView.getComputedStyle(d, null)[a]
	} 
	return curVal;
}

function CreateAjaxRequest()
{
	var ajax = null;

	if (window.XMLHttpRequest){
		ajax = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject)
	{
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e1)
			{
				try {
					ajax = new ActiveXObject("Microsoft.XMLHTTP");					
					} catch (e2){
					}
			}	
	}
	return ajax;
}

function AddQueryString(org,k,v)
{
    var ret;
    
    if( org==null )
        ret = k + "=" + encodeURIComponent(v);
    else
        ret = org + "&" + k + "=" + encodeURIComponent(v);
        
    return ret;
}

function getEvent() //同时兼容ie和ff的写法
{  
     if(document.all)    return window.event;    
     func=getEvent.caller;        
     while(func!=null){  
         var arg0=func.arguments[0];
         if(arg0)
         {
           if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
           {  
           return arg0;
           }
         }
         func=func.caller;
     }
     return null;
}

var browser;

function GetBrowser1()
{
	var browser = '';
	var agentInfo = navigator.userAgent.toLowerCase();
	if (agentInfo.indexOf("msie") > -1) {
		var re = new RegExp("msie\\s?([\\d\\.]+)","ig");
		var arr = re.exec(agentInfo);
		if (parseInt(RegExp.$1) >= 5.5) {
			browser = 'IE';
		}
	} else if (agentInfo.indexOf("firefox") > -1) {
		browser = 'FF';
	} else if (agentInfo.indexOf("netscape") > -1) {
		var temp1 = agentInfo.split(' ');
		var temp2 = temp1[temp1.length-1].split('/');
		if (parseInt(temp2[1]) >= 7) {
			browser = 'NS';
		}
	} else if (agentInfo.indexOf("gecko") > -1) {
		browser = 'ML';
	} else if (agentInfo.indexOf("opera") > -1) {
		var temp1 = agentInfo.split(' ');
		var temp2 = temp1[0].split('/');
		if (parseInt(temp2[1]) >= 9) {
			browser = 'OPERA';
		}
	}
	return browser;
}

function GetBrowser()
{
    if(navigator.appName == "Microsoft Internet Explorer")
        browser = "IE";
    else
        browser = "NotIE";
    
    return browser;
}

function MagicConvertAttribute(str)
{
	str = MagicClearAttributeScriptTag(str);
	return str;
}

function MagicClearAttributeScriptTag(str)
{
	var re = new RegExp("(\\son[a-z]+=)[\"']?[^>]*?[^\\\\\>][\"']?([\\s>])","ig");
	str = str.replace(re, function ($0,$1,$2) {
						return($1.toLowerCase() + "\"\"" + $2);
					}
				);
	return str;
}

function HtmlToXhtml(str) 
{
	str = str.replace(/<br.*?>/gi, "<br />");
	str = str.replace(/(<hr\s+[^>]*[^\/])(>)/gi, "$1 />");
	str = str.replace(/(<img\s+[^>]*[^\/])(>)/gi, "$1 />");
	str = str.replace(/(<\w+)(.*?>)/gi, function ($0,$1,$2) {
						return($1.toLowerCase() + MagicConvertAttribute($2));
					}
				);
	str = str.replace(/(<\/\w+>)/gi, function ($0,$1) {
						return($1.toLowerCase());
					}
				);
	return str;
}

function ClearScriptTag(str)
{
	str = str.replace(/<(script.*?)>/gi, "[$1]");
	str = str.replace(/<\/script>/gi, "[/script]");
	str = str.replace(/<(div.*?)>/gi, "");
	str = str.replace(/<\/div>/gi, "");
	str = str.replace(".write(","write");
	return str;
}

function ChangeHtmlentities(str)
{
    str=ClearScriptTag(str);

	str = str.replace(/&/g,'&amp;');
	str = str.replace(/</g,'&lt;');
	str = str.replace(/>/g,'&gt;');
	str = str.replace(/"/g,'&quot;');

	return str;
}

function htmlEncode(str)
{   
    str = str.replace(/&/g,'&amp;');
	str = str.replace(/</g,'&lt;');
	str = str.replace(/>/g,'&gt;');
	str = str.replace(/ /g,"&nbsp;");
	str = str.replace(/\r\n/g,"<br\/>")
	return str;
}


function GetBelowX(tt)  
{  
   var  ttop   =  tt.offsetTop;       //TT控件的定位点高  
   var  thei   =  tt.clientHeight;    //TT控件本身的高  
   var  tleft  =  tt.offsetLeft;      //TT控件的定位点宽  
   var  ttyp   =  tt.type;            //TT控件的类型  
   while  (tt  =  tt.offsetParent){ttop+=tt.offsetTop;  tleft+=tt.offsetLeft;}  

   return tleft;
}

function GetBelowY(tt)
{
   var  ttop   =  tt.offsetTop; 
   var  thei   =  tt.clientHeight;
   var  tleft  =  tt.offsetLeft;
   var  ttyp   =  tt.type;
   while  (tt  =  tt.offsetParent){ttop+=tt.offsetTop;  tleft+=tt.offsetLeft;}  

   return ttop+thei;
}

function GetScrollY()
{
    var scrollPos;
    
if (typeof window.pageYOffset != 'undefined') { 
   scrollPos = window.pageYOffset; 
} 
else if (typeof document.compatMode != 'undefined' && 
     document.compatMode != 'BackCompat') { 
   scrollPos = document.documentElement.scrollTop; 
} 
else if (typeof document.body != 'undefined') { 
   scrollPos = document.body.scrollTop; 
} 
    return scrollPos;
}

function GetScrollX()
{
    if (__nonMSDOMBrowser) 
    {
        return window.pageXOffset;
    }
    else 
    {
        if (document.documentElement && document.documentElement.scrollLeft) 
        {
            return document.documentElement.scrollLeft;
        }
        else if (document.body) 
        {
            return document.body.scrollLeft;
        }
    }
    return 0;
}

var OldCenterY = null;

// 得到屏幕中心的点在客户区域的Y值
function GetCenterY()
{
    var evt = getEvent();
    var y;
    
    if( evt == null )
    {
        y = OldCenterY;
    }
    else
    {
        var HalfScreen = window.screen.height / 2;
        
        var interval = evt.screenY - HalfScreen;
        
        y = GetScrollY() + evt.clientY - interval;
        
       
        
        OldCenterY = y;
    }
    
    return y;
}

function AdjustHeight(o)
{
    var h = window.screen.height;
    
    if( h > 800 )
    {
        var h1 = h - 800;
        
        var my = 370 + h1;
        
        o.height = my;
    }
    else
        o.height = 400;
}


function PopupDialog(url,width,height)
{
  var x = parseInt(screen.width / 2.0) - (width / 2.0); 
  var y = parseInt(screen.height / 2.0) - (height / 2.0);  
  var isMSIE= (navigator.appName == "Microsoft Internet Explorer");   //判断浏览器  
   if (isMSIE) 
   {          
     //retval = window.showModalDialog(url, window, "dialogWidth:"+width+"px; dialogHeight:"+height+"px; dialogLeft:"+x+"px; dialogTop:"+y+"px; status:no; help:no; directories:yes;scrollbars:no;Resizable=no;"); 
   
     retval = window.showModalDialog(url, window, "dialogWidth:"+width+"px; dialogHeight:"+height+"px; dialogLeft:"+x+"px; dialogTop:"+y+"px; status:no; help:no; directories:yes;scroll:no;Resizable=no;"); 
   } 
   else 
   {  
   var win = window.open(url, "mcePopup", "top=" + y + ",left=" + x + ",scrollbars=no,dialog=yes,modal=yes,width=" + width + ",height=" + height + ",resizable=no" );  
   eval('try { win.resizeTo(width, height); } catch(e) { }');  
   win.focus();             
   }  
}

function AddFavorite()
{
    if (document.all)
    {
       window.external.addFavorite('http://www.totofo.cn','投投富—懂得投资才能收获财富');
    }
    else if (window.sidebar)
    {
       window.sidebar.addPanel('投投富—懂得投资才能收获财富', 'http://www.totofo.cn', "");
    }
}

function addBookmark(title,url) {
    if (window.sidebar) { 
    window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
    window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
    return true;
    }
}

function setHomepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage('http://www.totofo.cn');
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
         { 
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
         } 
         catch (e) 
         { 
             MagicMsgBoxShow("该操作被浏览器拒绝.如果想启用该功能.<br />请在地址栏内输入 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','http://www.totofo.cn');
 }
}










 
