//常用JavaScript函数
//Created by Simb 2004.10.20

function OpenWin(url,target,w,h){
	newWin=window.open(url,target,"toolbar=no,menubar=no,status=no,location=no,scrollbars=yes,resizable=no,copyhistory=yes,width="+w+",height="+h);
	if(newWin)
		newWin.focus();
	else
		alert("出现错误，可能是因为你的浏览器屏蔽了弹出窗口功能！\r请尝试修改浏览器设置或者在点击时按住Ctrl键。")
}
function GetRadioValue(ObjectName){//检验单选按钮


	var Object=document.getElementsByName(ObjectName);	
	for(iIndex=0;iIndex<Object.length;iIndex++)
	{
		if(Object[iIndex].checked==true)
		{
			return true;
		}
	}
	return false;
}
function textCounter(field, countfield, maxlimit) {//限制字数
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0,maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}
function havenoChar(theelement){//含有非法字符 返回 true
   text="'%\"";
   for(i=0;i<=theelement.length-1;i++)
   {
      char1=theelement.charAt(i);
      index=text.indexOf(char1);
      if(index!=-1)
      {
        return true;
      }
   }
   return false;
}

function NotNumber(theelement,flag){//是否数字,flag=1为整数


    if(theelement==""||theelement=="."){
        return true;
    }	
    if(flag){  
	text="1234567890";
	}
    else{
	text="1234567890.";
	}
   for(i=0;i<=theelement.length-1;i++)
   {
      char1=theelement.charAt(i);
      index=text.indexOf(char1);
      if(index==-1)
      {
        return true;
      }
   }
   return false;
}

function checknum(targ,flag)
{//检查输入是否数字


	var num=num;	
	if(targ.value==""){
		alert("Please enter a number！");
		targ.value=targ.defaultValue;
		targ.focus();
		return;
	}
	if(flag){
		if(NotNumber(targ.value,1)){
			alert("Please enter an integer");
			targ.value=targ.defaultValue;
			targ.focus();
			return;
		}
	}
	else{
		if(NotNumber(targ.value,0)){
			alert("Plase enter a number！");
			targ.value=targ.defaultValue;
			targ.focus();
			return;
		}		
	}
}

function whichItem(flag){//选择操作对象
	var e = event.srcElement
	while (e.tagName != flag)
		e = e.parentElement
	return e
}

function CheckAll(targ){//全部选中
	if (targ.sel.length==null)
		{//只有一条记录的情况
			targ.sel.checked=targ.selall.checked;
			cca(targ.sel);
		}else{
			for (var i=0;i<targ.sel.length;i++){
			targ.sel[i].checked=targ.selall.checked;
			cca(targ.sel[i]);
			}
		}
}

function CheckSelect(targ){//是否选中，返回选中的记录数目
	var num=0;
	if (targ.sel.length==null)
		{//只有一条记录的情况
			if (targ.sel.checked==true){
				num=1;
			}			
		}else{
			for (var i=0;i<targ.sel.length;i++){
			if(targ.sel[i].checked)
			num+=1;
			}
		}
	if(num==0){
		alert("你没有选中任何信息！！");
		}
	return num;
}

function DeleteAlert(targ,act,flag){//删除警告,flag非零则每次只能处理一条记录


	if (CheckSelect(targ)) {
		if(flag && CheckSelect(targ)>1){
			alert("此操作每次只能处理一条记录！")
			return;
		}
		if(confirm("警告：此操作不可恢复！！\r确认删除所选信息？")){
			targ.action=act;
			targ.submit();
		}
	}
}

function DoSubmit(targ,act,flag){//提交表单,flag非零则每次只能处理一条记录


	if (CheckSelect(targ)) {
		if(flag && CheckSelect(targ)>1){
			alert("此操作每次只能处理一条记录！")
			return;
		}
		targ.action=act;
		targ.submit();
	}
}

function DelAlert(act){//警告
if (confirm("警告：此操作不可恢复！！\r确认删除所选信息？"))
window.location=act;
return;
}

function cca(s){//选择后变颜色
	var e=s
	while (e.tagName != "TR")
		e = e.parentElement;	
	if(s.checked)
		e.style.backgroundColor="#C1CDD8";
	else
		e.style.backgroundColor="#FFFFFF";
}

function CheckPage(targ){//检测页码


	if(NotNumber(targ.page.value)){
		alert("请输入正确的页码!");
		targ.page.value=targ.page.defaultValue;
		targ.page.focus();
		return false;
	}
	return true;
}

function CheckCheckCode(){
	if(document.all.CheckCode.value==""){
		alert("请输入验证码！");
		document.all.CheckCode.focus();
		return false;
	}
	return true;
}

function ChangePage(newpage){//换页
	var newpage=newpage;
	targ=document.pageform;
	targ.page.value=newpage;
	targ.submit();
}
function displayCtl(t_id){//显示或隐藏层
	if (t_id.style.display == "none"){ //如果为隐藏状态切换为显示状态


		t_id.style.display="";      
	}
	else{//否则
		t_id.style.display="none";  //切换为隐藏状态


	}
}

function SelectOption(targ,sv){//根据选定值定位下拉菜单 targ:目标下拉菜单，sv选中的数值

	if(sv=="") return;
	for(i=0;i<=targ.length;i++){
		if(targ.options[i].value==sv){
			targ.selectedIndex=i;
			break;
		}
	}	
}

function AddList(fromList,toList,num){//从一个列表中选择内容到另一个列表

	var i,m,flag;
	for(i=0;i<fromList.length;i++){
		if(toList.length>=num){
			alert("对不起，最多可以选择"+num+"项！");
			return;
		}
		flag=0;		
		if(fromList.options[i].selected&&fromList.options[i].value!=''){
			for(m=0;m<toList.length;m++){
				if(toList.options[m].value==fromList.options[i].value){
				flag=1;
				break;
				}
			}
			if(flag==0)
			toList.options[toList.length]=new Option(fromList.options[i].text, fromList.options[i].value);
		}
	}
}

function DeleteList(tf){//从列表中删除选定项

	var i,obj;
	var tmp = new Array();
	for(i=0;i<tf.length;i++){
		if(tf.options[i].selected==false)
		tmp[tmp.length]=new Array(tf.options[i].text,tf.options[i].value);
	}
	tf.length=0;
	for(i=0;i<tmp.length;i++){
		tf[tf.length]=new Option(tmp[i][0],tmp[i][1]);
	}
}