  /* even is unsupported in NS4! */
  function stringLen(Str){
	var StrLen = 0;
		for(var i=0;i<Str.length;i++){
			if(Str.charCodeAt(i)>=255){
				StrLen = StrLen + 2; 
			} 
			else{ 
				StrLen = StrLen + 1;
			}
	}
	return StrLen; 
	}
		
	function trim(inString)
	{
	   var l,i,g,t,r;
		//inString=Cstr(inString);
		l=inString.length;
		t=inString;
	   for(i=0;i<l;i++)
	   {
		   g=inString.substring(i,i+1);
		   if(g==" ")
		   {
			  t=inString.substring(i+1,l);
			}
		   else
		   {
			 break;;
		   }
		}
	   r=t;
	   l=t.length;
	   //Delete the spaces back
	   for(i=l;i>0;i--)
	   {
		  g=t.substring(i,i-1);
		  if(g==" ")
		  {
			r=t.substring(i-1,0);
		  }
		  else
		 {
			break;
		 }
	   }
	   return(r);
	}

 function CVal(theValue){
	  var checkOK = "0123456789-.";
	  var checkStr = trim(theValue);	  
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	 if ((checkStr.indexOf("..") !="-1")) {
	  		allValid = false;		 	
	  }
	  
	  for (i = 0;  i < checkStr.length;  i++)
	  {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		  if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}
		if (ch == ".")
		{
		  allNum += ".";
		  decPoints++;
		}
		else
		  allNum += ch;
	  }	  	  
	  return(allValid);
 }
 
 function CInt(theValue){
	  var checkOK = "0123456789";
	  var checkStr = theValue;	  
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	  for (i = 0;  i < checkStr.length;  i++)
	  {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		  if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}
		if (ch == ".")
		{
		  allNum += ".";
		  decPoints++;
		}
		else
		  allNum += ch;
	  }	  	  
	  return(allValid);
 }
 
 function IsTime(T){
	var StrLen = 0;
	var allValid = true;
	if (!CInt(T))
	{
		allValid = false;
		return(allValid);	
	}
	if (T.length!=4 ) 
	{
		allValid = false;
		return(allValid);		
	}
	
	if (T.substring(2,3)>'59')
	{
		allValid = false;
		return(allValid);
	}
	
	return(allValid);
	}
	
	function isEmail(sEmail) {
		if ((sEmail.value.indexOf("@") !="-1") && (sEmail.value.indexOf(".") !="-1")) {
			return(true);
		}else{ return(false);
		}
	}
	
	function numbersonly(){
		if (event.keyCode<48||event.keyCode>57)
			return false
	}
		
	MaxDot = new Number();
	function IsNumeric(e){
		onKeyup  =new String();
		s = new String();
		s = event.srcElement.value;
		rg = event.srcElement.createTextRange();
		rg.collapse(true);
		MaxDot = e;
		if (event.srcElement.onkeyup!=null) {
		   if (event.srcElement.onkeyup.toString().indexOf('CheckNegative()')<0) {
		      onKeyup = event.srcElement.onkeyup.toString().slice(event.srcElement.onkeyup.toString().indexOf('{')+1,event.srcElement.onkeyup.toString().lastIndexOf('}'));
		      event.srcElement.onkeyup = new Function('CheckNegative();'+onKeyup)
		   }    
		} else {
		   event.srcElement.onkeyup = new Function('CheckNegative();')
		}
		if (event.keyCode == 46 && s.indexOf('.') >= 0) {
		   event.keyCode = 0;
		}    
		if (event.keyCode == 45){
		   event.keyCode = 0;
		   if (s.charAt(0) != '-') {
		      event.srcElement.insertAdjacentText('AfterBegin','-');
		   }
		}    
		if (event.keyCode < 45 || event.keyCode > 57 || event.keyCode == 47) {
		   event.keyCode = 0;
		}
}


function CheckNegative() {
   s = new String();
   s= event.srcElement.value;
   if (s.indexOf('-') > 0) {
       rg = event.srcElement.createTextRange();
       rg.findText(s.slice(0,s.indexOf('-') + 1));
       rg.text = '-' + s.slice(0,s.indexOf('-'));
   }
   if (s.indexOf('.') >= 0 && s.length - s.indexOf('.') > MaxDot+1) {
       rg = event.srcElement.createTextRange();
       rg.moveStart("character",s.indexOf('.') + MaxDot+1);
       rg.text='';
   }
}


function IsUcaseE(){
  if (event.keyCode>=97&&event.keyCode<=122) { 
     event.keyCode=event.keyCode-32;
  } else if (event.keyCode<65||event.keyCode>90) {
     event.keyCode=0;
  }
}

function IsPlusNumeric(e){
		onKeyup  =new String();
		s = new String();
		s = event.srcElement.value;
		rg = event.srcElement.createTextRange();
		rg.collapse(true);
		MaxDot = e;		
		if (event.srcElement.onkeyup!=null) {
		   if (event.srcElement.onkeyup.toString().indexOf('CheckNegative()')<0) {
		      onKeyup = event.srcElement.onkeyup.toString().slice(event.srcElement.onkeyup.toString().indexOf('{')+1,event.srcElement.onkeyup.toString().lastIndexOf('}'));
		      event.srcElement.onkeyup = new Function('CheckNegative();'+onKeyup)
		   }    
		} else {
		   event.srcElement.onkeyup = new Function('CheckNegative();')
		}
		if (event.keyCode == 46 && s.indexOf('.') >= 0) {
		   event.keyCode = 0;
		}    
		if (event.keyCode == 45){
		   event.keyCode = 0;
		   /*if (s.charAt(0) != '-') {
		      event.srcElement.insertAdjacentText('AfterBegin','-');
		   }*/
		}    		
		if (event.keyCode < 45 || event.keyCode > 57 || event.keyCode == 47) {
		   event.keyCode = 0;
		}
	}

	function DateOnly(){
		if ((event.keyCode<48||event.keyCode>57) && (event.keyCode!=47))
			return false
	}
	
	function CheckDate(pObj,pShowMsg) 
	{ 
	    var lRet; 
	    lRet = gfcChkYMD(pObj.value,"A"); 
	    if (lRet.eErr) 
	    {if (pShowMsg){alert(lRet.eErrDesc);return false;}} 
	    else 
	    {pObj.value = lRet.eYMD;return true;} 
	} 

function gfcString(pStr,pLen,pCode)
{
    var tobjResult = new Object();
    var tStr = "";

    if (typeof(pStr) == "number") {   pStr = pStr.toString();}

    for(var ixI=0;ixI<pLen-pStr.length;ixI++)
    {
        tStr = tStr + pCode;
    }
    tobjResult.eLStr = tStr + pStr;
    tobjResult.eRStr = pStr + tStr;
    
    return tobjResult;
}
function gfcOpenCalendar(pDate,pDateType,pFixYear,pUrl)
{
    var tobjResult = new Object();

	tobjResult.eErr   = false;
	tobjResult.eDate  = ""; 
    tobjResult.eYear  = "";
    tobjResult.eMonth = "";
    tobjResult.eDay   = "";
    tobjResult.eCDate = "";
    tobjResult.eCYear = "";
    tobjResult.eCMonth= "";

	var lRet;
	lRet = gfcChkYMD(pDate,pDateType);
	if (lRet.eErr)
		pDate = '';
    
	tarParam = Array(pDate,pDateType,pFixYear);
    tPos     = "scrollbar=no;status=no;help=no;dialogWidth=230px;dialogHeight=185px;center=yes";
    tReturnValue = window.showModalDialog(pUrl,tarParam,tPos);
	if (typeof(tReturnValue)!="undefined")
	{
		tobjResult.eDate  = tReturnValue.eDate; 
		tobjResult.eYear  = tReturnValue.eYear;
		tobjResult.eMonth = tReturnValue.eMonth;
		tobjResult.eDay   = tReturnValue.eDay;
		tobjResult.eCDate = tReturnValue.eCDate;
		tobjResult.eCYear = tReturnValue.eCYear;
		tobjResult.eCMonth= tReturnValue.eCMonth;
	}
	else
	{
		tobjResult.eErr   = true;
	}
	return tobjResult;
}

function gfcChkYMD(pYMD,pType)
{
    var tPos,tY,tMM,tDD,tY1,tnY,tnM;
    var tobjResult = new Object();
    var tDate;

    tobjResult.eErr = false;
    tobjResult.eYMD = "";
    tobjResult.eErrDesc = "";

    if (typeof(pType) == "undefined") {   pType = "C";}

    if (pYMD == null)
    {
        tobjResult.eYMD = null;
        return tobjResult;
    }
    if (pYMD == "") 
    {
        tobjResult.eYMD = "";
        return tobjResult;
    }

    tPos = pYMD.indexOf("/");
    if (tPos == -1)
    {
      tPos = pYMD.indexOf("-");
      if (tPos == -1)
      {
        if ((pType == "C") || (pType == "c"))
        {
            if (pYMD.length != 6 && pYMD.length != 7)
            {
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(瞻瞻簞礙礎~) !";
                return tobjResult;
            }
            if (pYMD.length == 6)
            {   pYMD = "0" + pYMD;   }
            tY = pYMD.substring(0,3);
            tMM = pYMD.substring(3,5);
            tDD = pYMD.substring(5,7);
        }
        else
        {
            if (pYMD.length != 8) 
            {
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(礎癡瞻繡礎~) !";
                return tobjResult;
            }        
            tY = pYMD.substring(0,4);
            tMM = pYMD.substring(4,6);
            tDD = pYMD.substring(6,8);
        }
      }
      else
      {
        if ((pType == "C") || (pType == "c"))
        {
            if (tPos > 3)
            {   
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(瞻瞻簞礙礎~) !";
                return tobjResult;
            }
        }
        else
        {
            if (tPos > 4)
            {   
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(礎癡瞻繡礎~) !";
                return tobjResult;
            }
        }
        tY = pYMD.substring(0,tPos)
        pYMD = pYMD.substring(tPos + 1);
        tPos = pYMD.indexOf("-");
        tMM = pYMD.substring(0, tPos);
        tDD = pYMD.substring(tPos + 1);
        if (tMM.length == 1) {   tMM = "0" + tMM;}
        if (tDD.length == 1) {   tDD = "0" + tDD;}
      }
    }
    else
    {
        if ((pType == "C") || (pType == "c"))
        {
            if (tPos > 3)
            {   
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(瞻瞻簞礙礎~) !";
                return tobjResult;
            }
        }
        else
        {
            if (tPos > 4)
            {   
                tobjResult.eErr = true;
                tobjResult.eYMD = "";
                tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(礎癡瞻繡礎~) !";
                return tobjResult;
            }
        }
        tY = pYMD.substring(0,tPos)
        pYMD = pYMD.substring(tPos + 1);
        tPos = pYMD.indexOf("/");
        tMM = pYMD.substring(0, tPos);
        tDD = pYMD.substring(tPos + 1);
        if (tMM.length == 1) {   tMM = "0" + tMM;}
        if (tDD.length == 1) {   tDD = "0" + tDD;}
    }

    if ((isNaN(tY)) || (isNaN(tMM)) || (isNaN(tDD)) || (tMM.length > 2) || (tDD.length > 2))
    {
        tobjResult.eErr = true;
        tobjResult.eYMD     = "";
        if ((pType == "C") || (pType == "c"))
        {   tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(瞻瞻簞礙礎~) !";}
        else
        {   tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(礎癡瞻繡礎~) !";}
        return tobjResult;
    }

    if ((pType == "C") || (pType == "c"))
    {   tY1 = parseInt(tY,10) + 1911;}
    else
    {   tY1 = parseInt(tY,10);}

    tDate = new Date(tY1,tMM-1,tDD);
    tnY = tDate.getFullYear();
    tnM = tDate.getMonth() + 1;
    if ((tY1 != tnY) || (tMM != tnM))
    {   
        tobjResult.eErr = true;
        tobjResult.eYMD     = "";
        if ((pType == "C") || (pType == "c"))
        {   tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(瞻瞻簞礙礎~) !";}
        else
        {   tobjResult.eErrDesc = "瞻矇織?簧疆礎癒聶矇瞻J聶羅罈~(礎癡瞻繡礎~) !";}
        return tobjResult;
    }

    if ((pType == "C") || (pType == "c"))
    {   tY = gfcString(tY,3,"0").eLStr;}
    else
    {   tY = gfcString(tY,4,"0").eLStr;}

    tobjResult.eYMD = tY + "/" + tMM + "/" + tDD;
    return tobjResult;
}

function Calendar(pObj) 
{ 
    var lRet; 
    lRet = gfcOpenCalendar(trim(pObj.value),"A",false,'/function/calendar.html'); 
    if (lRet.eDate!='') 
    {pObj.value = lRet.eDate;} 
} 

 function IsTimeF(T){		//判斷時間格式正確與否(24小時)
	var StrLen = 0;
	var allValid = true;
	if (!CInt(T))
	{
		allValid = false;
		return(allValid);	
	}
	if (T.length!=4 ) 
	{
		allValid = false;
		return(allValid);		
	}
	if (T.substring(0,2)>'23')
	{
		allValid = false;
		return(allValid);
	}
	if (T.substring(2,3)>'59')
	{
		allValid = false;
		return(allValid);
	}
	
	return(allValid);
	}

	function TimeOnly(){
            var agt = navigator.userAgent.toLowerCase();
            if (agt.indexOf("msie") != -1) {
		if (event.keyCode<48||event.keyCode>57)
			return false
            }
	}

	function NumberOnly(){
            var agt = navigator.userAgent.toLowerCase();
            if (agt.indexOf("msie") != -1) {
		if ((event.keyCode<48||event.keyCode>57)
		    && event.keyCode != 45 && event.keyCode != 46)
			return false
            }
	}

function checkDelete () {
    var a = (document.getElementsByName('ListDelete'));
    var str = '';
    for (i=0; i < a.length; i++) {
	if (a[i].checked) { return true; }
    }
    return false;
}

// To confirm archives deletion
function dbl_confirm(my_form, my_message,my_message2) {
    
    if (confirm(my_message)) 
    {
	if (confirm(my_message2)) 
	{
	    my_form.zip.value = "1";
	}
	}else{
    return false;
    }
}	

// To confirm a form submition
function request_confirm(my_form, my_message, my_action) {
if (window.confirm(my_message)) {
    my_form.action.value = my_action;
    my_form.submit();
}
}

// To confirm on a link (A HREF)
function request_confirm_link(my_url, my_message) {
question = confirm(my_message);
if (question !="0") {
	top.location = my_url;
}
}

// To confirm on a link (A HREF)
function refresh_mom_and_die() {
url = window.opener.location.href;

if (url.indexOf('logout') > -1 ) {
    url = '/wws/';
}

window.opener.location = url;
self.close();
}


function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) 
	return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break; 
    }
    return null;
}  

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
    endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function check_cookie() {

    if (GetCookie('sympauser') == null) {
    alert("Sympa could not set a cookie for login.\n Your should setup your navigator to accept cookies");
    }
}


function toggle_selection(myfield) {
for (i = 0; i < myfield.length; i++) {

    if (myfield[i].checked) {
	myfield[i].checked = false;
    }else {
	myfield[i].checked = true;
    }

}
}
function  chkDescp(){
//檢查該網頁是否所有的必填欄位<input>都填了
	event.returnValue=false;
	var chkArrayObj=document.getElementsByTagName("input");
	for( var i=0;i<chkArrayObj.length;i++){
		if(chkArrayObj[i].SHV=='1' && chkArrayObj[i].value==''){
		//if(chkArrayObj[i].SHV=='1'){
			alert("必填欄位："+chkArrayObj[i].descp+"，尚未填寫。");
			chkArrayObj[i].focus();
			return false;
		}
	}

//檢查該網頁是否所有的必填欄位<select>都填了

	chkArrayObj=document.getElementsByTagName("select");
	for( var i=0;i<chkArrayObj.length;i++){
		
		if(chkArrayObj[i].SHV=='1' && chkArrayObj[i].value==''){
		//if(chkArrayObj[i].SHV=='1'){
			alert("必填選項："+chkArrayObj[i].descp+"，尚未選擇。");
			chkArrayObj[i].focus();
			return false;
		}
	}
	return true;
}
function AddMoreEntry_Access(actionObj){
	var tableObj=actionObj.parentNode.parentNode.parentNode.parentNode; //找到所屬【處理】button之table
	var chktmpArray=new Array();
	var InputArray=tableObj.getElementsByTagName("input");

	//把tableObj中Chk的obj 抓出來。	
	chkArray= new Array();
	
	for(var i=0;i<InputArray.length;i++){
		if(InputArray[i].name=="DeleteEntry"){
			chkArray.push(InputArray[i]);
		}
	}
	var del=false;
	for(var i=chkArray.length-1;i>=0;i--){
		if(chkArray[i].checked==true){
		del=true;
			if(tableObj.lastChild.lastChild==chkArray[i].parentNode.parentNode){
				if(tableObj.lastChild.lastChild==tableObj.lastChild.childNodes[0]){
					var TRInputArray1=chkArray[i].parentNode.parentNode.getElementsByTagName("input");
					for(var p=0;p<TRInputArray1.length;p++){
						TRInputArray1[p].value=TRInputArray1[p].defaultValue;
						TRInputArray1[p].checked=TRInputArray1[p].DefaultChecked;
					}
				}else{
					chktmpArray=new Array();
					
					var TRInputArray1=chkArray[i].parentNode.parentNode.getElementsByTagName("input");
					var TRInputArray2=chkArray[i-1].parentNode.parentNode.getElementsByTagName("input");
					for(var p=0;p<TRInputArray2.length;p++){
						TRInputArray1[p].value=TRInputArray2[p].value;
						if(TRInputArray2[p].type=="checkbox"){
							chktmpArray.push(TRInputArray2[p].checked);
						}
					}
					var TRInputArray1=chkArray[i].parentNode.parentNode.getElementsByTagName("select");
					var TRInputArray2=chkArray[i-1].parentNode.parentNode.getElementsByTagName("select");
					for(var p=0;p<TRInputArray2.length;p++){
						TRInputArray1[p].value=TRInputArray2[p].value;
						if(TRInputArray2[p].type=="checkbox"){
							chktmpArray.push(TRInputArray2[p].checked);
						}
					}
				        tableObj.lastChild.lastChild.swapNode(chkArray[i-1].parentNode.parentNode);
					var tempchkArray=chkArray[i];
					chkArray[i]=chkArray[i-1];
					chkArray[i-1]=tempchkArray;

				
					chkArray[i].parentNode.parentNode.removeNode(true);
					
					TRInputArray2=chkArray[i-1].parentNode.parentNode.getElementsByTagName("input");
					var j=0;
					for(var p=0;p<TRInputArray2.length;p++){
						if(TRInputArray2[p].type=="checkbox"){
							TRInputArray2[p].checked=chktmpArray[j];
							j=j+1;
						}
						
					}
				}
			}else{
				chkArray[i].parentNode.parentNode.removeNode(true);
			}
		}
	}
        document.getElementById('Content').focus();
	if(del==false){
		for(var i=1;i<=AddMoreEntry_No;i++){
			copyNode(tableObj.lastChild,tableObj.lastChild.lastChild);
		}
	}
	AddMoreEntry_fsh(actionObj);
}
var AddMoreEntry_No=1; //多筆欄位時，預設加的筆數
function copyNode(objNode,CPobjNode){
	var Rtr=CPobjNode; //原來的<tr>
	var tempNode=CPobjNode.cloneNode(true);
	tempNode.lastChild.lastChild.removeNode(true);// delete 原來<tr>的處理<input>
	objNode.appendChild(tempNode);	


	
	var chkArrayObj=Rtr.getElementsByTagName("input");
	var tmptrueArray=new Array();
	var newArrayObj=tempNode.getElementsByTagName("input");
	for(var i=0; i<newArrayObj.length;i++){
		if(chkArrayObj[i].type=="checkbox"){
			tmptrueArray.push(chkArrayObj[i].checked);
			chkArrayObj[i].checked=chkArrayObj[i].defaultChecked;
		}
		chkArrayObj[i].value=chkArrayObj[i].defaultValue;
	}
	chkArrayObj=Rtr.getElementsByTagName("select");
	newArrayObj=tempNode.getElementsByTagName("select");
	for(var i=0; i<newArrayObj.length;i++){
		newArrayObj[i].value=chkArrayObj[i].value;
		chkArrayObj[i].value=chkArrayObj[i].defaultValue;
	}
	tempNode.swapNode(Rtr);
	chkArrayObj=tempNode.getElementsByTagName("input");
	var j=0;
	for(var i=0; i<chkArrayObj.length;i++){
 	  if(chkArrayObj[i].type=="checkbox"){
		chkArrayObj[i].checked=tmptrueArray[j];
		j++;
	  }
	}
}

/*
window.document.onkeydown=function(){
	var agt = navigator.userAgent.toLowerCase();
	if (agt.indexOf("msie") != -1) {
	    if (event.keyCode==13){
		event.returnValue=false;
	    }
	}
}
*/

function AddMoreEntry_ByTime(tableIndex,times){
	var tableObj=document.getElementsByName("EntryTable");
	for(var i=1;i<=times;i++){
		alert(tableObj.name);
		copyNode(tableObj[tableIndex].lastChild,tableObj[tableIndex].lastChild.lastChild);
	}
}
function AddMoreEntry_fsh(actionObj){
}

