﻿function go(obj) {
    var today = new Date();
    var timer = today.getTime();
    var requestURL = obj.href + '&timer=' + timer;
    location.href(requestURL);
    return false;    
}    
function getExtension(str) {
    if(str.lastIndexOf('.') != -1 && str.length - str.lastIndexOf('.') <= 5) {
	    return str.substr(str.lastIndexOf('.') + 1);
    }
	else {
	    return '';
	}
}
function checkNumPlus(obj,txtAlert) {
    for(z=0; z<obj.value.length;z++) {
        c = obj.value.charAt(z);
        if("0123456789".indexOf(c,0) < 0) {   
            window.alert(txtAlert);
            obj.select();
            return false;
        } 
    }    
    return true;
}
function checkNullPlus(obj,txtAlert) {
  if(obj.type == 'text') { 
    if(obj.value == '') {
      alert(txtAlert);
      obj.focus();
      return false;}
    else {
      return true;} 
  }    
  else if(obj.type == 'select-one') {
    if(obj.options[obj.selectedIndex].value == '') {
      alert(txtAlert);
      obj.focus();
      return false;}
    else {
      return true;} 
  }  
  else if(obj.type == 'textarea') { 
    if(obj.value == '') {
      alert(txtAlert);
      obj.focus();
      return false;}
    else {
      return true;} 
  }    
}
function selectType(obj) {
    if(obj.options[obj.selectedIndex].value == '0') {
        document.getElementById('Url').value='';
        document.getElementById('Description').value='';
        document.getElementById('Url').style.display='none';
        document.getElementById('editor').style.display='';
    } 
    else {
        document.getElementById('Url').value='';
        document.getElementById('Description').value='';
        document.getElementById('Url').style.display='';
        document.getElementById('editor').style.display='none';
    }
}

var isSelect = false;
function selectAll(obj) {
    if(isSelect == false) {
        objform = document.forms[0];
        for(i=0;i<=objform.elements.length-1;i++) {
            if(objform.elements[i].type == 'checkbox') {
                objform.elements[i].checked = true;
            }
        }
        isSelect = true;
        obj.innerText = '全不選';
    }    
    else {    
        objform = document.forms[0];
        for(i=0;i<=objform.elements.length-1;i++) {
            if(objform.elements[i].type == 'checkbox') {
                objform.elements[i].checked = false;
            }
        }
        isSelect = false;
        obj.innerText = '全選';
    }
}
function checkNull(obj) {
  if(obj.type == 'text') { 
    if(obj.value == '') {
      alert('您有欄位未填寫');
      obj.focus();
      return false;}
    else {
      return true;} 
  }    
  else if(obj.type == 'select-one') {
    if(obj.options[obj.selectedIndex].value == '') {
      alert('您有欄位未填寫');
      obj.focus();
      return false;}
    else {
      return true;} 
  }  
  else if(obj.type == 'textarea') { 
    if(obj.value == '') {
      alert('您有欄位未填寫');
      obj.focus();
      return false;}
    else {
      return true;} 
  }    
}
function checkEmail(obj) {
    var strEmail = obj.value;
    check = /.+@.+\..+/;
    if(strEmail != '' && !strEmail.match(check)) {
        alert('Email 格式不正確');
        obj.focus();
        return false;
    }
    else {
        return true;
         //checkEmail = true;}
  }
}
function checkEmailPlus(obj,txtAlert) {
	var strEmail = obj.value;
	check = /.+@.+\..+/;
    if(strEmail != '' && !strEmail.match(check)) {
        alert(txtAlert);
		obj.focus();
		return false;
	}
	else {
		return true;
		 //checkEmail = true;}
  }
}
function checkNum(obj) {
    for(z=0; z<obj.value.length;z++) {
        c = obj.value.charAt(z);
        if("0123456789".indexOf(c,0) < 0) {   
            window.alert('此欄位必需為數字');
            obj.select();
            return false;
        } 
    }    
    return true;
}
function checkBeforeDelete() {
    objform = document.forms[0];
    iTotal = 0;
    for(i=0;i<=objform.elements.length-1;i++) {
        if(objform.elements[i].type == 'checkbox' && objform.elements[i].name.search('dg') == 0) {
            if(objform.elements[i].checked == true) {
                iTotal++;
            }    
        }
    }
    if(iTotal == 0) {
        alert('您尚未選擇任何項目');
        return false;
    }
    else {
        if(!confirm('您確定要將所選的項目刪除嗎?')) {
            return false;            
        }
    }
}
function checkBeforeDelete() {
    objform = document.forms[0];
    iTotal = 0;
    for(i=0;i<=objform.elements.length-1;i++) {
        if(objform.elements[i].type == 'checkbox' && objform.elements[i].name.search('dg') == 0) {
            if(objform.elements[i].checked == true) {
                iTotal++;
            }    
        }
    }
    if(iTotal == 0) {
        alert('您尚未選擇任何項目');
        return false;
    }
    else {
        if(!confirm('您確定要將所選的項目刪除嗎?')) {
            return false;            
        }
    }
}
function checkBeforeDelete() {
    objform = document.forms[0];
    iTotal = 0;
    for(i=0;i<=objform.elements.length-1;i++) {
        if(objform.elements[i].type == 'checkbox' && objform.elements[i].name.search('dg') == 0) {
            if(objform.elements[i].checked == true) {
                iTotal++;
            }    
        }
    }
    if(iTotal == 0) {
        alert('您尚未選擇任何項目');
        return false;
    }
    else {
        if(!confirm('您確定要將所選的項目刪除嗎?')) {
            return false;            
        }
    }
}
function checkBeforeUpdate() {
    objform = document.forms[0];
    iTotal = 0;
    for(i=0;i<=objform.elements.length-1;i++) {
        if(objform.elements[i].type == 'checkbox' && objform.elements[i].name.search('dg') == 0) {
            if(objform.elements[i].checked == true) {
                iTotal++;
            }    
        }
    }
    if(iTotal == 0) {
        alert('您尚未選擇任何項目');
        return false;
    }
    else {
        if(!confirm('您確定要將所選的項目更新嗎?')) {
            return false;            
        }
    }
}
function disableForm(objform) {
   var objFormElements = objform.elements;     
   for (i=0;i<objFormElements.length;i++){
       objFormElements[i].disabled = true;
   }       
}
function toggle(obj){
  ourParent = obj.parentNode.parentNode;
  if (obj.parentNode.parentNode.childNodes[1].style.display == "none"){
      ourParent.childNodes[0].style.display ='';
      ourParent.childNodes[1].style.display ='';
      ourParent.childNodes[2].style.display =''; 
      obj.className = 'toggle';
  } 
  else {
      ourParent.childNodes[0].style.display ='';
      ourParent.childNodes[1].style.display ='none';
      ourParent.childNodes[2].style.display ='none'; 
      obj.className = 'toggle2';
  } 
}
function toggleClose(obj){
    ourParent = obj.parentNode.parentNode;
    ourParent.childNodes[0].style.display ='';
    ourParent.childNodes[1].style.display ='none';
    ourParent.childNodes[2].style.display ='none'; 
    obj.className = 'toggle2';
}
function checkRadio(obj) {
    var checked = 0;
    for(i=0;i<=obj.length-1;i++) {
        if(obj[i].checked == true) {
            checked = 1;
        }
    }
    if(checked == 0) {
        alert('您有欄位未選擇');
    return false;
    }
    else {
        return true;
    }
}
function checkRadioPlus(obj,txtAlert) {
    var checked = 0;
    for(i=0;i<=obj.length-1;i++) {
        if(obj[i].checked == true) {
            checked = 1;
        }
    }
    if(checked == 0) {
        alert(txtAlert);
	return false;
    }
    else {
        return true;
    }
}