<!--

var GoodChr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var NumChr = "0123456789";
var BadChr = "'\"+";

//****************************************************************************************************//

function isGoodId(input, length1, length2) {
  if (input.length < length1 || input.length > length2 || !isGoodChr(input) || isBadChr(input)) {
  // if (!isGoodChr(input) || isBadChr(input)) {
    return false;
  }

  return true;
}

//****************************************************************************************************//

// Use this function to retrieve a cookie.
function getCookie(name) {
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
      }
  }
  return null;
}

//****************************************************************************************************//

// Use this function to save a cookie.
function setCookie(name, value, expires) {
  document.cookie = name + "=" + escape(value) + "; path=/" +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

//****************************************************************************************************//

// Use this function to delete a cookie.
function delCookie(name) {
  document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

function chkBrowser() {
  var bName = navigator.appName;
  var bVer = parseInt(navigator.appVersion);

  if (bName == "Netscape" && bVer >= 4) br = "n4";		// Netscape 4.x
  else if (bName == "Netscape" && bVer == 3) br = "n3";		// Netscape 3.x
  else if (bName == "Netscape" && bVer == 2) br = "n2";		// Netscape 2.x
  else if (bName == "Microsoft Internet Explorer" && bVer >= 4) br = "e4";		// IE 4.x or newer
  else if (bName == "Microsoft Internet Explorer") br = "e3";		// IE 3.x
  else br = "n2";		// if none of these are found, default to Netscape 2

  return br;
}

//****************************************************************************************************//

function varIsNull(value) {
  return (value==null || value=="") ? true : false;
}


//****************************************************************************************************//

function isROCIdentNo(s) {
	var c, n, i;
	var t = "ABCDEFGHJKLMNPQRSTUVXYWZIO";

	c = s.substring(0,1);
	c = t.indexOf(c.toUpperCase());
	if ((s.length != 10) || (c < 0)) return false;

	n = parseInt(c/10) + c%10*9 + 1;
	for (i = 1; i<9; i++) n = n + parseInt(s.substring(i, i+1)) * (9-i);
	n = (10 - (n % 10)) % 10;
	if (n != parseInt(s.substring(9, 10))) return false;

	return true;
}

//****************************************************************************************************//

function isForeIdentNo(s) {
	var c, c1, c2, c3, n, i;
	var t = "ABCDEFGHJKLMNPQRSTUVXYWZIO";

	c = s.substring(8,9);
	c = t.indexOf(c.toUpperCase());
	if ((s.length != 10) || (c < 0)) return false;

	c = s.substring(9,10);
	c = t.indexOf(c.toUpperCase());
	if ((s.length != 10) || (c < 0)) return false;

	c1 = s.substring(0,4);
	c2 = s.substring(4,6);
	c3 = s.substring(6,8);
	if (!isTrueYear(c1, -15, -100)) return false;
	if (!isTrueDay(c1, c2, c3)) return false;

	return true;
}

//****************************************************************************************************//

function isCorpNo(value) {
  if (value.length != 8) return false;
  if (!isNumChr(value)) return false;

  return true;
}

//****************************************************************************************************//

function isTrueYear(value, upline, downline) {

  if (isNaN(value)) return false;
  if (!isNumChr(value)) return false;

  var d = new Date();
  var nowYear = d.getFullYear();
  if (value > (nowYear + upline) || value < (nowYear + downline)) return false;

  return true;
}

//****************************************************************************************************//

function isTrueDay(year, month, day) {
  var m1 = "01, 03, 05, 07, 08, 10, 12";
  var m2 = "04, 06, 09, 11";
  var m3 = "02";

  if (m2.indexOf(month) != -1 && day == "31") return false;
  if (month == m3) {
    if (year % 4 == 0) {
      if (day == "30" || day == "31") return false;
    }
    else {
      if (day == "29" || day == "30" || day == "31") return false;
    }
  }

  return true;
}

//****************************************************************************************************//

function isUrl(value) {
  if (value.indexOf("http://") == -1) {
    value = "http://" + value;
  }
  if (value.indexOf(".") == -1) return false;
  if (isBadChr(value)) return false;

  return true;
}

//****************************************************************************************************//

function isMail(email) {
  if (email.length < 5) { return false; }
  if (email.indexOf("@") == -1) { return false; }
  if (email.indexOf(".") == -1) { return false; }

  return true;
}

//****************************************************************************************************//

function isGoodChr(value) {
	if (value.length < 4){
		return false;
	}
  for (var i = 0; i < value.length; i++) {
    if (GoodChr.indexOf(value.charAt(i)) == -1) {
      return false;
    }
  }

  return true;
}

//****************************************************************************************************//

function isNumChr(value) {
  for (var i = 0; i < value.length; i++) {
    if (NumChr.indexOf(value.charAt(i)) == -1) {
      return false;
    }
  }

  return true;
}

//****************************************************************************************************//

function isBadChr(value) {
  for (var i = 0; i < value.length; i++) {
    if (BadChr.indexOf(value.charAt(i)) != -1) {
      return true;
    }
  }

  return false;
}

//****************************************************************************************************//

function go(url) {
  window.location.href = url;
}

//****************************************************************************************************//

function setBgColor(obj, color) {
  obj.style.backgroundColor = color;
}

//****************************************************************************************************//

function setColor(obj, color) {
  obj.style.color = color;
}

//****************************************************************************************************//

function setVisible(obj, status) {
  if (status) {
    obj.style.visibility = "";
  }
  else {
    obj.style.visibility = "hidden";
  }
}

//****************************************************************************************************//

function setImgSrc(obj, src) {
  obj.src = src;
}

//****************************************************************************************************//

function ChangeOptions(objMaster, objSlave, newArray, keyVal) {

  var keyInd  = objMaster.options[objMaster.selectedIndex].value;

  for (var i = objSlave.options.length - 1; i >= 0 ; i--) {
    objSlave.options[i] = null;
  }

  var ind = 0;
  for (var i = 0; i < newArray.length; i++) {
    if (newArray[i][0] == keyInd) {
      objSlave.options[ind] = new Option(newArray[i][2], newArray[i][1]);
      if (keyVal == newArray[i][1]) objSlave.selectedIndex = ind;
      ind++;
    }
  }

}

//****************************************************************************************************//

function chkField(isBad, obj, msg) {
  if (isBad) {
    alert(msg);
    obj.focus();
    return false;
  }

  return true;
}

//****************************************************************************************************//

function goConfirm(msg, url) {
  if (window.confirm(msg)) {
    go(url);
  }
}

//****************************************************************************************************//

function openWindow(url, target, style, moveX, moveY) {
  var theWin = window.open(url, target, style);
  theWin.moveTo(moveX, moveY);
  theWin.focus();
}

//****************************************************************************************************//

function openConfirm(msg, url, target, style, moveX, moveY) {
  if (!varIsNull(msg)) {
    if (window.confirm(msg)) {
      openWindow(url, target, style, moveX, moveY);
    }
  }
  else {
    openWindow(url, target, style, moveX, moveY);
  }
}

//****************************************************************************************************//

function stripslashes(value) {
  var retval = value;

  while (retval.indexOf("\\") != -1) {
    retval = retval.substring(0, retval.indexOf("\\")) + retval.substring(retval.indexOf("\\") + 1, retval.length);
  }

  return retval;
}

//****************************************************************************************************//

function setCheckWord(cnum,cwval) {
	if (document.getElementById(cwval).value == cnum && document.getElementById("account").value != "" && document.getElementById("passwd").value != ""){
		//window.location.href = "main.php?fid=09&page_name=users_login&user_id=" + document.getElementById("account").value + "&passwd=" + document.getElementById("passwd").value + "&action=login";
		document.getElementById("form1").submit();
	}else{
	    if (document.getElementById("account").value == ""){
			alert("請輸入帳號!");
			document.getElementById("account").focus();
            return false;
		}
		else if (document.getElementById("passwd").value == ""){
			alert("請輸入密碼!");
			document.getElementById("passwd").focus();
            return false;
		}
		else if (document.getElementById(cwval).value == ""){
			alert("請輸入驗證碼!!!");
			document.getElementById(cwval).focus();
            return false;
		}else{
			alert("輸入的驗證碼錯誤!!!");
			document.getElementById(cwval).focus();
            return false;
		}
	}
}

//****************************************************************************************************//

function setCheckWordt(cnum,cwval) {
	if (document.getElementById(cwval).value == cnum && document.getElementById("taccount").value != "" && document.getElementById("tpasswd").value != ""){
		window.location.href = "main.php?fid=09&page_name=users_login&user_id=" + document.getElementById("taccount").value + "&passwd=" + document.getElementById("tpasswd").value + "&action=login";
		//document.getElementById("form1").submit();
		return false;
	}else{
	    if (document.getElementById("taccount").value == ""){
			alert("請輸入帳號!");
			document.getElementById("taccount").focus();
			return false;
		}
		else if (document.getElementById("tpasswd").value == ""){
			alert("請輸入密碼!");
			document.getElementById("tpasswd").focus();
            return false;
		}
		else if (document.getElementById(cwval).value == ""){
			alert("請輸入驗證碼!!!");
			document.getElementById(cwval).focus();
            return false;
		}else{
			alert("輸入的驗證碼錯誤!!!");
			document.getElementById(cwval).focus();
            return false;
		}
	}
}

//****************************************************************************************************//

function addBookmarkForBrowser() {
	var weburl = "http://" + String(self.location).split("/")[2];
	var webName = "作文薄落";

	if (document.all){
		window.external.AddFavorite(weburl, webName);
	} else {
		window.sidebar.addPanel(webName, weburl, "");
	}
}

//****************************************************************************************************//

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//****************************************************************************************************//

function chkAttendForm(){
	var chkId = document.getElementById("id");
	var logchk = document.getElementById("loginCheck");
	var chkNextId = document.getElementById("chkNextId");

	if (chkId.value == chkNextId.value){
		document.getElementById('form1').submit();
	}else{
		switch(chkNextId.value){
			case "a":
                var remesg = "請先完成備課課程,才能進行本課程進度!!!";
				break;
			case "b":
                var remesg ="請先完成前一課備課課程,才能進行本備課課程進度!!!";
				break;
			case "c":
                var remesg = "請先完成前一課的課程,才能進行本備課課程進度!!!";
				break;
			default:
				var remesg = "請先完成備課課程才能進行本課程!";
				break;
		}
		//var remesg = (chkNextId.value == 0 && logchk.value == 1 && $chkId == 1) ? "請先完成備課課程,才能進行本課程進度!!!" : "請先完成前一課課程才能進行本課程!";
		alert(remesg);
		return false;
	}
}

//****************************************************************************************************//

//-->