function PopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=500');");
}

function PopUpRoom(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=600');");
}

function Confirm_Del(theForm) {
   var confirmString;
      confirmString = "Do you want to delete?"; 
   if(  !confirm(confirmString) )
      return false;
  return true;
}

function Viewby(url){
	frm = document.profrm;
	idx = frm.viewby.value;
	window.location.href=url+'?catid='+idx;
}

function Change_Cat_View(form, url){
	idx = form.viewby.value;
	window.location.href=url+'?viewby='+idx;
}

function checkAll(field, val){
	if(val == true){
		for (i = 0; i < field.length; i++){
			field[i].checked = true ;
		}
	}else{
		for (i = 0; i < field.length; i++){
			field[i].checked = false ;
		}
	}
}

function SubmitContact(form){
	var frm = document.contact_frm;

	if(frm.fullname.value == ""){
		alert("กรุณาระบุชื่อ");
		frm.fullname.focus();
		return false;
	}
	if(frm.email.value == ""){
		alert("กรุณาระบุอีเมล์");
		frm.email.focus();
		return false;
	}
	var string1=frm.email.value;
	
	if(!emailCheck(string1)){
		alert("รูปแบบอีเมล์ของคุณไม่ถูกต้อง กรุณาระบุอีกครั้ง")
		frm.email.focus();
		return false
	}
	
	if(frm.message.value == ""){
		alert("กรุณาระบุข้อความ");
		frm.message.focus();
		return false;
	}else{
		//frm.submit();
		return true;
	}

}

function CheckRegisForm(form){
	if(!form.gender[0].checked && !form.gender[1].checked && !form.gender[2].checked){
		alert("กรุณาระบุคำนำหน้าชื่อ");
		return false;
	}
	if(form.firstname.value == ''){
		alert("กรุณาระบุชื่อ");
		form.firstname.focus();
		return false;
	}
	if(form.lastname.value == ''){
		alert("กรุณาระบุนามสกุล");
		form.lastname.focus();
		return false;
	}
	if(form.birthday.value == ''){
		alert("กรุณาระบุวันเกิด");
		form.birthday.focus();
		return false;
	}
	if(form.address.value == ''){
		alert("กรุณาระบุที่อยู่");
		form.address.focus();
		return false;
	}
	if(form.province.value == ''){
		alert("กรุณาระบุจังหวัด");
		form.province.focus();
		return false;
	}
	if(form.postcode.value == ''){
		alert("กรุณาระบุรหัสไปรษณีย์");
		form.postcode.focus();
		return false;
	}
	if(form.phone.value == ''){
		alert("กรุณาระบุหมายเลขโทรศัพท์");
		form.phone.focus();
		return false;
	}
	if(form.mobile.value == ''){
		alert("กรุณาระบุหมายเลขมือถือ");
		form.mobile.focus();
		return false;
	}
	if(form.email.value == ''){
		alert("กรุณาระบุอีเมล์");
		form.email.focus();
		return false;
	}
	var string1=form.email.value;
	
	if(!emailCheck(string1)){
		alert("กรุณาระบุอีเมล์ให้ถูกต้อง")
		form.email.focus();
		return false
	}
	if(form.password.value == ''){
		alert("กรุณาระบุรหัสผ่าน");
		form.password.focus();
		return false;
	}
	if(form.password.value != form.repassword.value){
		alert("รหัสผ่านไม่ตรงกัน กรุณาระบุใหม่");
		form.repassword.focus();
		return false;
	}
	if(!form.occupation[0].checked && !form.occupation[1].checked && !form.occupation[2].checked && !form.occupation[3].checked && !form.occupation[4].checked && !form.occupation[5].checked){
		alert("กรุณาระบุอาชีพ");
		return false;
	}else{
		if(form.occupation[5].checked && form.occupation_other == ''){
			alert("กรุณาระบุข้อความในช่องอื่น ๆ");
			form.occupation_other.focus();
			return false;
		}
	}
	if(!form.income[0].checked && !form.income[1].checked && !form.income[2].checked && !form.income[3].checked){
		alert("กรุณาระบุรายได้");
		return false;
	}
	if(!form.how2_tv.checked && !form.how2_radio.checked && !form.how2_web.checked && !form.how2_mag.checked && !form.how2_credit.checked && !form.how2_option.checked && !form.how2_friend.checked){
		alert("กรุณาระบุสื่อที่ทำให้คุณรู้จักร่มไม้ชายคา");
		return false;
	}else{
		if(form.how2_option.checked && form.how2_other.value == ''){
			alert("กรุณาระบุข้อความในช่องอื่น ๆ");
			form.how2_other.focus();
			return false;
		}
	}
	if(form.code.value == ''){
		alert("กรุณาระบุ Code ตามภาพ");
		form.code.focus();
		return false;
	}else{
		return true;
	}

}

function controlChk(form, mode){
	if(mode == 'blizz'){
		if(form.chk_bliz.checked == false){
			for(k=3;k<=11;k++){
				var i = k;
				form["chk_kara_bliz["+i+"]"].checked = false;
				form["chk_kara_bliz["+i+"]"].disabled = true;
			}
		}else{
			for(k=3;k<=11;k++){
				var i = k;
				form["chk_kara_bliz["+i+"]"].disabled = false;
			}
		}
	}else if(mode == 'std'){
		if(form.chk_std.checked == false){
			for(k=12;k<=22;k++){
				var i = k;
				form["chk_kara_std["+i+"]"].checked = false;
				form["chk_kara_std["+i+"]"].disabled = true;
			}
		}else{
			for(k=12;k<=22;k++){
				var i = k;
				form["chk_kara_std["+i+"]"].disabled = false;
			}
		}
	}else if(mode == 'vip'){
		if(form.chk_vip.checked == false){
			for(k=23;k<=24;k++){
				var i = k;
				form["chk_kara_vip["+i+"]"].checked = false;
				form["chk_kara_vip["+i+"]"].disabled = true;
			}
		}else{
			for(k=23;k<=24;k++){
				var i = k;
				form["chk_kara_vip["+i+"]"].disabled = false;
			}
		}
	}else if(mode == 'outdoor'){
		if(form.chk_outdoor.checked == false){
			form.outdoor_no.value = "";
			form.outdoor_no.disabled = true;
		}else{
			form.outdoor_no.disabled = false;
			form.outdoor_no.focus();
		}
	}

}	

function CheckReserveForm(form){
	if(form.date1xx_tmp.value == ''){
		alert("กรุณาระบุวันที่ต้องการจอง");
		form.date1xx_tmp.focus();
		return false;
	}
	if(form.rev_time.value == ''){
		alert("กรุณาระบุเวลาที่ต้องการใช้บริการ");
		form.rev_time.focus();
		return false;
	}
	if(form.rev_visitor.value == ''){
		alert("กรุณาระบุจำนวนลูกค้า");
		form.rev_visitor.focus();
		return false;
	}

	var chosen = false;

	if(form.chk_outdoor.checked){
		chosen = true;
	}
	if(form["chk_catering[1]"].checked || form["chk_catering[2]"].checked){
		chosen = true;
	}
	for(k=3;k<=11;k++){ // Blizz Zone
		var i = k;
		if(form["chk_kara_bliz["+i+"]"].checked){
			chosen = true;
		}
	}
	for(k=12;k<=22;k++){ // Standard Zone
		var i = k;
		if(form["chk_kara_std["+i+"]"].checked){
			chosen = true;
		}
	}
	for(k=23;k<=24;k++){ // Vip Zone
		var i = k;
		if(form["chk_kara_vip["+i+"]"].checked){
			chosen = true;
		}
	}

	if(chosen == false){
		alert("กรุณาระบุห้อง หรือโต๊ะที่ต้องการจอง");
		return false;
	}else{
		return true;
	}
}


function checkOnlyNumber(control, val, msg){

		// only allow numbers to be entered
		var checkOK = "0123456789.";
		var checkStr = val;
		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(msg);
			control.value = '';
			control.focus();
			return (false);
		}

}


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. */

//alert("Email address seems incorrect (check @ and .'s)");
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) {
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

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

// user is not valid

//alert("The username doesn't seem to be 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) {
//alert("Destination IP address is invalid!");
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) {
//alert("The domain name does not seem to be valid.");
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) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

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

if (len<2) {
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}