function $(id) {
	var ret = document.getElementById(id);
	if(ret=='null'&&getBrowser().substring(0, 2)=='IE') ret = document.getElementByName(id);
	return ret;

/*function $() 
{ 
   var elements = new Array(); 
   for (var i = 0; i < arguments.length; i++) 
   { 
     var element = arguments[i]; 
     if (typeof element == 'string') 
       element = document.getElementById(element); 
     if (arguments.length == 1) 
       return element; 
     elements.push(element); 
   } 
   return elements; 
}*/
}

function $F(id) {
	if(typeof id=='string') id = $(id);
	switch(id.type){
		case 'checkbox':
			var r = id.checked;
			break;
		default:
			var r = id.value;
			break;
		}
	return r;
}

var Event = new Object();

Event.observe = function(obj, evt, func){
	if(typeof obj=='string') obj = $(obj);
	try{
		if(obj.addEventListener) {
			obj.addEventListener(evt, func, false);
		} else if(obj.attachEvent) {
			obj.attachEvent("on" + evt, func);
		}
	}catch (e) {}
}


var Element = new Object();

Element.setStyle = function(obj, p, v){
	if(typeof obj=='string') obj = $(obj);
	switch(p.Trim().toLowerCase()){
		case 'margin-top':
			obj.style.marginTop = (isNaN(v)? v: v+'px');
			break;
		case 'background-position-x':
			obj.style.backgroundPositionX = v;
			break;
		case 'background-position-y':
			getBrowser().substring(0, 2)=='IE'? obj.style.backgroundPositionY = v: obj.style.backgroundPosition = Element.getStyle(obj, 'background-position-x') + ' ' +v;
			break;
		case 'height':
			obj.style.height = (isNaN(v)? v: v+'px');
			break;
		}
	//obj.style.
	//alert(getBrowser());
//	obj.className = value;
	}

Element.getStyle = function(obj, p){
	if(typeof obj=='string') obj = $(obj);
	var r;
	switch(p.Trim().toLowerCase()){
		case 'background-position-x':
			r = (getBrowser().substring(0, 2)=='IE'? obj.style.backgroundPositionX: document.defaultView.getComputedStyle(obj, 0)['backgroundPosition'].split(' ')[0]);
			break;
		case 'background-position-y':
			r = (getBrowser().substring(0, 2)=='IE'? obj.style.backgroundPositionY: document.defaultView.getComputedStyle(obj, 0)['backgroundPosition'].split(' ')[1]);
			break;
		case 'height':
			r = obj.offsetHeight;
			break;
		}
	return r;
	}

Element.setClass = function(obj, value){
	if(typeof obj=='string') obj = $(obj);
	obj.className = value;
	}

Element.getClass = function(obj){
	if(typeof obj=='string') obj = $(obj);
	return obj.className;
	}

Element.removeClass = function(obj, value){
	if(typeof obj=='string') obj = $(obj);
	var s = obj.className.split(' ');
	for (var i=0; i<s.length; i++){
		if(s[i].toLowerCase()==value.toLowerCase()) s[i] = '';
		}
	obj.className = s.join(' ');
	}

Element.addClass = function(obj, value){
	if(typeof obj=='string') obj = $(obj);
	if (Element.findClass(obj, value)) return false;
	var s = obj.className.split(' ');
	s.push(value);
	obj.className = s.join(' ');
	}

//查找是否包含此CSS
Element.findClass = function(obj, value){
	if(typeof obj=='string') obj = $(obj);
	var s = obj.className.Trim().split(' ');
	var isf = false;
	for (var i=0; i<s.length; i++){
		if(s[i].toLowerCase()==value.toLowerCase()){
			isf = true;
			break;
			}
		}
	return isf;
	}

Element.show = function(obj){
	if(typeof obj=='string') obj = $(obj);
	obj.style.display = 'block';
	}

Element.hide = function(obj){
	if(typeof obj=='string') obj = $(obj);
	obj.style.display = 'none';
	}

Element.disable = function(obj){
	if(typeof obj=='string') obj = $(obj);
	obj.disabled = true;
	}

Element.enable = function(obj){
	if(typeof obj=='string') obj = $(obj);
	obj.disabled = false;
	}

String.prototype.Trim = function(){return this.replace(/(^s*)|(s*$)/g, "")}
String.prototype.LTrim = function(){return this.replace(/(^s*)/g, "")}
String.prototype.Rtrim = function(){return this.replace(/(s*$)/g, "")} 
String.prototype.isMail = function(){
	//检测邮件或MSN是否合法
	var re = /^[a-z0-9]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/i;
	return chkReg(re, this);
	}

String.prototype.isQQ = function(){
	//检测邮件或MSN是否合法
	var re = /^[1-9][0-9]{4,12}$/i;
	return chkReg(re, this);
	}

String.prototype.isSafeString = function(){   //检测帐号是否合法
	str = this.Trim();
	var re = /^[A-Za-z0-9_\u4e00-\u9fa5]*$/;
	return chkReg(re, str);
	}

function chkReg(reg, str){
	if(reg.test(str)){return true;}return false;
    }

function getBrowser(){
	var bro = navigator.userAgent.toLowerCase();
	if(/msie/.test(bro)) return 'IE' + bro.match(/msie ([\d.]*);/)[1]
	else if(/navigator/.test(bro)) return 'NS' + bro.match(/navigator\/([\d.]*)/)[1]
	else if(/chrome/.test(bro)) return 'CR' + bro.match(/chrome\/([\d]*)/)[1]
	else if(/safari/.test(bro)) return 'SF' + bro.match(/version\/([\d]*)/)[1]
	else if(/opera/.test(bro)) return 'OP' + bro.match(/version\/([\d]*)/)[1]
	else if(/firefox/.test(bro)) return 'FF' + bro.match(/firefox\/([\d]*)/)[1]
	}

function addfavorite(t, u){    
	if (document.all) window.external.addFavorite(u, t)
	else if (window.sidebar) window.sidebar.addPanel(t, u, "");    
	}    

function setHomepage(u){
	if (document.all){
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(u);
	    } 
	else if (window.sidebar){
		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', u);
		}
	}