

//判断是否是全部是数字
function isDig(str)
{
    var reg = /^\d*$/;
    return reg.test(str);
}
//判断是否是全部是数字或小数点
function isND(str)
{
    var reg = /^[\+\-]?\d*?\.?\d*?$/;
    return reg.test(str);
}
//判断是否是全部是数字或下划线或字母组成
function isNHM(str)
{
    
    return (str.replace(/\w/g, "").length == 0);
}
//去掉空格
function trim(str)
{ 
 return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}

//判断日期是否合法
function checkDate(sdate,edate)//sdate、edate填写日期控件的名称
{
   var stime=trim(document.getElementById (sdate).value);
   var etime=trim(document.getElementById (edate).value);
   
   if((stime!="")||(etime!=""))
   {
     if(stime=="")
     { 
        alert("请选择起始日期！");
        document.getElementById(sdate).focus();
        return false;
     }
     if(etime=="")
     {
        alert("请选择终止日期！");
        document.getElementById(edate).focus();
        return false;
     }
     if ((!isDate(stime))||(!isDate(etime)))
     {
         if(!isDate(stime))
         {
            alert("起始日期错误！请重新选择！");
             document.getElementById(sdate).focus();
            return false;
         }
         else
         {
             alert("终止日期错误！请重新选择！");
             document.getElementById(edate).focus();
            return false;
         }
         
     }
     else
     {
        if(stime>etime)
        {
           alert("起始日期不能大于终止日期！请重新选择！");
            document.getElementById(sdate).focus();
           return false;
        }
        return true;
     }
   }
   else
   {
     return true;
   }
  
}

//验证给定的日期是否合法   ,参数格式要求：yyyy-mm-dd 可以根据情况更改正则表达式
function isDate(oStartDate)
{
    //对日期格式进行验证 要求为2000-2099年  格式为 yyyy-mm-dd 并且可以正常转换成正确的日期
    var pat_hd=/^20\d{2}-((0[1-9]{1})|(1[0-2]{1}))-((0[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/;
    //对日期格式进行验证 要求为1900-2099年  格式为 yyyy-mm-dd 并且可以正常转换成正确的日期
    //var pat_hd=/^20\d{2}|19\d{2}-((0[1-9]{1})|(1[0-2]{1}))-((0[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/;
 try{
     if(!pat_hd.test(oStartDate)){throw "日期非法！";}
  var arr_hd=oStartDate.split("-");
  var dateTmp;
  dateTmp= new Date(arr_hd[0],parseFloat(arr_hd[1])-1,parseFloat(arr_hd[2]));
  if(dateTmp.getFullYear()!=parseFloat(arr_hd[0]) || dateTmp.getMonth()!=parseFloat(arr_hd[1]) -1 || dateTmp.getDate()!=parseFloat(arr_hd[2]))
  {
   throw "日期非法！";
  }
 }
 catch(ex)
 {
  if(ex.description)
   {return false;}
   else
    {return false;}
 }
 return true;
}
///////////////////两个列表框互选操作///////////////////////////////////////

//全选
function selectall(from,to)
{
  var fromselect=document.getElementById (from);
  var toselect=document.getElementById (to);
  for(var i=fromselect.options.length-1;i>=0;i--)
  {
     selectone(from,to,i);
  }
}

//选择部分
function selectsome(from,to)
{
   var fromselect=document.getElementById (from);
   var toselect=document.getElementById (to);
   for(var i=fromselect.options.length-1;i>=0;i--)
  {
     if(fromselect.options[i].selected)
     {
     selectone(from,to,i);
     }
  }
}

//单选
function selectone(from,to,index)
{
   
   var fromselect=document.getElementById (from);
   var toselect=document.getElementById (to);
   var tempoption=document.createElement("option");
   var newindex;
   if (index==-1)
   {
   newindex=fromselect.selectedIndex;
   }
   else
   {
   newindex=index;
   }
   var insertvalue=fromselect.options[newindex].value;//要插入的value
   var flag=true;//标志是否在目的表已经有该值
   for(var i=toselect.options.length-1;i>=0;i--)
   {
      if(toselect.options[i].value==insertvalue)
      {
      flag=false;
      break;
      }
   }
   if (flag)
   {
   tempoption.value=fromselect.options[newindex].value;
   tempoption.text=fromselect.options[newindex].text;
 
   toselect.add(tempoption);
   }
   fromselect.remove(newindex);
   return false;
}
///////////////////两个列表框互选操作///////////////////////////////////////

/*投票触发*/
function Send_Poll(){
    var pollIds=[],pollcounts=[];
    var pqid=document.getElementById("pollId").value;
    var pqname=document.getElementById("QuestionLab").innerHTML;
    var checkboxs=document.getElementsByName("PollList");
    if(checkboxs!=null&&checkboxs.length>0){
        for(var i=0;i<checkboxs.length;i++){
            if(checkboxs[i].checked){
                pollIds.push(checkboxs[i].value);
                checkboxs[i].title=parseInt(checkboxs[i].title)+1;
                pollcounts.push(checkboxs[i].title);
            }
        }
        if(pollIds!=null&&pollIds.length>0){
            var ret=GZW_MHW.Web._Default.Send_Poll(pollIds,pollcounts).value;
            window_open("Hdjl/TestViewCount.aspx?pqid=" + pqid + "",400,300);
        }
    }
    return false;
}

/*查看网上调查*/
function LookNetPool(){
    var pqid=document.getElementById("pollId").value;
    var pqname=document.getElementById("QuestionLab").innerHTML;
    window_open("Hdjl/TestViewCount.aspx?pqid=" + pqid + "",400,300);
    return false;
}

/*投票触发，二级页面上调用*/
function Se_Send_Poll(){
    var pollIds=[],pollcounts=[];
    var pqid=document.getElementById("pollId").value;
    var pqname=document.getElementById("QuestionLab").innerHTML;
    var checkboxs=document.getElementsByName("PollList");
    if(checkboxs!=null&&checkboxs.length>0){
        for(var i=0;i<checkboxs.length;i++){
            if(checkboxs[i].checked){
                pollIds.push(checkboxs[i].value);
                checkboxs[i].title=parseInt(checkboxs[i].title)+1;
                pollcounts.push(checkboxs[i].title);
            }
        }
        if(pollIds!=null&&pollIds.length>0){
            var ret=GZW_MHW.Web.Interaction.NetPoll_Send.Send_Poll(pollIds,pollcounts).value;
            window_open("../Hdjl/TestViewCount.aspx?pqid=" + pqid + "",400,300);
        }
    }
    return false;
}

/*查看网上调查，二级页面上调用*/
function Se_LookNetPool(){
    var pqid=document.getElementById("pollId").value;
    var pqname=document.getElementById("QuestionLab").innerHTML;
    window_open("../Hdjl/TestViewCount.aspx?pqid=" + pqid + "",400,300);
    return false;
}