/*
作者：那些花儿
时间: 2010-10-14
*/
//程序内部响应键盘事件
	function keydown(keyCode){
		    if(!document)
			return;
			if(keyCode==67 )
            {
			 CopiedTxt = document.selection.createRange();
			 CopiedTxt.execCommand("Copy");
			}
			else  if(keyCode==86 )
            {
			 CopiedTxt = document.selection.createRange();
			 CopiedTxt.execCommand("Paste"); 
			}
			 else  if(keyCode==88 )
            {
			 CopiedTxt = document.selection.createRange();
			 CopiedTxt.execCommand("Cut"); 
			}
			else  if(keyCode==90)
            {
			  CopiedTxt = document.selection.createRange();
			  CopiedTxt.execCommand("Undo");
			}
			}
//插入到光标位置
	function InsertString(tbid, str){
	var tb = document.getElementById(tbid);
    tb.focus();
    if (document.all){
        var r = document.selection.createRange();
        document.selection.empty();
        r.text = str;
        r.collapse();
        r.select();
    }
    else{
        var newstart = tb.selectionStart+str.length;
        tb.value=tb.value.substr(0,tb.selectionStart)+str+tb.value.substring(tb.selectionEnd);
        tb.selectionStart = newstart;
        tb.selectionEnd = newstart;
    }
}
//选中全部
function checkAll(e, itemName)
{
    var aa = document.getElementsByName(itemName);
    for (var i=0; i<aa.length; i++)
      aa[i].checked = e.checked;
}
//选中一项
function checkItem(e, allName)
{
   var all = document.getElementsByName(allName)[0];
   if(!e.checked) all.checked = false;
   else
   {
    var aa = document.getElementsByName(e.name);
    for (var i=0; i<aa.length; i++)
     if(!aa[i].checked) return;
    all.checked = true;
   }
}
//以下为tab显示控制
function Nav()
{
	if(window.navigator.userAgent.indexOf("MSIE")>=1) return 'IE';
	else if(window.navigator.userAgent.indexOf("Firefox")>=1) return 'FF';
	else return "OT";
}
function $Obj(objname)
{
	return document.getElementById(objname);
}

function ShowConfig(em,allgr)
{
		var oItem1 = document.getElementById('tab21');  
		if(oItem1)
		{
			 oItem1.style.fontWeight = "normal";
			 oItem1.style.color="";
		}

		var oItem2 = document.getElementById('tab22');  
		if(oItem2)
		{
			 oItem2.style.fontWeight = "normal";
			 oItem2.style.color="";
		}

	for(var i=1;i<=allgr;i++)
	{    
		var oItem = document.getElementById('tab'+i);  		
		if(i==em)
		{
			$Obj('td'+i).style.display = (Nav()=='IE' ? 'block' : 'table');
			 if(oItem)
			 {
			  oItem.style.fontWeight="900";
			 oItem.style.color="#FF0000";
			}

		}
		else 
		{
			$Obj('td'+i).style.display = 'none';
			if(oItem)
			{
			 oItem.style.fontWeight = "normal";
			 oItem.style.color="";
			}
		}
	}
}
/*function ShowHide(objname)
{
	alert(objname);
	var obj = $Obj(objname);
	if(obj.style.display != "none") obj.style.display = "none";
	else obj.style.display = (Nav()=='IE' ? 'block' : 'table-row');
}*/

function HideSaveTip()
{
	$Obj('savetip').style.display = 'none';
}
function ShowSaveTip()
{		
    $Obj('savetip').style.top=(document.body.scrollTop+(document.body.clientHeight-$Obj('savetip').offsetHeight)/2)+"px";
     $Obj('savetip').style.left=(document.body.scrollLeft+(document.body.clientWidth-$Obj('savetip').offsetWidth)/2)+"px";
	$Obj('savetip').style.display ='';
	setTimeout("HideSaveTip();",700);
		

}

function SetBtnEnable(id,bl)
{
  if(bl==0)
    document.getElementById(id).disabled="disable";
  else
	document.getElementById(id).disabled=""; 
}

function SetBtnText(id,str)
{
    document.getElementById(id).value=str;
}
function HideRow(isShow,id)
{
if(isShow){
		 $Obj(id).style.display = (Nav()=='IE' ? 'block' : 'table');
			}
else{
		$Obj(id).style.display= 'none';
	}
}

function SetFocus(id)
{
	document.getElementById(id).focus();
	document.getElementById(id).select();//选中
		var t = document.getElementById(id).createTextRange();
	t.moveStart("character", 0); //开头
	t.moveEnd("character", t.text.length); //结尾
	t.select();//选中
}

function SetDiffFont(id,str)
{
	oDiv = document.createElement('DIV');
	oDiv.innerHTML = str;
	oDiv.id="testResultTip";
	$Obj(id).appendChild(oDiv);
}

//是否为数字
function IsNumber()
{
    var    k=window.event.keyCode;   

    if ((k==46)||(k==8)||(k==189)||(k==109)||(k==190)||(k==110)|| (k>=48 && k<=57)||(k>=96 && k<=105)||(k>=37 && k<=40)) 
    {}
    else if(k==13){
         window.event.keyCode = 9;}
    else{
         window.event.returnValue = false;}
}

//判断是否为字母
function IsLetter()     
{     
      var    k=window.event.keyCode;   
    if ((k>=97 && k<=122)||(k>=65 && k<=90)) 
    {}
    else{
         window.event.returnValue = false;
		 }
}   

//限制最大长度,属性maxlength
function isMaxLen(o){  
 var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):"";  
 if(o.getAttribute && o.value.length>nMaxLen){  
 o.value=o.value.substring(0,nMaxLen)  
 }  
} 