// 去左右空格
function trim(s){ 
return rtrim(ltrim(s)); 
}
// 去左空格
function ltrim(s){ 
return s.replace( /^\s*/, ""); 
}
// 去右空格
function rtrim(s){ 
return s.replace( /\s*$/, ""); 
}
//检查textarea输入框的长度的函数   
function CheckInputLength(obj,maxword){
	var len=obj.innerHTML.length;
	if(len>maxword)
	{
		alert("对不起，您输入的字数已经超过"+maxword+"个!");
		obj.innerHTML = obj.innerHTML.substring(0, maxword);
	}
}
function IsNum(theNum)
{
	//判断是否为数字
	for(var i=0;i<theNum.length;i++){
	  oneNum=theNum.substring(i,i+1);
	if (oneNum < "0" || oneNum>"9")
	return false;
	}
	return true;
}

function GetRadioValue(RadioName){
    var obj;    
    obj=document.getElementsByName(RadioName);
    if(obj!=null){
        var i;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                return obj[i].value;            
            }
        }
    }
    return null;
}
function GetSelectValue(SelectName){
	var tt="";
	tt=document.getElementsByName(SelectName)[0].options[document.getElementsByName(SelectName)[0].selectedIndex].value;
	return tt;
}
function GetCheckboxValue(CheckboxName){
    var r=document.getElementsByName(CheckboxName); 
	var result="";
    for(var i=0;i<r.length;i++){
         if(r[i].checked){
			 if(result=="") result=r[i].value;
			 else result=result+","+r[i].value;
         }
    }
	return result;
}
function ResetCheckboxValue(CheckboxName){
    var r=document.getElementsByName(CheckboxName); 
    for(var i=0;i<r.length;i++){
        r[i].checked=false;
    }
	return;
}

function setRadioValue(RadioName,str){ 
	var objs=document.getElementsByName(RadioName) 
	for(var i=0;i<objs.length;i++) 
	{ 
		if(objs[i].value==str) 
		{ 
			objs[i].checked=true 
			break; 
		} 
	} 
}

function ResetSelectValue(SelectName,ItemValue){   
	var obj;    
    obj=document.getElementsByName(SelectName);
     for(var i=0;i<obj[0].options.length;i++)
     {
         if(obj[0].options[i].value == ItemValue)
         {
             obj[0].options[i].selected = true;
             break;
         }
     }  
}

function sAlert(msgwidth,msgtitle,txt){
	var sWidth,msgdivWidth,msgdivleft;
	msgdivWidth=msgwidth;	                           //可设置浮动框的宽度
	sWidth=document.documentElement.offsetWidth;  //如果内容不是很宽时，用此更好(一般情况)
	//sWidth=((document.documentElement.clientWidth>document.documentElement.scrollWidth)?document.documentElement.clientHeight:document.documentElement.scrollWidth);  //如果内容过宽时，可用此值，可使浮动框始终居中
	msgdivleft=(sWidth-msgdivWidth)/2;
	var bg_div = document.createElement("DIV");
	bg_div.id = "bg_div";
	bg_div.style.position = "absolute";
	bg_div.style.left = "0px";
	bg_div.style.top = "0px";	
	bg_div.style.width = ((document.documentElement.clientWidth>document.documentElement.scrollWidth)?document.documentElement.clientHeight:document.documentElement.scrollWidth)+"px";
	bg_div.style.height = ((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px";
	bg_div.style.background = "#333";
	bg_div.style.textAlign = "center";
	bg_div.style.zIndex = "10";//bg_div.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=5,finishOpacity=75)";  //背景有静态渐变效果,但无动态过度效果
	bg_div.style.filter = "alpha(opacity=0)";                           //背景无静态渐变效果,但有动态过度效果
	bg_div.style.opacity = 0.6;
//浮动框层	
	var msg_div = document.createElement("DIV");
	msg_div.id="msg_div";
	msg_div.style.position = "absolute";
	msg_div.style.left = msgdivleft+"px";
	msg_div.style.top = (document.documentElement.scrollTop+100)+"px";                         //设置浮动框上边框位置	
	//msg_div.style.lineHeight = "10px";	
	//msg_div.style.marginTop = -105+document.documentElement.scrollTop+"px";
	msg_div.style.width = msgdivWidth+"px";
	msg_div.style.height = "auto";
	//msg_div.style.background = "#333";
	msg_div.style.textAlign = "center";

	msg_div.style.zIndex = "11";
	
	strHtml  = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
	//strHtml += "	<li style=\"background:#99CCFF;text-align:right;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;\"><a href=\"javascript:doOk()\"><font color=#ff0000>[关闭提示]</font></a></li>\n";	
	strHtml += "	<li style=\"background:#99CCFF;text-align:left;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1px solid #336699;\">["+msgtitle+"]</li>\n";
	strHtml += "	<li><div style=\"background:#fff;text-align:left;font-size:12px;border-left:1px solid #336699;border-right:1px solid #336699;\">"+txt+"</div></li>\n";
	//strHtml += "	<li style=\"background:#99CCFF;text-align:center;font-weight:bold;height:25px;line-height:25px; border:1px solid #99CCFF;\"><input type=\"button\" value=\" 关 闭 \" id=\"do_OK\" onclick=\"doOk()\" /></li>\n";
	strHtml += "</ul>\n";
	msg_div.innerHTML = strHtml;
	document.body.appendChild(msg_div);
	document.body.appendChild(bg_div);
	this.setOpacity = function(obj,opacity){
		if(opacity>=1)opacity=opacity/100;
		try{ obj.style.opacity=opacity; }catch(e){}
		try{ 
			if(obj.filters.length>0&&obj.filters("alpha")){
				obj.filters("alpha").opacity=opacity*100;
			}else{
				obj.style.filter="alpha(opacity=\""+(opacity*100)+"\")";
			}
		}catch(e){}
	}
	var c = 0;
	this.doAlpha = function(){
		if (++c > 20){clearInterval(ad);return 0;}
		setOpacity(bg_div,c);
	}
	var ad = setInterval("doAlpha()",1);
	this.doOk = function(){
		document.body.removeChild(msg_div);
		document.body.removeChild(bg_div);
		document.body.onselectstart = function(){return true;}
		document.body.oncontextmenu = function(){return true;}
	}
	//document.getElementById("do_OK").focus();
	return this;
}