function doAllSelect(tempform,obj)
{
 len=tempform.gecs_check_num.value;
 if(obj.checked==true){
	for(t=0;t<len;t++){
	eval("tempform.gecs_check"+t+".checked=true;");
	}
 }else{
 	for(t=0;t<len;t++){
	eval("tempform.gecs_check"+t+".checked=false;");
	}
 }
}


function isPageNum(snum,desc){
    if(snum.value.length < 1){
        return true;
    }else{
        if (isNaN(snum.value)){
            alert(desc+"非法数字！\请重新输入！");
            snum.focus();
            return false;
        }
        s  = /[1-9]+/;
        ok = s.exec(snum.value);
        //alert(ok);
        s2=/[0-9]*[.]+[0-9]*/;
        if(s2.test(snum.value)) {
            alert(desc+"非法数字！\请重新输入！");
            snum.focus();
            return false;
        }
        if(ok!=null){
            return true;
        }else{
            alert(desc+"非法数字！\请重新输入！");
            snum.focus();
            return false;
        }
    }
}

/**********use for pagmanager**************/
var page_form_name;
function setForm(obj){
page_form_name=obj;
}
function getForm(){
return page_form_name;
}

function checkOnKeyPress(){
	if(event.keyCode==13){
		doTurnPage();
	}
}
function doTurnPage(){
	var t=getForm().totalPage.value;
	pn=getForm().pageNo.value;
	if (!isPageNum(getForm().pageNo,"页数")) {
		return;
	} else {
	    if(pn>t){alert('页数非法数字！\请重新输入!');return;};
		getForm().curPage.value=pn;
		getForm().submit();
	}
}
function check() {
	if (isInt(getForm().pageNo,'页数')) return false;
	doTurnPage();
}
function jumpto(type) {
var v=parseInt(getForm().curPage.value);
var t=parseInt(getForm().totalPage.value);
var s=parseInt(getForm().pageSize.value);
if(s==null && s==""){s=10;};
	if(type==1){
		v=1;
	}else if(type==2){
		v=v-1;
	}else if(type==3){
		v=v+1;
	}else if(type==4){
		v=t;
	}
	getForm().curPage.value=v;
	getForm().action=getForm().action_list_url.value;
    getForm().submit();
}
function setForKeyword(){
getForm().curPage.value=1;
getForm().action=getForm().action_list_url.value;
}
function doOrder(field){
	oFlag=getForm().orderFlag.value;
	var newFlag=oFlag==""?"DESC":"";
	getForm().orderFlag.value=newFlag;
	getForm().orderbyField.value=field;
	setForKeyword();
	getForm().submit();
}
/**********use for pagmanager**************/



//替换全部
function replaceAll(Sstring,Cstring,Dstring)
{
  var blength=Cstring.length;
  var firstbyte=Sstring.indexOf(Cstring,0);
  for (var i=0;i<=Sstring.length-blength;i++)
  {
    tstring=Sstring.substring(i,i+blength);
    if (tstring==Cstring)
    {
      Sstring=Sstring.substring(0,i)+Dstring+Sstring.substring(i+blength,Sstring.length);
    }
  }
  return Sstring;
}
//替换全部
function Replace(Sstring,Cstring,Dstring)
{
  var blength=Cstring.length;
  var firstbyte=Sstring.indexOf(Cstring,0);
  for (var i=0;i<=Sstring.length-blength;i++)
  {
    tstring=Sstring.substring(i,i+blength);
    if (tstring==Cstring)
    {
      Sstring=Sstring.substring(0,i)+Dstring+Sstring.substring(i+blength,Sstring.length);
    }
  }
  return Sstring;
}


//检验是否有标记被选择
function hasSelected(theform){
    var ilength = theform.elements.length;
	var isHas = false;
    for (i=0;i<ilength;i++){
        if  (theform.elements[i].type=="checkbox" && theform.elements[i].checked==true && theform.elements[i].name!="gecs_allselectcheck"){
			isHas = true;
        }
    }
    if(isHas == false) {
		alert("对不起，您沒有选择选项!!");
		return false;
	}else{
		return true;
	}
}

//检验是否为空




function isEmpty(obj,desc){
	if(obj.value==""){
		alert(desc+"不能为空");
		obj.focus();
		return false;
	}else{
		return true;
	}
}
function CheckEmpty(obj,desc){
	if(obj.value==""){
		alert(desc+"不能为空");
		obj.focus();
		return false;
	}else{
		return true;
	}
}
//检验redio是否为空


function isRedioEmpty(obj,desc){
	var isHas=0;
	for ( i = 0; i < obj.length; i++ ){
   		if (obj[i].checked) {
   	        isHas = 1;
   		}
	}
	if(isHas==0)
	{
		alert("请选择"+desc);
		obj[0].focus();
		return false;
	}else{
		return true;
	}
}

//检验多个checkbox是否为空,至少要选中一个



function isCheckBoxEmpty(checkboxName,total,desc){
	var isHas=0;
	for ( i = 0; i < total; i++ ){
   		if (eval(checkboxName+""+i+".checked;")) {
   	        isHas = 1;
   		}
	}
	if(isHas==0)
	{
		alert("请选择"+desc);
		eval(checkboxName+"0.focus();");
		return false;
	}else{
		return true;
	}
}

//字数约束
function checkWordNum(obj,num,desc){
	var len=obj.value.length;
	if(len>parseInt(num)){
		alert(desc+"不能超过"+num+"字");
		obj.focus();
		return false;
	}else{
		return true;
	}
}


//检验是否为正确的日期格式 yyyy-mm-dd(10位)
function isDate(sdate,desc){
    if  (sdate.value == ""){
		return true;
	}else{
		if(sdate.value.length!=10){		//判断长度是否10位


			alert(desc+"错误:日期型长度必须是10位！");
			sdate.focus();
			return false;
	    } else{
			var yyyy='';
			var mm='';
			var dd='';
			s=/\d{4}[-]\d{2}[-]\d{2}/;
			ok=s.exec(sdate.value);
			if  (ok==null){
				alert(desc+"日期格式检测错误！\n必须是 'yyyy-mm-dd'格式输入！");
				sdate.focus();
				return false ;
			}
			else{
				yyyy=sdate.value.substring(0,4);
				mm=sdate.value.substring(5,7);
				dd=sdate.value.substring(8,10);
				if  (yyyy<1900||yyyy>2130){
					alert(desc+"的年份不正确！\n请重新输入！");
					sdate.focus();
					return false;
				}
				else if(mm<=0||mm>12){
					alert(desc+"的月份不正确！\n请重新输入！");
					sdate.focus();
					return false;
				}
				else if(dd<=0||dd>31){
					alert(desc+"的天数不正确！\n请重新输入！");
					sdate.focus();
					return false;
				}
				else
					return true ;
			}
		}
    }
}

//判断是否合法数字，比如：6.1,100 合法 ；.34，100. 不合法





function isNumber(snum,desc){
    if  (snum.value == ""){
    	alert("请输入"+desc);
		snum.focus();
        return false;
    }
    else{
        s1=/[^0-9.]+/;
        if  (snum.value.length == 1){
            s2=/[0-9]+/;
        }
        else{
            s2=/[0-9]+[.]?[0-9]+/;
        }
        s3=/[.]+\w*[.]+/;
        ifpoint1=snum.value.substring(snum.length-1,snum.length);
        ifpoint2=snum.value.substring(0,1);
        if  (ifpoint1=="."||ifpoint2=="."){
     	    alert(desc+"错误：数字头不能是'.'");
			snum.focus();
	        return(false);
        }
        ok1=s1.exec(snum.value);
        ok2=s2.exec(snum.value);
        ok3=s3.exec(snum.value);
        if  ((ok1==null)&&(ok2!=null)&&(ok3==null)){
            var tempnum = parseFloat(snum.value);
            if  (tempnum > 0)
	            return true;
	        else{
	            alert(desc+"应大于0");
				snum.focus();
	            return false;
	        }
	    }
        else{
	        alert(desc+"非法数字！\n请重新输入！");
			snum.focus();
	        return false;
	    }
    }
}

//检验是否合法的Email
function isMail(email,desc) {
    s=/\w+@\w+[.]\w+/;
    es=/@+\w*@+/;
    es2=/[.]{2,}/;

    var o=email;
    var ifpoint1=o.value.substring(o.value.length-1,o.value.length);
    var ifpoint2=o.value.substring(0,1);

	if(ifpoint1=="."||ifpoint2=="."){
		alert(desc+"开始或结束不能是'.'");
		o.focus();
		return false;
	}else{
		ok=s.exec(o.value);
		error=es.exec(o.value);
		error2=es2.exec(o.value);
		if(!(ok!=null&&!error&&error2==null)){
			alert("请输入有效的邮件格式！如：'youname@mailserver.com'");
			o.focus();
			return false;
		}else{
			return true;
		}
	}
}
//检验是否是整数
function isInteger(snum,desc){
    var arg = snum.value;
    if  (isNaN(arg)){
    	alert(desc+"非法数字！\n请重新输入！");
        snum.focus();
        return false;
    }
    else{
        var iValue = parseInt(arg);
        //alert(iValue);
        if(iValue<0){
            alert(desc+"不能是负数!");
            snum.focus();
            return false;
        }else{
            var index = arg.indexOf(".");
            if(index == 0) {
                alert(desc+"不能以小数点开头!");
                snum.focus();
                return false;
            }
            if(index == -1) {
                return true;
            } else {
                alert(desc+"要输入整数!");
                snum.focus();
                return false;
            }
        }
    }
}

 function moveOptions(firstSelect,secondSelect){
	len=firstSelect.options.length;
	for(i=0;i<len;i++){
		var oOption=firstSelect.options[i];
		if(oOption!=null){
		if(oOption.selected){
			var value=oOption.value;
			var display=oOption.innerText;
			firstSelect.remove(i);
			i--;
			var oOption2 = document.createElement("OPTION");
			secondSelect.add(oOption2);
			oOption2.innerText=display;
			oOption2.value=value;
		}
		}
 	}
}
 function moveOptionsNoDelete(firstSelect,secondSelect){
	len=firstSelect.options.length;
	len2=secondSelect.options.length;
	for(i=0;i<len;i++){
		var oOption=firstSelect.options[i];
		if(oOption!=null){
			if(oOption.selected){
				var value=oOption.value;
				var display=oOption.innerText;
				var hasExist=0;
				for(q=0;q<len2;q++){
					var oOptiontemp=secondSelect.options[q];
					if(oOptiontemp!=null){
						if(oOptiontemp.value==value){
						hasExist=1;
						}
					}
				}
				if(hasExist==0){
					//alert("no exist");
					var oOption2 = document.createElement("OPTION");
					secondSelect.add(oOption2);
					oOption2.innerText=display;
					oOption2.value=value;
				}else{
					//alert("exist");
				}

			}
		}
 	}
}

 function moveOptionsNoAdd(firstSelect,secondSelect){
	len=firstSelect.options.length;
	for(i=0;i<len;i++){
		var oOption=firstSelect.options[i];
		if(oOption!=null){
			if(oOption.selected){
				var value=oOption.value;
				var display=oOption.innerText;
				firstSelect.remove(i);
				i--;
			}
		}
 	}
}

function isListHasMember(listobj,value){
	len=listobj.options.length;
	var isHas=0;
	for(i=0;i<len;i++){
		if(listobj.options[i]==value){
		isHas=1;
		}
	}
	if(isHas==1){
		return true;
	}else{
		return false;
	}
}
function upOptions(listobj){
	 var selectnum=0;
	 for(i=0;i<listobj.options.length;i++){
		   if(listobj.options[i].selected&&i>0){
				 var oOption0=listobj.options[i-1];
				 var oOption1=listobj.options[i];
				 var value=oOption0.value;
				 var display=oOption0.innerText;
				 oOption0.innerText=oOption1.innerText;
				 oOption0.value=oOption1.value;
				 oOption1.innerText=display;
				 oOption1.value=value;
			 }
	 }
	 selectnum=listobj.options.selectedIndex;
 	 if(selectnum>=0){
	 	listobj.options[selectnum].selected=false;
	 if(selectnum>0) selectnum--;
	 listobj.options[selectnum].selected=true;
 }
}

function downOptions(listobj){
	var selectnum=0;
 	for(i=0;i<listobj.options.length;i++){
   		if(listobj.options[i].selected&&i<listobj.options.length-1){
			 selectnum=i;
			 var oOption0=listobj.options[i];
			  var oOption1=listobj.options[i+1];
			 var value=oOption0.value;
			 var display=oOption0.innerText;
			 oOption0.innerText=oOption1.innerText;
			 oOption0.value=oOption1.value;

			 oOption1.innerText=display;
			 oOption1.value=value;
	     }
 	}
    selectnum=listobj.options.selectedIndex;
	if(selectnum>=0){
		 listobj.options[selectnum].selected=false;
	 	if(selectnum<listobj.options.length-1) selectnum++;
	 	listobj.options[selectnum].selected=true;
	}
}
function getOptionValues(listobj){
	var str="";
	for(i=0;i<listobj.options.length;i++){
		var oOption0=listobj.options[i];
		var value=oOption0.value;
		var display=oOption0.innerText;
		if(str==""){
			str=value;
		}else{
			str=str+";"+ value;
		}
	}
	//alert(str);
	return str;
}
function getOptionTexts(listobj){
	var str="";
	for(i=0;i<listobj.options.length;i++){
		var oOption0=listobj.options[i];
		var value=oOption0.value;
		var display=oOption0.innerText;
		if(str==""){
			str=display;
		}else{
			str=str+";"+ display;
		}
	}
	//alert(str);
	return str;
}