﻿
/***************************************************************
 *   Create By lion                                            *
 *   2005-08-29 11:54                                          *
 *   Copyright (C) 1998-2005 www.csdn.net All rights reserved. *
 *   Web: http://www.lionsky.net    http://www.csdn.net        *
 *   Email: lion-a@sohu.com                                    *
 ***************************************************************/
/* ============================================
$ Method 1

Usage examples:
$('testId');
============================================ */
function $(id)
{
  if (typeof(id) != "string" || id == "") return null;
  if (document.getElementById) return document.getElementById(id);
  if (document.all) return document.all(id);
  try {return eval(id);} catch(e){ return null;}
}
/* ============================================
AttachEvent Method 1

Usage examples:
AttachEvent(window,"onload", InitializePage);
============================================ */
function AttachEvent(object, eventName, Function, cancelBubble)
{
  var cb = cancelBubble ? true : false;
  eventName = eventName.toLowerCase();
  if(document.attachEvent) object.attachEvent(eventName, Function);
  else object.addEventListener(eventName.substr(2), Function,  cb);
}
/* ============================================
AttachEvent Method 1

Usage examples:
alert(GetScrollTop(document));
============================================ */
function GetScrollTop(oDocument)
{
	if (oDocument.documentElement && oDocument["documentElement"].scrollTop)
	{
		return oDocument["documentElement"].scrollTop;
	}
	else
	{
		return oDocument.body.scrollTop;
	}
}
/* ============================================
AttachEvent Method 1

Usage examples:
alert(GetScrollLeft(document));
============================================ */
function GetScrollLeft(oDocument)
{
	if (oDocument.documentElement && oDocument["documentElement"].scrollLeft)
	{
		return oDocument["documentElement"].scrollLeft;
	}
	else
	{
		return oDocument.body.scrollLeft;
	}
}	


/* ============================================
Util_AddStyleSheet Method 1
向浏览器中插入样式表块。
Usage examples:
Util_AddStyleSheet("test.css", document);
============================================ */
if(!window.Util_AddStyleSheet)
{
    window.Util_AddStyleSheet = function(styleName, doc)
    {
	    var documents=doc != null?doc:document; 		
	    var link=documents.createElement("link"); 
	    link.setAttribute("href",styleName); 
	    link.setAttribute("type","text/css"); 
	    link.setAttribute("rel","stylesheet"); 
	    var head=documents.getElementsByTagName("head")[0]; 		
	    if (Util_DetectBrowser("safari"))
	    {
		    var ADDHEAD= function ()
		    {
			    head.appendChild(link); 
		    };
		    window.setTimeout(ADDHEAD,0310); 
	    }
	    else 
	    {
		    head.appendChild(link); 
	    }
    }
}
/* ============================================
Util_DetectBrowser Method 1
检测浏览器。
Usage examples:
alert(Util_DetectBrowser("safari"));
============================================ */
if(!window.Util_DetectBrowser)
{
    window.Util_DetectBrowser = function(arg)
    {
	    arg=arg.toLowerCase(); 
	    if ("ie" == arg)
	    {
		    arg="msie";
	    } 
	    else if ("mozilla" == arg||"firefox" == arg)
	    {
		    arg="compatible"; 
	    }
	    var navi=navigator.userAgent.toLowerCase(); 
	    var test=navi.indexOf(arg)+1; 
	    if (test)
	    {
		    return true; 
	    }
	    else 
	    {
		    return false;
	    } 
    }
}