function getRadioVal(rb){

	var L=rb.length;var ret="";

	for (var i = 0 ; i< L ; i++)

	 { if(rb[i].checked) { ret=rb[i].value; break; } }

	return(ret);

}



// Check Valid Time

<!-- Begin

function timevalidate(field) {

var valid = "0123456789"

var ok = "yes";

var temp;

for (var i=0; i<field.value.length; i++) {

temp = "" + field.value.substring(i, i+1);

if (valid.indexOf(temp) == "-1") ok = "no";

}

if (ok == "no") {

alert("โปรดตรวจสอบ เวลาที่โอนเงินให้ถูกต้องด้วยค่ะ ( นับเวลาแบบ 24 ชม! )");

field.focus();

field.select();

   }

}

//  End -->



// Check Valid Time

<!-- Begin

function timevalidate2(field) {

var valid = "0123456789"

var ok = "yes";

var temp;

for (var i=0; i<field.value.length; i++) {

temp = "" + field.value.substring(i, i+1);

if (valid.indexOf(temp) == "-1") ok = "no";

}

if (ok == "no") {

alert("โปรดตรวจสอบ เวลาที่โอนเงินให้ถูกต้องด้วยค่ะ ( ประมาณเวลาเป็นนาที ! )");

field.focus();

field.select();

   }

}

//  End -->



// Check Valid Money Amount

<!-- Begin

function moneyvalidate(field) {

var valid = ",.0123456789"

var ok = "yes";

var temp;

for (var i=0; i<field.value.length; i++) {

temp = "" + field.value.substring(i, i+1);

if (valid.indexOf(temp) == "-1") ok = "no";

}

if (ok == "no") {

alert("โปรดตรวจสอบ จำนวนเงินที่โอนต้องเป็นตัวเลขเท่านั้นค่ะ!");

field.focus();

field.select();

   }

}

//  End -->



function Form_Validator(MyForm)

{

// check to see if the field is blank

if  (getRadioVal(MyForm.paytype) == '')

{

alert("โปรดตรวจสอบ ประเภทของการชำระค่าบริการด้วยค่ะ!");

//MyForm.paytype.focus();

MyForm.paytype[0].focus();

return (false);

}



// check to see if the field is blank

if (MyForm.ticketid1.value == "")

{

alert("โปรดตรวจสอบ เลขที่อ้างอิงด้วยค่ะ ( Ticket ID ) !");

MyForm.ticketid1.focus();

return (false);

}



// check to see if the field is blank

if (MyForm.domain.value == "")

{

alert("โปรดตรวจสอบ ชื่อโดเมนด้วยค่ะ!");

MyForm.domain.focus();

return (false);

}



// check to see if the field is blank

if (MyForm.ext.value == "")

{

alert("โปรดตรวจสอบ สกุลของโดเมนด้วยค่ะ!");

MyForm.ext.focus();

return (false);

}



// check to see if the field is blank

if (MyForm.name.value == "")

{

alert("โปรดตรวจสอบ ชื่อ-นามสกุลด้วยค่ะ!");

MyForm.name.focus();

return (false);

}



/*Email Validation*/

<!-- Begin



// check to see if the field is blank

if (MyForm.cust_email.value == "")

{

alert("โปรดตรวจสอบ อีเมล์ด้วยค่ะ!");

MyForm.cust_email.focus();

return (false);

}



/* 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=MyForm.cust_email.value.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. */

	alert("อีเมล์ไม่ถูกต้อง! (โปรดตรวจสอบ เครื่องหมาย @ และ . )")

	MyForm.cust_email.focus();

	MyForm.cust_email.select();

	return false

}

var user=matchArray[1]

var domain=matchArray[2]



// See if "user" is valid 

if (user.match(userPat)==null) {

    // user is not valid

    alert("Account Name ของอีเมล์ไม่ถูกต้อง โปรดตรวจสอบ!")

	MyForm.cust_email.focus();

	MyForm.cust_email.select();

    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) {

	        alert("IP address ไม่ถูกต้อง โปรดตรวจสอบ!")

		return false

	    }

    }

    return true

}



// Domain is symbolic name

var domainArray=domain.match(domainPat)

if (domainArray==null) {

	alert("ชื่อโดเมนของอีเมล์ไม่ถูกต้อง โปรดตรวจสอบ!")

	MyForm.cust_email.focus();

	MyForm.cust_email.select();

    return false

}



/* domain name seems valid, but now make sure that it ends in a

   three-letter word (like com, edu, gov) or a two-letter word,

   representing country (uk, nl), and that there's a hostname preceding 

   the domain or country. */



/* Now we need to break up the domain to get a count of how many atoms

   it consists of. */

var atomPat=new RegExp(atom,"g")

var domArr=domain.match(atomPat)

var len=domArr.length

if (domArr[domArr.length-1].length<2 || 

    domArr[domArr.length-1].length>3) {

   // the address must end in a two letter or three letter word.

   alert("อีเมล์แอดเดรสต้องลงท้ายด้วยตัวอักษร 3 ตัว (นามสกุลของโดเมน) หรือตัวอักษร 2 ตัว (ตัวอักษรย่อของประเทศ)")

	MyForm.cust_email.focus();

	MyForm.cust_email.select();

   return false

}



// Make sure there's a host name preceding the domain.

if (len<2) {

   var errStr="อีเมล์แอดเดรสไม่ถูกต้อง โปรดตรวจสอบ!"

   alert(errStr)

	MyForm.cust_email.focus();

	MyForm.cust_email.select();

   return false

}

//  End -->



// check phone number

if ((MyForm.phone.value==null)||(MyForm.phone.value=="")){

	alert("โปรดตรวจสอบ เบอร์โทรศัพท์ด้วยค่ะ!")

	MyForm.phone.focus();

	return false;

}



// check to see if the field is blank

if (getRadioVal(MyForm.bank) == '')

{

	alert ("โปรดตรวจสอบ ธนาคารที่โอนเงินด้วยค่ะ ...");

	MyForm.bank[0].focus();

	return false;

}



// check to see if the field is blank

if (MyForm.place.value == "")

{

alert("โปรดตรวจสอบ สถานที่โอนเงินด้วยค่ะ!");

MyForm.place.focus();

return (false);

}



// check to see if the field is blank

if (MyForm.branch.value == "")

{

alert("โปรดตรวจสอบ สาขา/เลขที่เครื่อง ATM ด้วยค่ะ!");

MyForm.branch.focus();

return (false);

}



// check to see if the field is blank

if (MyForm.slipid.value == "")

{

alert("โปรดตรวจสอบ เลขที่สำเนาสลิปด้วยค่ะ!");

MyForm.slipid.focus();

return (false);

}



// check to see if the field is blank

if (MyForm.hourtime.value == "")

{

alert("โปรดตรวจสอบ เวลาที่โอนเงินด้วยค่ะ!");

MyForm.hourtime.focus();

return (false);

}



// check to see if the field is blank

if (MyForm.sectime.value == "")

{

alert("โปรดตรวจสอบ เวลาที่โอนเงินด้วยค่ะ!");

MyForm.sectime.focus();

return (false);

}



// check to see if the field is blank

if (MyForm.money.value == "")

{

alert("โปรดตรวจสอบ จำนวนเงินที่โอนด้วยค่ะ!");

MyForm.money.focus();

return (false);

}



return true;

}



//============================================================================





var date_arr = new Array;



var tdate_arr = new Array;



date_arr[0]=new Option("มกราคม",31);

date_arr[1]=new Option("กุมภาพันธ์",28);

date_arr[2]=new Option("มีนาคม",31);

date_arr[3]=new Option("เมษายน",30);

date_arr[4]=new Option("พฤกษภาคม",31);

date_arr[5]=new Option("มิถุนายน",30);

date_arr[6]=new Option("กรกฏาคม",31);

date_arr[7]=new Option("สิงหาคม",30);

date_arr[8]=new Option("กันยายน",30);

date_arr[9]=new Option("ตุลาคม",31);

date_arr[10]=new Option("พฤษจิกายน",30);

date_arr[11]=new Option("ธันวาคม",31);



var def="";

var ttime = new Date();

var ddate = ttime.getDate();

var mmonth = ttime.getMonth();

var yyear = ttime.getYear();



function fill_select(f)

{

        document.writeln("<SELECT name=\"tdate\" ></SELECT><SELECT name=\"tmonth\"  onchange=\"update_tdate(payment)\">");



        for(x=0;x<12;x++) 

		{

                        if (mmonth == x)  def="selected";



                        else		def="";



			mv = x+1;

             document.writeln("<OPTION value=\""+mv+"\"  "+def+" >"+date_arr[x].text);

//             document.writeln("<OPTION value=\""+date_arr[x].value+"\"  "+def+" >"+date_arr[x].text);

//                document.writeln("<OPTION value=\""+x+"\"  "+def+" >"+date_arr[x].text);

		}

        document.writeln("</SELECT>");



//        selection=f.tmonth[f.tmonth.selectedIndex].value;

}







function update_tdate(f)

{



        temp=f.tdate.selectedIndex; 



        for(x=tdate_arr.length;x>0;x--)

        {



                tdate_arr[x]=null;



                f.tdate.options[x]=null;



         }



		kkk = (f.tmonth[f.tmonth.selectedIndex].value) - 1;

		selection = parseInt(date_arr[kkk].value);

//        selection=parseInt(f.tmonth[f.tmonth.selectedIndex].value);



        ret_val = 0;



        if(f.tmonth[f.tmonth.selectedIndex].value == 28)

        {



                year=parseInt(f.tyear.options[f.tyear.selectedIndex].value);



                if (year % 4 != 0 || year % 100 == 0 ) ret_val=0;



                else



                        if (year % 400 == 0)  ret_val=1;



                        else



                                ret_val=1;

        }



        selection = selection + ret_val;        



        for(x=1;x < selection+1;x++) 

        {

                tdate_arr[x-1]=new Option(x);            



                f.tdate.options[x-1] = tdate_arr[x-1];

        } 





//       if (temp == -1) f.tdate.options[temp].selected=true;

	   if (temp == -1) f.tdate.options[ddate-1].selected=true;

//		if (temp == -1) f.tdate.options[0].selected=true;



        else



//             f.tdate.options[temp].selected=true;  

			 f.tdate.options[0].selected = true;



}







function year_install(f)

{



        document.writeln("<SELECT name=\"tyear\" onchange=\"update_tdate(payment)\">")

		if ( yyear < 1000 )

		{

			yyear += 1900;

		}

		var startyear = yyear -1;

		var endyear = yyear +1;



        for(x=startyear;x<=endyear;x++) 

		{

			if (yyear == x)  def="selected";



			else		def="";

						

			document.writeln("<OPTION value=\""+x+"\" "+def+" >"+x);

		}

        document.writeln("</SELECT>");



        update_tdate(f)



}
