﻿// JavaScript Document


function checknull(a, str){
	if(a.value==''){
		alert(str);
		a.focus();
		return false;
	}else{
//		alert(a.text);
//		if(a.value.indexOf("'")>-1){
//			a.focus();
//			alert("不能輸入'此符號！");
//			return false;
//		}
		return true;
	}
}



//檢查電郵
function checkemail(a, str){
	if(checknull(a, str)){
		return true;
		if(vaildemail(a, '電郵地址不正確！')){
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
}

function vaildemail(a, str){
	var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(a.value)){
		return true;
	}else{
		alert(str);
		a.focus();
		return false;
	}
}
//打開新視窗
	function showwindow(aurl, atitle){
		var awidth=screen.width;
		var aheight=screen.height;
	window.open(aurl, atitle, 'height='+aheight+', width='+awidth+', top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=yes, status=no');
	
	}

	
function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}



	
function isNum(N){

var numtype="0123456789";

  for(var i=0;i<N.length;i++){ //檢討是否有不在 0123456789之內的字
    if(numtype.indexOf(N.substring(i,i+1))<0){
		return false ;//是的話....結束迴圈;傳回false
	}
  }

		return true;
} 

function checknum(a, str){
		if(isNaN(a.value)){
			alert(str);
			a.focus();
		return true;
	}else{
		return false;
	}
	
}


function delfile(a)
{
	var x=0;
   	var b = $("input");

	for(var i=0; i<b.length; i++){
		if(b[i].type=="checkbox"){
			if(b[i].name==a){
				if(b[i].checked==true){
				x=x+1;
				}
			}
		}
	}
	if(x==0){
	alert("請選擇你要刪除的資料！");
	return false;
	}else{
		if(confirm('確認刪除嗎？')){
		return true;
		}else{
		return false;
		}
	}
}

function selectall(b, c){

   var a = document.getElementsByName(c);
	for (var i=0; i<a.length; i++){
		a[i].checked = b;
	}
}

	
function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}




