// JavaScript Document
//前台編輯列表頁
function listsend()
{
  var mytb=document.getElementById('edtable');
  var data=Array();
  var m=mytb.rows.length;
  var num=0;
  for(i=1;i<m;i++)
  {//選擇編輯項目
    if(mytb.rows[i].cells[0].firstChild.checked)
    {
      data[data.length]=mytb.rows[i].cells[0].firstChild.value;
      num++;
    }
    
  }
  
  if(num==0) 
  { 
     alert('請勾選項目');
  }
  else
  {
     var myurl=window.location.href.split("/");
     var editurl=myurl[myurl.length-1].split("_");
     gotourl(editurl[0]+'_edit.php'+'?id='+data);
  }
}

function listsends()
{
  var myurl=window.location.href.split("/");
  var editurl=myurl[myurl.length-1].split("_");
  gotourl(editurl[0]+'_edit.php');
}

//邀請福委會
function Invite(){
    var myurl=window.location.href.split("/");
    var editurl=myurl[myurl.length-1].split("_");
    gotourl(editurl[0]+'_invite.php');
}

//福委會移除會員
function Out(){
    var mytb=document.getElementById('edtable');
    var data=Array();
    var m=mytb.rows.length;
    var num=0;
    for(i=1;i<m;i++){//選擇編輯項目
        if(mytb.rows[i].cells[0].firstChild.checked){
            data[data.length]=mytb.rows[i].cells[0].firstChild.value;
            num++;
        }  
    }
  
    if(num==0){ 
        alert('請勾選項目');
    }else{
        if( confirm("確定要移除勾選的 "+num+" 位會員!?\n移除的會員將不在屬於福委會!!") ){
            var myurl=window.location.href.split("/");
            var editurl=myurl[myurl.length-1].split("_");
            gotourl(editurl[0]+'_list.php'+'?type=out&id='+data);                
        }
    }
}

//會議紀錄
function meetingsend()
{
  var mytb=document.getElementById('edtable');
  var data=Array();
  var m=mytb.rows.length;
  var num=0;
  for(i=1;i<m;i++)
  {//選擇編輯項目
    if(mytb.rows[i].cells[0].firstChild.checked)
    {
      data[data.length]=mytb.rows[i].cells[0].firstChild.value;
      num++;
    }
    
  }
  
  if(num==0) 
  { 
     alert('請勾選項目');
  }
  else
  {
     var myurl=window.location.href.split("/");
     var editurl=myurl[myurl.length-1].split("_");
     gotourl(editurl[0]+'_edit.php'+'?id='+data+'&ck=1');

  }
}

//前台編輯列表頁
function addsend()
{
  var myurl=window.location.href.split("/");
  var editurl=myurl[myurl.length-1].split("_");
  gotourl(editurl[0]+'_edit.php');
}

//前台編輯頁
function reback()
{
  var myurl=window.location.href.split("/");
  var editurl=myurl[myurl.length-1].split("_");
  gotourl(editurl[0]+'_list.php');
}

function rebackimg()
{
  var myurl=window.location.href.split("/");
  var editurl=myurl[myurl.length-1].split("_");
  var qs=editurl[1].indexOf("=");
  qs++; 
  gotourl(editurl[0]+'_list.php'+'?id='+editurl[1].substring(qs));
}

//前台刪除
function delsend()
{
    if(confirm("確定要刪除選擇的項目?? ")){
        var mytb=document.getElementById('edtable');
        var data=Array();
        var m=mytb.rows.length;
        var num=0;
        for(i=1;i<m;i++)
        {//選擇刪除項目
            if(mytb.rows[i].cells[0].firstChild.checked){
                data[data.length]=mytb.rows[i].cells[0].firstChild.value;
                num++;
            }   
        }
  
        if(num==0){ 
            alert('請勾選項目');
        }else{
            var myurl=window.location.href.split("/");
            var editurl=myurl[myurl.length-1].split("_");
            gotourl2(editurl[0]+'_list.php'+'?type=del&id='+data);
        }        
    }
}

function excel()
{
  var mytb=document.getElementById('edtable');
  var data=Array();
  var m=mytb.rows.length;
  var num=0;
  for(i=1;i<m;i++)
  {//選擇編輯項目
    if(mytb.rows[i].cells[0].firstChild.checked)
    {
      data[data.length]=mytb.rows[i].cells[0].firstChild.value;
      num++;
    }
    
  }
  
  if(num==0) 
  { 
     alert('請勾選項目');
  }
  else if(num>1)
  {
    alert('只能選一個項目');
  }
  else
  {
     var myurl=window.location.href.split("/");
     var editurl=myurl[myurl.length-1].split("_");
     gotourl('excel.php?id='+data);
     
  }
}

function addimg()
{
  var data=document.getElementById('search').value;
  var myurl=window.location.href.split("/");
  var editurl=myurl[myurl.length-1].split("_");
  var qs=editurl[1].indexOf("=");
  qs++; 
  gotourl(editurl[0]+'_edit.php'+'?id='+editurl[1].substring(qs));
}

//刪除相片
function Delimg(){
    var id=document.getElementById('id').value;
    var mydiv=document.getElementById('eddiv');
    obj=mydiv.getElementsByTagName('input');
    var data=Array();
    var num = 0;
    for(i=0;i<obj.length;i++){
        if(obj[i].checked){
            data[data.length]=obj[i].value;
            num++;
        }
    }
    if(num==0) alert("請勾選欲刪除項目!!");
    else{
        if(confirm("確定要刪除選擇的項目?? "))  gotourl(window.location.href+'&type=del&data='+data+'&id='+id);        
    }     
}

//刪除相簿
function delalbum()
{
  var mydiv=document.getElementById('eddiv');
	obj=mydiv.getElementsByTagName('input');
	var data=Array();
	
	for(i=0;i<obj.length;i++){
    if(obj[i].checked) data[data.length]=obj[i].value;
  }

  gotourl(window.location.href+'?type=del&data='+data);
}

//設為封面
function cover(){
    var id=document.getElementById('id').value;
    var mydiv=document.getElementById('eddiv');
    obj=mydiv.getElementsByTagName('input');
    var data='';
    cks=0;
    for(i=0;i<obj.length;i++){
        if(obj[i].checked){
            cks++;
            data=obj[i].value;
        }
    }
  
    if(cks!=1){
        alert('封面只能選一張');
    }else{
        gotourl(window.location.href+'&type=cover&data='+data+'&id='+id);
    }
}

//檢視
function view()
{
  var mytb=document.getElementById('edtable');
  var data=Array();
  var m=mytb.rows.length;
  var num=0;
  for(i=1;i<m;i++)
  {//選擇編輯項目
    if(mytb.rows[i].cells[0].firstChild.checked)
    {
      data[data.length]=mytb.rows[i].cells[0].firstChild.value;
      num++;
    }
    
  }
  
  if(num==0) 
  { 
     alert('請勾選項目');
  }
  else
  {
     var myurl=window.location.href.split("/");
     var editurl=myurl[myurl.length-1].split("_");
     gotourl(editurl[0]+'_view.php'+'?id='+data);
  }
}

//寄發電子報
function sendnews()
{
  var mytb=document.getElementById('edtable');
  var data=Array();
  var m=mytb.rows.length;
  var num=0;
  for(i=1;i<m;i++)
  {//選擇編輯項目
    if(mytb.rows[i].cells[0].firstChild.checked)
    {
      data[data.length]=mytb.rows[i].cells[0].firstChild.value;
      num++;
    }
    
  }
  
  if(num==0) 
  { 
     alert('請勾選項目');
  }
  else
  {
     var myurl=window.location.href.split("/");
     var editurl=myurl[myurl.length-1].split("_");
     gotourl(editurl[0]+'_send.php'+'?id='+data);
  }
}

//前台搜索
function search()
{
  var data=document.getElementById('search').value;
  var myurl=window.location.href.split("/");
  var editurl=myurl[myurl.length-1].split("_");
  gotourl2(editurl[0]+'_list.php'+'?keyword='+encodeURIComponent(data));
  
}

//前台功能表開關
function leftitems()
{
  var myurl=window.location.href.split("/");
  var editurl=myurl[myurl.length-1].split("_");
  var ss=document.getElementById(editurl[0]);
  var m=document.getElementById(ss.getAttribute('alt'));
  document.getElementById(m.id+'s').style.display='';
  
}

//資料區選取
function ListSel(chk){
    var obj = document.getElementById("edtable");
    var Num = 1;
    for(var i=Num;i<obj.rows.length;i++){
        obj.rows[i].cells[0].firstChild.checked = chk;
    }
}

//下一筆
function next()
{
    var myurl=window.location.href.split("/");
    var editurls=myurl[myurl.length-1].split("?id=");
    var editurl=myurl[myurl.length-1].split("_");
    var items=editurls[1].split(",");
    items.shift();
    if(items.length>=1) gotourl(editurl[0]+'_view.php'+'?id='+items);
    else gotourl(editurl[0]+'_list.php');
}


function leftitemt(obj)
{
  document.getElementById(obj.id+'s').style.display='';
}

function gotourl(to)
{
  window.location.replace(to);
}

function gotourl2(to)
{
  window.location=to;
}

//驗證
function ckvalue(num)
{
    re=/[0][9][0-9]{8}/g;
    if(!re.test(num)) return false;
    else return true;
}

//驗證
function CkValItem(val,num)
{
    switch(num)
    {
        case 'chinese':
            re = new RegExp(/^\W{1,}$/);
			ckstr=re.test(val);
            break;
        case 'mobile':
            re = new RegExp(/^[0][9][0-9]{8}$/);
			ckstr=re.test(val);
            break;
        default:
            ckstr=true;
            break;
    }
    return ckstr;
} 

