<!--

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

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

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 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 setListul(tableName){
	if (tableName == undefined){
        timeUls = setTimeout('setListulo()', 3000);
	}else{
		clearTimeout(timeUls);
        setListulo()
		document.getElementById(tableName).style.display = 'block';
	}
}

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

function setListulo(){
	var tableAry = new Array('item_1', 'item_2', 'item_3', 'item_4');

	for (var x = 0;x < tableAry.length;x++){
		document.getElementById(tableAry[x]).style.display = 'none';
	}
}

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

function chkPicNumber(chkWord){
	if (document.getElementById(chkWord).value.length == 4){
		document.getElementById('pnSet').value = 'CHECK';
		var cpnAjax = new ajax();
		cpnAjax.top_listCase(2,"/includes/setDivs.php","cpnText", document.getElementById(chkWord).value);
	}
}

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

function setCpnNum(cpn){
    document.getElementById('pnSet').value = cpn;
	if (cpn == "Y"){
        document.getElementById('cpnText').innerHTML = "<img src='/images/ok.gif' alt='驗證成功' title='驗證成功...'>";
	}
	else if (cpn == "N"){
        document.getElementById('cpnText').innerHTML = "<img src='/images/error.gif' alt='驗證失敗' title='驗證失敗...'>";
	}
}

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

userPowerEbook = {
	erabare : [],
	erabNum : 5,
	objDiv: null,
	obj : null,
	cobjName : null,
	chkNums: false,

	setDataList : function(chkName, erabpurs, chkNumber, erabNumber){           //checkbox名稱,記錄用的欄位名稱,是否要檢查,設定最大值
		this.cobjName = chkName;												//設定檢查用的checkbox
		this.objDiv = document.getElementById(erabpurs);
		this.obj = document.getElementsByTagName('input');						//取得input物件群
		if (erabNumber != undefined){											//當有輸入erabNumber值時,更新erabNum
			this.erabNum = erabNumber;
		}
		if (chkNumber){															//設定是否檢查最大設定數
			this.chkNums = chkNumber;
		}
		this.getCheckboxNum();													//執行預設程式
	},

	getCheckboxNum : function(){
		for (var x = 0;x < this.obj.length;x++){								//取得所有input的物件
			if (this.obj[x].id == this.cobjName){								//只取出要的checkbox
                this.obj[x].onclick = function(){								//設定點選時執行判斷式
					userPowerEbook.chkSelectObj(this);
				}
				if (this.obj[x].checked){                                       //取出有點選的值
					this.erabare.push(this.obj[x].value);
				}
			}
		}
	},

	chkSelectObj : function(purObj){
		if (this.chkNums){                                                      //是否要檢查最大值
			if (this.erabare.length <= this.erabNum){							//檢查是否超過最大值
				if (purObj.checked){                                            //是點選還是取消
					this.erabare.push(purObj.value);                            //將點選的加入陣列
					if (this.erabare.length > this.erabNum){                    //如果最後的值大於最大值
						this.erabare = this.objDiv.value.split(',');            //還原最後的結果
						purObj.checked = false;                                 //取消現在點選的值
						alert('最大可設定權限數為' + this.erabNum + '次!');     //顯示警告
					}
				}else{
					this.erabare = [];                                          //如果是取消點選的話,重設陣列值(歸零)
					this.getCheckboxNum();                                      //重新取得現有的勾選值
				}
				this.objDiv.value = this.erabare.toString();                    //最後將結果傳送到指定欄位
			}else{
				alert('最大可設定權限數為' + this.erabNum + '次!');
			}
		}else{
            if (purObj.checked){
				this.erabare.push(purObj.value);
			}else{
				this.erabare = [];
				this.getCheckboxNum();
			}
            this.objDiv.value = this.erabare.toString();
		}
	}
}

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

//-->
