/*-------------全局变量-----------------------*/
//便于浏览器兼容
//暂时只有ie的用法
var ns = (document.layers)?true:false
var ie = (document.all)? true:false

String.prototype.trim= function(){  
    // 用正则表达式将前后空格  
    // 用空字符串替代。  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}
String.prototype.stripHTML = function (){
	var reTag = /<(?:.|\s)*?>/g;
	return this.replace(reTag,"");
}

//返回一个对象的浏览器兼容函数
function getObject(id){
	return document.getElementById(id);
}
//隐藏一个对象
function hidObject(obj){
	obj.style.display = 'none';
	obj.style.visibility = 'hidden';
}

//显示一个对象
function showObject(obj){
	obj.style.display = '';
	obj.style.visibility = 'visible';
}
function isHidden(obj){
	return obj.style.display=='none'||obj.style.visibility=='hidden'?true:false;	
}
//
function nl2br(msg){
	return msg.replace(/\n/g,"<br />");
}
function br2nl(str){
	var reg = /<br\s*\/?>/gi;
	return str.replace(reg,"\n");
}
//基本js
/*
*一个产生 XMLHttpRequest 的对象的类
*/
function createXMLHttpRequest(){
	if(typeof XMLHttpRequest!="undefined"){
		return new XMLHttpRequest();
	}else if(typeof ActiveXObject!="undefined"){
		var a,h,c="MSXML2.XMLHTTP",b="MICROSOFT.XMLHTTP",i=[c+".5.0",c+".4.0",c+".3.0",c,b+".1.0",b+".1",b];
		for(a=0;h=i[a++];){
			try{
				if( typeof(new ActiveXObject(h)) =='object') return new ActiveXObject(h) ;
			}catch(d){}
		}
	}
	return false;
}

//创建一个Http类
function Http(){
	return  {
		sURL 	: '',
		sParams	: '',
		
		http :  new	createXMLHttpRequest(),
	
		//定义http的get方法
		get : function(onReadyStateChange){
			//onReadyStateChange(this.sURL);
			try{
				this.http.open("GET",this.sURL,true);	//在firefox中,此处可能引起跨域调用异常
			}catch(e){alert(e);}
			var temp_http = this.http;
			this.http.onreadystatechange = function(){ 
				onReadyStateChange(temp_http);
			}
			this.http.send(null);
		},		
		//定义http的post方法
		post : function(onReadyStateChange){
			try{		
				this.http.open("POST",this.sURL,true);//在firefox中,此处可能引起跨域调用异常
			}catch(e){alert(e);}
			var temp_http = this.http;
			this.http.setRequestHeader("Cntent-Type","application/x-www-form-urlencoded");
			this.http.onreadystatechange = function(){
				onReadyStateChange(temp_http);
			}
			this.http.send(this.sParams);			
		},
		//构造get字符串
		addURLParam : function(sParamName,sParamValue){
			this.sURL += (this.sURL.indexOf("?") == -1?"?":"&");
			this.sURL += encodeURIComponent(sParamName)+ "=" + encodeURIComponent(sParamValue);
		},
		//构造post字符串
		addPostParam : function(sParamName,sParamValue){
			if(this.sParams.length>0){
				this.sParams += "&";	
			}
			this.sParams += encodeURIComponent(sParamName)+ "=" + encodeURIComponent(sParamValue);
		}
	}
}

//===========================htmlencode()===================
function   HTMLEnCode(str)   
{   
	var   s   =   "";   
	if   (str.length   ==   0)   return   "";   
	s   =   str.replace(/&/g,   "&gt;");   
	s   =   s.replace(/</g,       "&lt;");   
	s   =   s.replace(/>/g,       "&gt;");   
	s   =   s.replace(/   /g,       "&nbsp;");   
	s   =   s.replace(/\'/g,     "&#39;");   
	s   =   s.replace(/\"/g,     "&quot;");   
	s   =   s.replace(/\n/g,     "<br>");   
	return   s;   
}   
function   HTMLDeCode(str)   
{   
	var   s   =   "";   
	if   (str.length   ==   0)   return   "";   
	s   =   str.replace(/&gt;/g,   "&");   
	s   =   s.replace(/&lt;/g,       "<");   
	s   =   s.replace(/&gt;/g,       ">");   
	s   =   s.replace(/&nbsp;/g,       "   ");   
	s   =   s.replace(/&#39;/g,     "\'");   
	s   =   s.replace(/&quot;/g,     "\"");   
	s   =   s.replace(/<br>/g,     "\n");   
	return   s;   
} 
//===============================================================

//============================测试用=========================
/* 
*功能:	返回对对象的类型
*/ 
Object.prototype.getType = function(){
	return typeof(this);	
}
/* 
*功能:	返回对对象的所有属性和方法
*/ 
Object.prototype.getAll = function(){
	return getAll(this);	
}
Function.prototype.hello = function(){
	alert("hello world");	
}
/* 
* 用来遍历指定对象所有的属性名称和值 
* obj 需要遍历的对象 
* author: Jet Mah 
* website: http://www.javatang.com/archives/2006/09/13/442864.html 
*/ 
function getAll(obj) { 
    // 用来保存所有的属性名称和值 
    var props = ""; 
	var funs = "";
    // 开始遍历 
    for(var p in obj){  
        // 方法 
        if(typeof(obj[p])=="function"){  
           	funs += p + "=" +obj[p] + "\n"; 
        }else{  
            // p 为属性名称，obj[p]为对应属性的值 
            props+= p + "=" + obj[p] + "\n"; 
        }  
    }  
    // 最后显示所有的属性 
    return  "properties: \n"+ props + "\n functions: \n"+ funs; 
} 

function getDOMTree(node,indentChar,enter,deep){
	var DOMTree = '';
	enter =enter?enter:'\n';
	indentChar = indentChar?indentChar:'\t';
	deep = deep?++deep:1;	
	DOMTree +=node.nodeName + enter;

	for(var i=0;i<node.childNodes.length;i++){
		DOMTree += printTabs(deep,indentChar) + getDOMTree(node.childNodes[i],indentChar,enter,deep) + enter ;
	}
	return DOMTree +printTabs(--deep,indentChar) + "$" +node.nodeName;
}

/*
*功能:	返回cnt个str连接起来的字符串
*/
function printTabs(cnt,str){
	var tabs = '';
	for(var i=0;i<cnt;i++){
		tabs += str;	
	}
	return tabs;
}