function $(str){
	return document.getElementById(str);
}

function $_(str){
	return document.getElementsByName(str);
}
//浏览器判断
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){  
	if (typeof(a)=="string") return a.replace(/(^\s+)|(\s+$)/g,'');  
	else return a;
}

// 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));
	}
}

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 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 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);	
}

function getRadioValue(a)	//得到radio的value值
{
	var Obj = document.getElementsByName(a);
	for(i=0;i<Obj.length;i++)
		{
			if(Obj[i].checked){break}
		};
	if(i==Obj.length)
		{
			filetype = "";
		}
		else
		{
			filetype = Obj[i].value;
		}	
	return filetype;
}

function CheckRadio(obj){
	o = $_(obj);
	p = false;
	for(i = 0;i < o.length;i ++){
		if (o[i].checked)
		{
			p = true;
			break;
		}
	}
	return p;
}

function GetRadioValue(obj){
	o = $_(obj);
	for(i = 0;i < o.length;i ++){
		if (o[i].checked)
		{
			myvalue = o[i].value;
			break;
		}
	}
	return myvalue;
}

function GetCheckboxValue(obj){
	o = $_(obj);
	var myvalue = '';
	for(i = 0;i < o.length;i ++){
		if (o[i].checked)
		{
			myvalue += o[i].value + ",";
		}
	}
	return myvalue.substring(0,myvalue.length-1);
}

function CheckBoxValue(obj,value){
	var objvalue = "," + GetCheckboxValue(obj) + ",";
	var value = "," + value + ",";
	if(objvalue.indexOf(value) > -1)
		return 1;
	else
		return 0;
}

/** 全选 ischeck=false 为全不选*/
function checkAll(name, ischeck){
	var names = document.getElementsByName(name);
	var len = names.length;
	for(var i=0; i<len; i++){
		if(!names[i].disabled){
			if(ischeck){
				names[i].checked = true; 
			}else{
				names[i].checked = false; 
			}
		}
	}
}

function ischeckAll(obj, name){
	var chkAllobj = document.getElementsByName(obj.name);
	var len = chkAllobj.length;
	
	if(obj.checked){
		checkAll(name, true);
		for(var i=0; i<len; i++){
			chkAllobj[i].checked = true;
		}
	}else{
		checkAll(name, false);
		for(var i=0; i<len; i++){
			chkAllobj[i].checked = false;
		}
	}
}
function chkAllUrl(name, url){
	var names = document.getElementsByName(name);
	var len = names.length;
	var str = '';
	
	for(var i=0; i<len; i++){
		if(!names[i].disabled){
			if(names[i].checked){ 
				str += ((i == 0) ? '' : ',') + names[i].value;
			}
		}
	}
	
	window.location.href = url + str;
}
