//----------------- show  data --------------------
function changePage(pageIndex, pageCode) {
  parent.parent.pageCode.location = pageIndex; 
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  
   var newWindow = window.open(theURL,winName,features);
   newWindow.focus();
}

function showuserdata(page,hislogin)
{
var urlis=page+"?loginis="+hislogin;
newwnd = window.open(urlis ,"cl", "toolbar=0,resizable=1,status=1,menubar=0,scrollbars=1,left=120,top=5,width=500,height=520");
newwnd.focus();
}

//---------- delete or not delete ---------------
function del()
  {
    var tmp=confirm("Are You sure You want to delete ?");
     if(!tmp)
       return false;
     else
       return true; 
 }
function delthai()
  {
    var tmp=confirm("คุณต้องการลบใช่ไหม ?");
     if(!tmp)
       return false;
     else
       return true; 
 }
function can()
  {
    var tmp=confirm("Are You sure You want to cancel ?");
     if(!tmp)
       return false;
     else
       MM_goToURL('parent','cancel.php');
 }
function add()
  {
    var tmp=confirm("คุณต้องการจะเพิ่มสินค้าเข้าร้าน ?");
     if(!tmp)
       return false;
     else
       return true; 
 }
//----------------------- check text fields in the form without email-------------
function validate_form_no_email(nameofForm) //get name of form and email field
{
var rez=1;
//var ctr="document."+nameofForm+".length";
//alert(eval(ctr));
var ctr="document."+nameofForm;

var bad=new Array;  //create new array with bad (empty) fields
var j=0;
len=eval(ctr+".length");
for(i=0;i<len;i++)
 {
   aa_type=ctr + ".elements["+i+"].type";
   aa_value=ctr + ".elements[" + i + "].value"
  if (eval(aa_type) =="text")   //if type of field is 'text'
   {
    var pat="_nes";    // pattern 
    arr=ctr + ".elements[" + i + "].name";  //arr has name of field
	//   arr.split(pat); 
	//   arr=document.myform.elements[i].name; 
    ar=eval(arr+".split(pat)[0]");
      if (ar !=eval(arr))
         if(eval(ctr + ".elements[" + i + "].value") == "")
	       bad[j++]=ar;
	      
    }	

  else if (eval(aa_type) =="select-one")   //if type of field is 'select'
   {

    var pat="_selnes";    // pattern 
    arr=ctr + ".elements[" + i + "].name";  //arr has name of field
    ar=eval(arr+".split(pat)[0]");
      if (ar !=eval(arr))
         if(eval(ctr + ".elements[" + i + "].value") == "nothing")    //if value of select field is nothing
	       bad[j++]=ar;
	      
    }	

  }
 len=bad.length;
 if (len !=0) //if array bad not empty
  {
   var message="Please fill next field(s):";
   for (i=0;i<len;i++)
    {
    pat="zz";    // remove 'zz' from all fields
    bad[i]=bad[i].split(pat)[0];
     message+="\n - ";
     message+=bad[i];
     }

   alert (message);

   return false;
  }
 return true;

}



function validate_form_search(nameofForm) //get name of form 
{

var rez=1;
var ctr="document."+nameofForm;
var bad=new Array;  //create new array with bad (empty) fields
var j=0;
len=eval(ctr+".length");
for(i=0;i<len;i++)
 {
   aa_type=ctr + ".elements["+i+"].type";
   aa_value=ctr + ".elements[" + i + "].value"
  if (eval(aa_type) =="text" || eval(aa_type) =="file")   //if type of field is 'text' or 'file'
   {
    var pat="is";    // pattern 
    arr=ctr + ".elements[" + i + "].name";  //arr has name of field
    ar=eval(arr+".split(pat)[0]");
      if (ar !=eval(arr))
         if(eval(ctr + ".elements[" + i + "].value")=="")
	       bad[j++]=ar;
   }	

  else if (eval(aa_type) =="select-one" )   //if type of field is 'select'
   {

    var pat="is";    // pattern 
    arr=ctr + ".elements[" + i + "].name";  //arr has name of field
    ar=eval(arr+".split(pat)[0]");
      if (ar !=eval(arr))
         if(eval(ctr + ".elements[" + i + "].value") == "nothing")    //if value of select field is nothing
	       bad[j++]=ar;
    }	
  }

 len=bad.length;
// alert(len);
 if (len !=0) //if array bad not empty
  {
   var message="Please fill next field(s):";
   for (i=0;i<len;i++)
    {
     message+="\n - ";
     message+=bad[i];
     }
   alert (message);
   return false;
  }
 return true;
}

//********************* end check text fields in the form without email*******

// ------- help window opens --------
 function helpme(help1) 
{
if  (help1==1)
    window.open("help1.htm" ,"help_me", "toolbar=0,resizable=1,status=0,scrollbars=0,menubar=0,left=260,top=110,width=290,height=170");
}
// ----------- end help window -------

// --------------- check if feedback form is correct ----------
function checkfeedback()
{
if (document.feedback.visitoremail.value=="" || document.feedback.visitoremail.value.indexOf ('@')==-1 || document.feedback.visitoremail.value.indexOf ('.')==-1 )
  {
alert("Email is incorrect or absent");
document.feedback.visitoremail.focus();
return false;
  }
else if (document.feedback.visitorname.value=="" )
  {
alert("Name is absent");
document.feedback.visitorname.focus();
return false;
  }

else
return true;
}

// --------- end feedback form --------------

// --------- cart submit form ---------------

function mycart(){
window.open('_blank' ,"windName", "toolbar=0,resizable=0,status=0,menubar=0,scrollbars=0,left=220,top=150,width=200,height=180");
}


//--------- end cart submit form ------------

// ---------- print pages ------------
function printIt(page,hislogin) 
{ 
	showuserdata(page,hislogin);
	newwnd.focus(); 
	newwnd.print(); 
} 
// ------------- print pages -----------------


 
function display_status_line()
{
var d = new Date(); 
var y =  d.getYear() + 543; 
var h = d.getHours(); 
var m = d.getMinutes(); 
var s = d.getSeconds(); 
var mo = d.getMonth() + 1; 
var da = d.getDate(); 
var ampm = (h >= 12)?"PM":"AM"; 
if (da < 10) da = "0" + da;
if (mo < 10) mo = "0" + mo;
if (h > 12) h -= 12; 
if (h == 0) h = 12; 
if (m < 10) m = "0" + m; 
//var t = 'Ehotel Online Status Date' + da + '/' + mo + '/' + y + '  Time' + h + ':' + m +  ':' + s + ' ' + ampm; 
defaultStatus = ' '; 
setTimeout("display_status_line()", 100); 
}


var disableAutoPostback = 0;
		
	function __doPostBack2(eventTarget, eventArgument, actionType)
	{
		if (actionType == 'Delete')
			if (!confirm('Are you sure you wish to delete?'))
				return;
		if (document.forms[0].editing)
		{
			if (actionType == 'ConfirmSave')
				if (!confirm('Are you sure you wish to save?'))
					return;
			if (actionType == null || actionType == 'Cancel')
				if (!confirm('Discard changes?'))
					return;
		}
		var theform = document.forms[0];
		theform.__ACTIONTYPE.value = actionType;
		theform.__EVENTTARGET.value = eventTarget;
		theform.__EVENTARGUMENT.value = eventArgument;
 	 
		theform.submit();
	}

	function selectFirstControl()
	{
		document.getElementById('DataPanel').scrollTop = document.forms[0].__SCROLLPOS.value;
		if (document.forms[0].__AUTOFOCUS.value == '1')
			if (document.forms && document.forms.length > 0)
			{
				theElems = document.forms[0].elements
				for (i = 0; i < theElems.length; i++)
				{
				
					theElem = theElems[i];
					if (theElem.type && theElem.type == "hidden")
						continue;
					theElem.focus();
					break;
				}
			}
	}

	function dpb(e)
	{
		if (disableAutoPostback == 1)
			return;
		if (document.forms[0].defaultPostback && ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)))
		{
			__doPostBack2(document.forms[0].defaultPostback.value, '', 'Submit');
			event.cancelBubble = true;
			event.returnValue = false;
		}
		else if (document.forms[0].defaultEscape && ((e.which && e.which == 27) || (e.keyCode && e.keyCode == 27)))
			__doPostBack2(document.forms[0].defaultEscape.value, '', 'Cancel');
			
		var theform = document.forms[0];
		theform.__EVENTTARGET.value = '';
		theform.__EVENTARGUMENT.value = '';
	}

onLoad=display_status_line();
 var	ie=document.all
 var	dom=document.getElementById
 function setHighlight(i1, i2, r, selected)
	{
		for (i = parseInt(i1); i <= parseInt(i2); i++)
		{
			var c = window.document.getElementById(r + '_' + i);
			if (c != null)
			{
				if (c.getAttribute('orgC') == null)
					c.setAttribute('orgC', c.style.backgroundColor);
				c.setAttribute('selected', selected ? 'true' : 'false');
				c.style.backgroundColor = selected ? 'green' : c.getAttribute('orgC');
				c.setAttribute('lastC', c.style.backgroundColor);
			}
			else
			{
				if (selected)
				{
					MakeBooking.startColumnIndex.value = i2;
					MakeBooking.endColumnIndex.value = i2;
					setHighlight(i1, i == i1 ? i : i - 1, r, false);
					setHighlight(MakeBooking.startColumnIndex.value, MakeBooking.endColumnIndex.value, r, true);
				}
				return;
			}
		}			
	}
	
	function setHighlight2(i1, i2, r, selected, bNo)
	{
		for (i = parseInt(i1); i <= parseInt(i2); i++)
		{
			var c = window.document.getElementById(r + '_' + i);
			if (c != null && (i==i1 || c.getAttribute('B') == null || (MakeBooking.b2Id.value == 'null' && c == MakeBooking.firstBookingCell)))
			{
				if (c.getAttribute('orgC') == null)
					c.setAttribute('orgC', c.style.backgroundColor);
				c.setAttribute('selected', selected ? 'true' : 'false');
				c.style.backgroundColor = selected ? 'green' : c.getAttribute('orgC');
				c.setAttribute('lastC', c.style.backgroundColor);
				if (c.getAttribute('S') != null)
					i2 += parseInt(c.getAttribute('S'));
				if (c.getAttribute('SP') != null)
				{
					for (spi = 0; spi < c.getAttribute('SP').split(",").length; spi++)
					{
						if (parseInt(c.getAttribute('SP').split(",")[spi]) <= i2)
							i2++;
						else
							break;
					}
				}
				i = i + c.colSpan + c.rowSpan - 2;
			}
			else
			{
				if (selected)
				{
					showBook(1, false);
					if (MakeBooking.secondBookingCell != null)
					{
						showBook(2, false);
						setBookDetails(2, null);
					}
					showBook(1, true);
					alert('The booking(s) can not be moved to the selected position.');
				}
				return true;
			}
		}
		if (bNo == 1)
			MakeBooking.b1EC.value = i2;
		else
			MakeBooking.b2EC.value = i2;
	}
		
	function setBookDetails(bNo, cell)
	{
		if (bNo == 1)
		{
			MakeBooking.firstBookingCell = cell;
			MakeBooking.b1Id.value = (cell==null?'':cell.getAttribute('B'));
			MakeBooking.b1SC.value = (cell==null?'':cell.id.split("_")[1]);
			MakeBooking.b1EC.value = MakeBooking.b1SC.value;
			MakeBooking.b1SP = (cell==null || cell.getAttribute('SP')==null?0:cell.getAttribute('SP').split(",").length);
		}
		else
		{
			MakeBooking.secondBookingCell = cell;
			MakeBooking.b2Id.value = (cell==null?'':cell.getAttribute('B'));
			MakeBooking.b2RoomId.value = (cell==null?'':cell.id.split("_")[0]);
			MakeBooking.b2SC.value = (cell==null?'':cell.id.split("_")[1]);
			MakeBooking.b2SP = (cell==null || cell.getAttribute('SP')==null?0:cell.getAttribute('SP').split(",").length);
			if (cell == null)
				MakeBooking.b1EC.value = MakeBooking.b1SC.value;
		}
	}
	
	function selectBooking(cell)
	{
		var clickRoomId = cell.id.split("_")[0];
		if (MakeBooking.firstBookingCell == null)
		{
			if (cell.getAttribute('B') == null)
				alert('Please select a booking to move first.');
			else
			{
				setBookDetails(1, cell);
				showBook(1, true);
			}
		}
		else
		{
			if (MakeBooking.secondBookingCell != null)
			{
				showBook(1, false);
				showBook(2, false);
			}
			if (MakeBooking.firstBookingCell == cell)
			{
				showBook(1, false);
				setBookDetails(2, null);
				setBookDetails(1, null);
			}	
			else if (MakeBooking.secondBookingCell == cell)
			{
				setBookDetails(2, null);
				showBook(1, true);
			}
			else
			{
				setBookDetails(2, cell);
				MakeBooking.b1EC.value = parseInt(MakeBooking.b1SC.value) - MakeBooking.b2SP + MakeBooking.secondBookingCell.colSpan + MakeBooking.secondBookingCell.rowSpan - 2;
				MakeBooking.b2EC.value = parseInt(MakeBooking.b2SC.value) - MakeBooking.b1SP + MakeBooking.firstBookingCell.colSpan + MakeBooking.firstBookingCell.rowSpan - 2;
				
				if (showBook(1, true) != true)
					showBook(2, true);//alert("b1s:"+MakeBooking.b1SC.value+" b1e:"+MakeBooking.b1EC.value+" b2r:"+MakeBooking.b2RoomId.value+" b2s:"+MakeBooking.b2SC.value+" b2e:"+MakeBooking.b2EC.value);
			}
		}
	}
	
	function showBook(i, selected)
	{
		if (i == 1)
			return setHighlight2(parseInt(MakeBooking.b1SC.value), parseInt(MakeBooking.b1EC.value), MakeBooking.firstBookingCell.id.split("_")[0], selected, 1);
		else
			return setHighlight2(parseInt(MakeBooking.b2SC.value), parseInt(MakeBooking.b2EC.value), MakeBooking.secondBookingCell.id.split("_")[0], selected, 2);
	}
	
	function setBooking(cell)
	{
		var clickRoomId = cell.id.split("_")[0];
		
		var columnIndex = parseInt(cell.id.split("_")[1]);
       
		setHighlight(MakeBooking.startColumnIndex.value, MakeBooking.endColumnIndex.value, MakeBooking.roomId.value, false);
		if ((clickRoomId != MakeBooking.roomId.value) || (columnIndex <= parseInt(MakeBooking.startColumnIndex.value)))
		{
			MakeBooking.startColumnIndex.value = columnIndex;
			MakeBooking.endColumnIndex.value = columnIndex;
			MakeBooking.roomId.value = clickRoomId;
		}
		else
			MakeBooking.endColumnIndex.value = columnIndex;
		setHighlight(MakeBooking.startColumnIndex.value, MakeBooking.endColumnIndex.value, MakeBooking.roomId.value, true);
	}

	function Over(cell)
	{
		cell.setAttribute('lastC', cell.style.backgroundColor);
		if (cell.getAttribute('orgC') == null)
			cell.setAttribute('orgC', cell.style.backgroundColor);
		if (cell.getAttribute('selected') != 'true')
			cell.style.backgroundColor = 'blue';
			
	}
	
	function Over2(cell)
	{
		if (MakeBooking.firstBookingCell != null)
		{	
			cell.style.cursor = "hand";
			Over(cell);
		}
	}
	
	function Out(cell)
	{
		if (cell.getAttribute('lastC') != null)
			cell.style.backgroundColor = cell.getAttribute('lastC');
			else
			{
		if (cell.getAttribute('selected') != 'true')
			cell.style.backgroundColor = cell.getAttribute('orgC');
			}
	}
	
	function Out2(cell)
	{
		if (MakeBooking.firstBookingCell != null)
		{	
			cell.style.cursor = "default";
			Out(cell);
		}
	}


 
 
 function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,mm,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; mm=val.alt; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+mm+' ต้องเป็นค่าของอีเมล\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+mm+'ต้องเป็นค่าตัวเลข\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+mm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += 'ระบุ '+mm+'\n'; }
    } if (errors) alert(''+errors);
    document.MM_returnValue = (errors == '');
} }
 

function check_all(frm, chAll){  
	comfList = document.forms[frm].elements['cremove[]']; 
	checkAll = (chAll.checked)?true:false; 
	// what to do? Check all or uncheck all.   
	// Is it an array   
	if (comfList.length) {     
		if (checkAll) {          
			for (i = 0; i < comfList.length; i++) {  
				comfList[i].checked = true;       
				}        }     
				else {      
					for (i = 0; i < comfList.length; i++) {     
						comfList[i].checked = false;         
						}        }    }    else { 
							/* This will take care of the situation when your checkbox/dropdown list (checkList[] element here) is dependent on  
							a condition and only a single check box came in a list.        */  
							if (checkAll) {            comfList.checked = true;        }     
							else {            comfList.checked = false;        }    }    return;
							}
 function check_all2(frm, chAll){  
	comfList = document.forms[frm].elements['cremove1[]']; 
	checkAll = (chAll.checked)?true:false; 
	// what to do? Check all or uncheck all.   
	// Is it an array   
	if (comfList.length) {     
		if (checkAll) {          
			for (i = 0; i < comfList.length; i++) {  
				comfList[i].checked = true;       
				}        }     
				else {      
					for (i = 0; i < comfList.length; i++) {     
						comfList[i].checked = false;         
						}        }    }    else { 
							/* This will take care of the situation when your checkbox/dropdown list (checkList[] element here) is dependent on  
							a condition and only a single check box came in a list.        */  
							if (checkAll) {            comfList.checked = true;        }     
							else {            comfList.checked = false;        }    }    return;
							}


 function check_all3(frm, chAll){  
	comfList = document.forms[frm].elements['cremove2[]']; 
	checkAll = (chAll.checked)?true:false; 
	// what to do? Check all or uncheck all.   
	// Is it an array   
	if (comfList.length) {     
		if (checkAll) {          
			for (i = 0; i < comfList.length; i++) {  
				comfList[i].checked = true;       
				}        }     
				else {      
					for (i = 0; i < comfList.length; i++) {     
						comfList[i].checked = false;         
						}        }    }    else { 
							/* This will take care of the situation when your checkbox/dropdown list (checkList[] element here) is dependent on  
							a condition and only a single check box came in a list.        */  
							if (checkAll) {            comfList.checked = true;        }     
							else {            comfList.checked = false;        }    }    return;
							}

function check_all4(frm, chAll){  
	comfList = document.forms[frm].elements['cremove3[]']; 
	checkAll = (chAll.checked)?true:false; 
	// what to do? Check all or uncheck all.   
	// Is it an array   
	if (comfList.length) {     
		if (checkAll) {          
			for (i = 0; i < comfList.length; i++) {  
				comfList[i].checked = true;       
				}        }     
				else {      
					for (i = 0; i < comfList.length; i++) {     
						comfList[i].checked = false;         
						}        }    }    else { 
							/* This will take care of the situation when your checkbox/dropdown list (checkList[] element here) is dependent on  
							a condition and only a single check box came in a list.        */  
							if (checkAll) {            comfList.checked = true;        }     
							else {            comfList.checked = false;        }    }    return;
							}



function show_hide(divID){
var divArea = document.getElementById(divID)
var divAreaImg = document.getElementById(divID+"_img")
var divAreaVisible = divArea.style.display != "none"

if(divAreaVisible){
divArea.style.display = "none"
//divAreaImg.innerHTML = "<img src='/EN/Script/plus.jpg' border='0'>"
}else{
divArea.style.display = ""
//divAreaImg.innerHTML = "<img src='/EN/Script/minus.jpg' border='0'>"
}
}

function show_hide_text(divID){
var divArea = document.getElementById(divID)
var divAreaImg = document.getElementById(divID+"_img")
var divAreaVisible = divArea.style.display != "none"

if(divAreaVisible){
divArea.style.display = "none"
divAreaImg.innerHTML = "+"
}else{
divArea.style.display = ""
divAreaImg.innerHTML = "−"
//ADDED TO CLOSE ANY EXPANDED SECTIONS
close_others(divID)
}

}

 

 extArray1 = new Array(".jpg", ".jpeg", ".gif");
 extArray2 = new Array(".jpg", ".jpeg");  
    function LimitAttach(form, file, ext) {
	if(ext==1) extArray=extArray1; else  extArray=extArray2;
    allowSubmit = false;
    if (!file) return;
    while (file.indexOf("\\") != -1)
    file = file.slice(file.indexOf("\\") + 1);
    ext = file.slice(file.indexOf(".")).toLowerCase();
	 
    for (var i = 0; i < extArray.length; i++) {
    if (extArray[i] == ext) { allowSubmit = true; break; }
    }
    if (allowSubmit) return true;
    else
    alert("Please only upload files that end in types:  "
    + (extArray.join("  ")) + "\nPlease select a new "
    + "file to upload and submit again.");
    return false;
    }
 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];}
}
 
