//浏览器判断
var lBrowser = {}; 
lBrowser.agt = navigator.userAgent.toLowerCase(); 
lBrowser.isW3C = document.getElementById ? true:false; 
lBrowser.isIE = ((lBrowser.agt.indexOf("msie") != -1) && (lBrowser.agt.indexOf("opera") == -1) && (lBrowser.agt.indexOf("omniweb") == -1)); 
lBrowser.isNS6 = lBrowser.isW3C && (navigator.appName=="Netscape"); 
if(lBrowser.isNS6){ //firefox innerText define 
	HTMLElement.prototype.__defineGetter__( "innerText", function(){  return this.textContent;});  
	HTMLElement.prototype.__defineSetter__( "innerText", function(sText){ this.textContent=sText;});  
} 

function trim(a){  
	//   	type 1:
	//   	用正则表达式将前后空格  
	//   	用空字符串替代。  
	   	if (typeof(a)=="string") return a.replace(/(^\s+)|(\s+$)/g,'');  
		else return a;
	//	type 2:
/*	for(var i=0; i<a.length && (a.charAt(i)<'0'); i++);
    for(var j=a.length; j>0 && (a.charAt(j-1)<'0'); j--);
    if (i>j) return '';  
    return a.substring(i+2,j);  
*/
}

// Ajax类
function classAjax(){
	var _z = false; //xmlHTTP
	try {
		_z = new XMLHttpRequest();
	}catch (trymicrosoft){
		try {
			_z = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (othermicrosoft){
			try {
				_z = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (failed){
				_z = false;
			}
		}
	}
	this.setRequest = function(url,para,fun){
		_z.open("POST",url,true); 
		_z.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		_z.onreadystatechange = function(){
			if (_z.readyState==4){
				if (_z.status==200){
					fun(_z.responseText);
				}
			}
		}
		_z.send(encodeURI(para));
	}
}

//Dom 
function $(a){ 
	if (typeof(a)=="string")return document.getElementById(a);
	else return a;
}
function A(a, b, c, d, e, f, g){
  var _z = document.createElement("div");
  	a.appendChild(_z);
	vec(_z, b, c, d, e);
	if (f){
		for (var _y in f){
			_z.style[_y] = f[_y]; 
			if (_y=="class"){
				_z.className=f[_y]
			}
		}
	}
	if (g) I(_z, g);
    return _z;
}
function Aa(a, b, c, d, e, f, g){
	var _z = document.createElement("a");
	_z.href="#";
	vec(_z, b, c, d, e);
	if (f){
		for (var _y in f){
			if (_y=="class"){
				_z.className=f[_y]
			}else{
				_z.style[_y] = f[_y]; 
			}
		}
	}
	if (g) I(_z, g);
	a.appendChild(_z);
    return _z;
}
function Aspan(a, b){
	var _z = document.createElement("span");
	_z.style.position="static";
	if (b) I(_z, b);
	a.appendChild(_z);
    return _z;
}
function I(a, b){
	if (!a) return;
	a.innerHTML = (b) ? b : '';
}
function vE(a){
	$(a).style.display = "";
}
function hE(a){ 
	$(a).style.display = "none";
}
function iV(a){
	if ($(a).style.display=="none") return false;
	else return true;
}
function cE(a){
	if (iV(a))hE(a);
	else vE(a);
}
function vec(a, b, c, d, e){
	if (b) a.style.left = b;
	if (c) a.style.top = c;
	if (d) a.style.width = d;
	if (e) a.style.height = e;
}

//Cookie;
function setCookie(name,value,expireHours){
	var cookieString=name+"="+escape(value);
	//判断是否设置过期时间
	if(expireHours>0){
		var date=new Date();
		date.setTime(date.getTime+expireHours*3600*1000); // 转换为毫秒
		cookieString+="; expire="+date.toGMTString();
	}
	document.cookie=cookieString;
}
function getCookie(name){
	var strCookie=document.cookie;
	var arrCookie=strCookie.split("; "); // 将多cookie切割为多个名/值对
	var lenCookie=arrCookie.length;
	for(var i=0;i<lenCookie;i++){ // 遍历cookie数组，处理每个cookie对
		var arr=arrCookie[i].split("="); // 找到名称为userId的cookie，并返回它的值
		if(arr[0]==name) return unescape(arr[1]);
	}
	return "";
}
function deleteCookie(name){
	var date=new Date();
	date.setTime(date.getTime()-10000); // 删除一个cookie，就是将其过期时间设定为一个过去的时间
	document.cookie=name+"=v; expire="+date.toGMTString();
}

//debug
function showmsg(){
	if (debug){
		if (typeof(debug_msg)=="undefined"){
			debug_msg=[];	//debug信息存放
			t = getMS();
		}
		var _z = getMS();
		var _y = arguments.length;
		var _x = "";
		for (var i=0; i<_y; i++){
			_x += arguments[i]+", ";
		}
		if (_y==0) _x = 'here';
		debug_msg.unshift((_z-t)%10000+": "+_x+"<br>"); 
		t = _z;
		if (debug_msg.length>50)debug_msg.pop();	//限制行数
		I(D_content, debug_msg.join(""));
	}
}
function getMS(){
	return (new Date()).getMinutes()*60000+(new Date()).getSeconds()*1000+(new Date()).getMilliseconds();
}
function myalert(){
	var _z = "";
	var _y = arguments.length;
	for (var i=0; i<_y; i++){
		_z += myalert.arguments[i]+", ";
	}
	alert(_z);	
}
function showarr(a){
	var _z = "";
	var _y = a.length;
	for (var i=0; i<_y; i++){
		_z += "["+i+"]"+a[i]+", \n";
	}
	alert(_z);	
}