function isAlphabetic(str)
{
  var len= str.length;
  var p=0;
  var ok= false;
  var ch= "";
  while (p<len)
  {
    ch= str.charAt(p);
    if ( ('A'<=ch && ch<='Z') || ('a'<=ch && ch<='z') )
    {
        ok= true;
        break;
    }
    else
        p++;

  }
  return ok;
}



function isDate (day,month,year) {
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false
}// end function isDate()
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function checkNo(telNo, digit)
{
        var result=false; // false = not a telephone number, true = a telephone number
// isNaN() is going to check input value is Not a Number or not, but it's fail to check if the input is space
//or it is fail to check if there are some spaces included inside the number
        if(telNo.length!= digit || isNaN(telNo) == true){
                result = false;
        }
        else
        {
                result = true;
        }

        return result;
}// end of function checkNo


function repalceSpecialChar(input_value)
{
        var newString = "";
        for(var i=0;i<input_value.length;i++)
        {
                if(input_value.charAt(i) == "'")
                {
                        //newString += "&acute;" ;
                        newString += "&#39;" ;
                }
                else if(input_value.charAt(i) == "\"")
                {
                        newString += "&quot;" ;
                }
                else
                {
                        newString += input_value.charAt(i)  ;
                }
        }

        return newString;
}



function emailCheck(emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */


return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {

return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {

return false;
   }
}

// See if "user" is valid

if (user.match(userPat)==null) {

// user is not valid


return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {

return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {


return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {

return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {

return false;
}

// If we've gotten this far, everything's valid!
return true;
}// end of function emailCheck




function Check_Time(chktime)
{

if(Check_Digit(chktime)==false)
return (false);

if(chktime.value!="")
{
	var allValid = true;
	var hh=chktime.value.substring(0,2);
	var mm=chktime.value.substring(2,4);

if (chktime.value.length!=4)
allValid = false;

if (hh<0 ||hh>23)
allValid = false;

if (mm<0 ||mm>59)
allValid = false;

if (!allValid)
	{
//		alert("Invalid Time !");
		alert("請填寫正確的時間 !");
		chktime.focus();
		return(false);
	}
}
}




function Check_Blank(ctrim,msg)
{
if(ctrim.value=="")
{
//	alert(msg+" cannot be blank");
	alert("請填寫 " + msg);
//	ctrim.focus();
	return(false);
}
else
{
var btrim = ctrim.value;
var chkblank = true;
var chkbnk = '';
for (i = 0;  i < btrim.length;  i++)
{
ct = btrim.charAt(i);

if (ct == ' ' || ct == '')
	{
	ct = '';
	chkbnk+=ct;
	chkblank = false;
	}
else
	{
	chkblank = true;
	break;
	}

}

if (chkblank == false)
	{
//	alert(msg+" cannot be blank");
	alert("請填寫 " + msg);
	ctrim.focus();
	return(false);
	}
}
}

function Check_Either(chk1,chk2,msg1,msg2)
{
if ((chk1.value=="") && (chk2.value==""))
	{
	alert("Either");
	ch1.focus();
	return(false);
	}
}

function Check_Symbol(chksym)
{
}

function Check_Email(chkemail)
{
invalidChars = " /:,;"
if (chkemail.value == "")
	{
//	alert("Invalid E-Mail Address");
	alert("請填寫正確的 電郵地址");
	return(false);
	}
for (i = 0;  i < invalidChars.length;  i++)
	{
	badChar = invalidChars.charAt(i);
	if (chkemail.value.indexOf(badChar,0) > -1)
		{
//		alert("Invalid E-Mail Address");
		alert("請填寫正確的 電郵地址");
		return(false);
		}
	}
atPos = chkemail.value.indexOf("@",1)
if (atPos == -1) 
	{
//	alert("Invalid E-Mail Address");
	alert("請填寫正確的 電郵地址");
	return(false);
	}
if (chkemail.value.indexOf("@",atPos+1) > -1) 
	{
//	alert("Invalid E-Mail Address");
	alert("請填寫正確的 電郵地址");
	return(false);
	}
periodPos = chkemail.value.indexOf(".",atPos)
if (periodPos == -1) 
	{
//	alert("Invalid E-Mail Address");
	alert("請填寫正確的 電郵地址");
	return(false);
	}
if (periodPos + 3 > chkemail.length) 
	{
//	alert("Invalid E-Mail Address");
	alert("請填寫正確的 電郵地址");
	return(false);
	}
return true
}

function Check_Digit(c_trim)
{
	var checkOK = " -0123456789.";
	var allNum = "";
	var btrim = c_trim.value;
	var c_digit = '';
for (i = 0;  i < btrim.length;  i++)
{
ct = btrim.charAt(i);
if (ct == ' ')
	ct = '';
	c_digit+=ct;
}


  for (i = 0;  i < c_digit.length;  i++)
  {
    cd = c_digit.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (cd == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
    //alert("Input Number Only !");
   // c_trim.focus();
    return (false);
    break;
    }
    if (cd != ",")
      allNum += cd;
  }
c_trim.value = c_digit;
}


function Check_Number(c_trim)
{
	var checkOK = "1234567890";
	var allNum = "";
	
	alert(c_trim.value);
	
	//var c_numeric = c_trim.value;

	//for (i = 0;  i < c_numeric.length;  i++) {
		//cd = c_numeric.charAt(i);
		//for (j = 0;  j < checkOK.length;  j++)
			//if (cd == checkOK.charAt(j))
				//break;
		//if (j == checkOK.length) {
			//  alert("Input Integer Number Only !");
			// alert("只填寫數目!");
			//  c_trim.focus();
			//return false;
			//break;
		//}
		//if (cd != ",")
			//allNum += cd;
	//}
	//c_trim.value = c_numeric;
}

function check_int(num)
{
	// only allow numbers to be entered
var checkOK = "0123456789";
var checkStr = num.value;
//var checkStr = f.seq.value;
var allValid = true;
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 += ch;
}
if (!allValid)
{
//alert("只可填寫整數.");
//f.seq.focus();
return (false);
}

}





function Check_Alpha(c_trim)
{
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var allNum = "";
	var c_alpha = c_trim.value;

  for (i = 0;  i < c_alpha.length;  i++)
  {
    cd = c_alpha.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (cd == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
    alert("Input Alpha Only !");
    c_trim.focus();
    return (false);
    break;
    }
    if (cd != ",")
      allNum += cd;
  }
c_trim.value = c_alpha;
}


function Check_AlphaNumeric(c_trim)
{
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-";
	var allNum = "";
	var c_alphanumeric = c_trim.value;

  for (i = 0;  i < c_alphanumeric.length;  i++)
  {
    cd = c_alphanumeric.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (cd == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
//    alert("Input Alpha Numeric Only !");
    alert("只填寫英文和數目 !");
//    c_trim.focus();
    return (false);
    break;
    }
    if (cd != ",")
      allNum += cd;
  }
c_trim.value = c_alphanumeric;
return true
}


function Check_ChiDate(chkdate)
{

if(chkdate.value!="")
{

Pos1 = chkdate.indexOf("/",1);
Pos2 = chkdate.indexOf("/",Pos1+1);
lng = chkdate.length;
	var allValid = true;
	var yy=parseInt(chkdate.substring(0,Pos1));
	var mm=parseInt(chkdate.substring(Pos1+1,Pos2));
	var dd=parseInt(chkdate.substring(Pos2+1,lng));
if(!yy || !mm || !dd)
allValid = false;
if (mm<1||mm>12)
allValid = false;
now = new Date();
thisyear = now.getYear();
if (yy<1900 || yy>2100)
allValid = false;

if ((mm==1)||(mm==3)||(mm==5)||(mm==7)||(mm==8)||(mm==10)||(mm==12))
	{
	if (dd<1||dd>31)
	allValid = false;
	}
else if ((mm==4)||(mm==6)||(mm==9)||(mm==11))
	{
	if (dd<1||dd>30)
	allValid = false;
	}
else if (mm==2)
		{
		if((yy%4)==0)
			{
			if(dd<1||dd>29)
			allValid = false;
			}
		else
			{
			if(dd<1||dd>28)
			allValid = false;
			}
		}
else
	{
	allValid = false;
	}
if (!allValid)
	{
//		alert("Invalid date !");
//		chkdate.focus();
		return(false);
	}
return(true);
}
}


function Check_Date(chkdate)
{

if(chkdate.value!="")
{
	var allValid = true;
	var yy=parseInt(chkdate.value.substring(6,10));
	var mm=parseInt(chkdate.value.substring(0,2));
	var dd=parseInt(chkdate.value.substring(3,5));

if(!yy || !mm || !dd)
allValid = false;

if (mm<1||mm>12)
allValid = false;

now = new Date();
thisyear = now.getYear();
if (yy<1900 || yy>2100)
allValid = false;

if ((mm==1)||(mm==3)||(mm==5)||(mm==7)||(mm==8)||(mm==10)||(mm==12))
	{
	if (dd<1||dd>31)
	allValid = false;
	}
else if ((mm==4)||(mm==6)||(mm==9)||(mm==11))
	{
	if (dd<1||dd>30)
	allValid = false;
	}
else if (mm==2)
		{
		if((yy%4)==0)
			{
			if(dd<1||dd>29)
			allValid = false;
			}
		else
			{
			if(dd<1||dd>28)
			allValid = false;
			}
		}
else
	{
	allValid = false;
	}

if (!allValid)
	{
		alert("Invalid date !");
		chkdate.focus();
		return(false);
	}
}
}


function Check_Month(chkMonth)
{

if(Check_Digit(chkMonth)==false)
return (false);

if(chkMonth.value!="")
{
	var allValid = true;
	var yy=chkMonth.value.substring(0,4);
	var mm=chkMonth.value.substring(4,6);

if (chkMonth.value.length!=6)
allValid = false;

if (mm<1||mm>12)
allValid = false;

now = new Date();
thisyear = now.getYear();
if (yy<1900)
allValid = false;

if (!allValid)
	{
		alert("Invalid date !");
		chkMonth.focus();
		return(false);
	}
}
}


function Check_DateCmp(chkdate1,chkdate1desc,chkdate2,chkdate2desc,equal)
{
if (chkdate1.value != '' && chkdate2.value != '')
{
if (equal == '=')
{
if (chkdate1.value > chkdate2.value)
	{
	alert(chkdate2desc + " cannot be earlier than " + chkdate1desc);
	chkdate1.focus();
	return(false);
	}
}
else
{
if (chkdate1.value >= chkdate2.value)
	{
	alert(chkdate2desc + " cannot be earlier than or equal " + chkdate1desc);
	chkdate1.focus();
	return(false);
	}
}
}
}

function Check_Length(chklen,len)
{
if (chklen.value.length > len)
	{
	alert("Max Length is " + len);
	chklen.focus();
	return(false);
	}
}

//-------------------------------------------------------------------------------------------
//check the value of object whether blank or not 
//-------------------------------------------------------------------------------------------
function ChkBlank(fieldobj) 
{
		var bgBad = "red";
		var bgGood = "white";
		var a = fieldobj.value;

		if (a!=" ") {
			fieldobj.backgroundColor = bgGood;
			return true;
		}
		else {
			alert("Blank value do not allow !");
			fieldobj.backgroundColor = bgBad;
			fieldobj.select();
			fieldobj.focus();
			return false; 
		}
}

//-------------------------------------------------------------------------------------------
//check the object whether bit data type or not 
//-------------------------------------------------------------------------------------------
function ChkBitType(fieldobj)  
{
	var a = fieldobj.value;
	
	if ((a!="") && (typeof(a) == "boolean")) {
		return true; 
	} 
	else { 
		alert("Invalid Data Type !");
		fieldobj.select();
		fieldobj.focus(); 
		return false; 
	}
}	
 
//-------------------------------------------------------------------------------------------
//check the object whether number data type or not 
//------------------------------------------------------------------------------------------- 
function ChkNumType(fieldobj) 
{
	var a = fieldobj.value;
	
	if ((a!='') && typeof(a) == "number") {
		return true; 
	} 
	else { 
		alert("Invalid Number Data Type !");
//		fieldobj.select();
//		fieldobj.focus(); 
		return false; 
	}
}	

 
//-------------------------------------------------------------------------------------------
//check the object whether string data type or not 
//------------------------------------------------------------------------------------------- 
function ChkStrType(fieldobj) 
{
	var a = fieldobj.value;
	
	if ((a!="") && (typeof(a) == "string")) {
		return true; 
	}  
	else { 
		alert("Invalid Data Type !");
		fieldobj.select();
		fieldobj.focus(); 
		return false; 
	}
}	

 
//-------------------------------------------------------------------------------------------
//check the object whether string data type or not 
//------------------------------------------------------------------------------------------- 
function ChkStrType(fieldobj) 
{
	var a = fieldobj.value;
	
	if ((a!="") && (typeof(a) == "string")) {
		return true; 
	} 
	else { 
		alert("Invalid Data Type !");
		fieldobj.select();
		fieldobj.focus(); 
		return false; 
	}
}	
 

//-------------------------------------------------------------------------------------------
//check the object whether date format or not 
//------------------------------------------------------------------------------------------- 
function ChkDateFmt(fieldobj) 
{
	var a = fieldobj.value;
	var pos1 = a.lastIndexOf('/');
	var pos2 = a.lastIndexOf('/',2);
	alert(pos1);
	alert(pos2);
}	

 
//-------------------------------------------------------------------------------------------
// Check the value of object whether within the number ranage
//-------------------------------------------------------------------------------------------
function ChkNumRange(fieldobj,numfrom,numto) 
{
	var a = fieldobj.value;
	
	for (i=0; i<fieldobj.value.length; i++) {
		if (fieldobj.value.charCodeAt([i]) < 46 || fieldobj.value.charCodeAt([i]) > 57 || fieldobj.value.charCodeAt([i]) == 47) {
//			alert("Invalid Number Data Type!");
			alert("請填寫 數目!");
//			fieldobj.select();
//			fieldobj.focus();
			return false; 
		}
	}
	if (a>= numfrom && a<=numto) {
			return true;
	}
	else {
//		alert("Range should be " + numfrom + " and " + numto);		
		alert("請填寫 由 " + numfrom + " 至 " + numto);		
//		fieldobj.select(); 
//		fieldobj.focus();
		return false; 
	}
}


//-------------------------------------------------------------------------------------------
// Check the decimal point of value 
//-------------------------------------------------------------------------------------------
function ChkDecPt(fieldobj, decpt) 
{
	var a = fieldobj.value;
	var decptpos = a.lastIndexOf(".");
	
	if (decpt == 0 && decptpos == -1) { 
		return true; 
	}
	else 
		if ((decptpos != -1) && (decpt == decptpos)) {
		return true;
	}
	else {
		alert("Please enter numeric value with " + decptpos + " decimal place(s).");
		return false; 
	}	
}


//-------------------------------------------------------------------------------------------
// Convert the paramater value from 1 & 0 to (Y)es & (N)o
//-------------------------------------------------------------------------------------------
function ConvertToYN(fieldval)
{
	if (fieldval = 1) return 'Y'
		else return 'N';
} 


//-------------------------------------------------------------------------------------------
// Convert the paramater value from (Y)es & (N)o to 1 & 0
//-------------------------------------------------------------------------------------------
function ConvertToBit(fieldval) 
{
	if (fieldval = 'Y') return 1 
		else return 0;
} 


//-------------------------------------------------------------------------------------------
// Convert the paramater value to passing date format 
//-------------------------------------------------------------------------------------------
function ConvertToDate(fieldval,frdatefmt,todatefmt) 
{
	var today_date= new Date()
	var myyear=today_date.getYear()
	var mymonth=today_date.getMonth()+1
	var mytoday=today_date.getDate()
	var a = fieldval.value
	document.write("今天是： ")
	document.write(myyear+"/"+mymonth+"/"+mytoday)
} 


//-------------------------------------------------------------------------------------------
// Check the browser name 
//-------------------------------------------------------------------------------------------
function ChkBrowserName() 
{
	return navigator.appName;
}


//-------------------------------------------------------------------------------------------
// Check the browser version
//-------------------------------------------------------------------------------------------
function ChkBrowserVer() 
{ 
	return navigator.appVersion;
} 


//-------------------------------------------------------------------------------------------
// Confirm Messages
//-------------------------------------------------------------------------------------------
function ConfirmMsg(Msg) 
{
	ConfirmMsg = window.confirm(Msg);
	return;
} 
//-->