  function getRPDArray(){
    for(x=1; x<host.length; x++){
      RPD[x] = new Array();
      for(y=1; y<roomType.length; y++){
        RPD[x][y] = new Array();
        for(z=1; z<=gActiveMax; z++){
            RPD[x][y][z] = (x*1000)+(y*100)+z;
        }
      }
	}
	//for(x=1; x<host.length; x++){
	//	for(y=1; y<roomType.length; y++){
	//		for(z=1; z<=gActiveMax; z++){
	//			document.write(RPD[x][y][z]+"===");
	//		}
	//		document.write("<BR>");
	//	}
	//	document.write("<BR>");
	//}
  }
  function fillHostAndRoomType_bak(){
  	for(var h=1; h<host.length; h++){
  		for(var rt=1; rt<roomType[h].length; rt++){
			document.getElementById('h'+h+rt).innerHTML=host[h];
			document.getElementById('rt'+h+rt).innerHTML=roomType[h][rt];
  		}
  	}
  }
  function fillHostAndRoomType(){
	for(var h=1; h<host.length; h++){
		//alert(roomType[h].length);
		for(var rt=1; rt<roomType[h].length; rt++){
			document.getElementById('rt'+h+rt).innerHTML=roomType[h][rt];
			document.getElementById('maxBr'+h+rt).innerHTML=roomMaxBr[h][rt];
			document.getElementById('maxOcc'+h+rt).innerHTML=roomMaxOcc[h][rt];
		////document.getElementById('tag_a'+h+rt).innerHTML=roomFullRate[h][rt];
		////document.getElementById('tag_a'+h+rt).innerHTML="<a href='../../"+hostPath[h]+"/booknow.php' target='_blank'>Book</a>";
  		}
  	}
  }
  function fillHostAndRoomType_good(){
	for(var h=1; h<host.length; h++){
		document.getElementById('h'+h).innerHTML="<a href='../../"+hostPath[h]+"/index.php'>"+host[h]+"</a>";
		//document.getElementById('tag_a'+h).innerHTML="<a href='../../"+hostPath[h]+"/booknow.php' target='_blank'>Book</a>";
		document.getElementById('tag_a'+h).innerHTML="<a href='../../"+hostPath[h]+"/booknow.php' target='_blank'><img src='../../images/book-bt.gif' /></a>";
		//alert(roomType[h].length);
		for(var rt=1; rt<roomType[h].length; rt++){
			document.getElementById('rt'+h+rt).innerHTML=roomType[h][rt];
			document.getElementById('maxBr'+h+rt).innerHTML=roomMaxBr[h][rt];
			document.getElementById('maxOcc'+h+rt).innerHTML=roomMaxOcc[h][rt];
		//	//document.getElementById('tag_a'+h+rt).innerHTML=roomFullRate[h][rt];
		//	document.getElementById('tag_a'+h+rt).innerHTML="<a href='../../"+hostPath[h]+"/booknow.php' target='_blank'>Book</a>";
  		}
  	}
  }
  function fillDOM(){
  	var j;
  	j=gIndexStart;
  	for(var i=1; i<=gShowMax; i++){
  		document.getElementById('d'+i).innerHTML=DOM[j];
  		if(DOM[j].substr(0,3)=="Sun" || DOM[j].substr(0,3)=="Sat" ){
	  		document.getElementById('d'+i).style.color="red";
	  	}else{
	  		document.getElementById('d'+i).style.color="";
	  	}
  		j=j+1;
  	}
  }

  function getRate2(){
     var index=gIndexStart-1;
     for(var i=1; i<host.length; i++){
	  for(var j=1; j<roomType[i].length; j++){
	  	for(var k=1; k<=gShowMax; k++){
	  		if(WeekEnd[k]=="T"){
	  			//document.getElementById('c'+i+j+k).style.color="#FF6600";
				document.getElementById('c'+i+j+k).style.color="";
	  		}else{
	  			document.getElementById('c'+i+j+k).style.color="";
	  		}
			if(RPD[i][j][k+index]==LRBD[k+index] && LRBD[k+index]>0 ){
				document.getElementById('c'+i+j+k).innerHTML="<div class='best'>"+commaFormattedInt(RPD[i][j][k+index])+"</div>";		
				//document.getElementById('c'+i+j+k).innerHTML="<div class='best'>"+commaFormattedInt(RPD[i][j][k+index])+"</div>";
	  			//document.getElementById('c'+i+j+k).style.color="";
	  			//document.getElementById('c'+i+j+k).style.backgroundColor="#FF00FF";
	  		}else if(RPD[i][j][k+index]==0 ){
				document.getElementById('c'+i+j+k).innerHTML="<div class='title4'>sold out</div>";
	  			//document.getElementById('c'+i+j+k).style.color="";
	  			//document.getElementById('c'+i+j+k).style.backgroundColor="#FF00FF";
	  		}else{
	  			document.getElementById('c'+i+j+k).innerHTML=commaFormattedInt(RPD[i][j][k+index]);
	  			document.getElementById('c'+i+j+k).style.backgroundColor="";
	  		}
	  	}
	  }
    }
  }
  function getRate(){
     var index=gIndexStart-1;
     for(var i=1; i<host.length; i++){
	  for(var j=1; j<roomType[i].length; j++){
	  	for(var k=1; k<=gShowMax; k++){
	  		if(WeekEnd[k]=="T"){
	  			//document.getElementById('c'+i+j+k).style.color="#FF6600";
				document.getElementById('c'+i+j+k).style.color="";
	  		}else{
	  			document.getElementById('c'+i+j+k).style.color="";
	  		}
			if(RPD[i][j][k+index]==LRBD2[i][j] && LRBD2[i][j]>0 ){
				// if lowest rate
				//document.getElementById('c'+i+j+k).innerHTML="<div class='best'>"+commaFormattedInt(RPD[i][j][k+index])+"</div>";		
	  			document.getElementById('c'+i+j+k).innerHTML=commaFormattedInt(RPD[i][j][k+index]);
	  			document.getElementById('c'+i+j+k).style.backgroundColor="";
				//document.getElementById('c'+i+j+k).style.backgroundColor="";
	  			//document.getElementById('c'+i+j+k).style.backgroundColor="#FF00FF";
	  		}else if(RPD[i][j][k+index]==0 ){
				document.getElementById('c'+i+j+k).innerHTML="<div class='title4'>sold out</div>";
	  			//document.getElementById('c'+i+j+k).style.color="";
	  			//document.getElementById('c'+i+j+k).style.backgroundColor="#FF00FF";
	  		}else{
	  			document.getElementById('c'+i+j+k).innerHTML=commaFormattedInt(RPD[i][j][k+index]);
	  			document.getElementById('c'+i+j+k).style.backgroundColor="";
	  		}
	  	}
	  }
    }
  }
  function getRateByAction(pAction){
  	if(pAction=='next'){
  		//gIndexStart=gIndexStart+1;
		gIndexStart=gIndexStart+9;
  	}
  	if(pAction=='pre'){
  		//gIndexStart=gIndexStart-1;
		gIndexStart=gIndexStart-9;
  	}
  	chkStatusButton();
  	getRate();
  }
  function fillRateOnload(){
  	gIndexStart=1;
  	////getRPDArray();
  	chkStatusButton();
  	fillHostAndRoomType();
  	fillDOM();
  	getRate();
  }
  function fillDIVHearder(){
  	document.getElementById('a1').value=gIndexStart;
  	document.getElementById('a2').value=gIndexStart+1;
  	document.getElementById('a3').value=gIndexStart+2;
  	document.getElementById('a4').value=gIndexStart+3;
  	document.getElementById('a5').value=gIndexStart+4;
  	document.getElementById('a6').value=gIndexStart+5;
  	document.getElementById('a7').value=gIndexStart+6;  	
  }
  function getDayOfMonthHTML(pAction){
  	if(pAction=='next'){
  		//gIndexStart=gIndexStart+1;
		gIndexStart=gIndexStart+9;
  	}
  	if(pAction=='pre'){
  		//gIndexStart=gIndexStart-1;
		gIndexStart=gIndexStart-9;
  	}
  	//fillDIVHearder();
  	chkStatusButton();
  	fillHostAndRoomType();
  	fillDOM();
  	getRate();
  }
  function chkStatusButton(){
  	if(gIndexStart==1 || gIndexStart<1 ){
  		document.getElementById('btnpre').style.display = 'none';
  		document.getElementById('btnnext').style.display = 'inline';
  		gIndexStart=1;
  	}
  	else if(gIndexStart==gActiveMax-gShowMax+1 || gIndexStart>gActiveMax-gShowMax+1 ){
  		document.getElementById('btnpre').style.display = 'inline';
  		document.getElementById('btnnext').style.display = 'none';
  		gIndexStart=gActiveMax-gShowMax+1;
  	}else{
  		document.getElementById('btnpre').style.display = 'inline';
  		document.getElementById('btnnext').style.display = 'inline';
  	}
  }
  function commaFormattedInt(amount)
  { 
	var delimiter = ","; // replace comma if desired
	var a = amount;
	var i = parseInt(a);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n =  i.toString();
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
    amount = n ;
	amount = minus + amount;
	return amount;
}
function updateBarRateAjax(br_id,br_price,br_date,rt_id,host_id,row){
		//var frm = document.forms['formName'];
		//var selectEvent = frm.selected_event.value;
		//var selectHost = frm.selected_host.value;
		//var selectMonth = frm.selected_month.value;
		//var selectYear = frm.selected_year.value;
		
		var req = new XMLHttpRequest();
		if (req) {
			req.onreadystatechange = function()
			{
				if (req.readyState == 4 && req.status == 200) {
	      			var temp = req.responseText;
		       		//String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
					//temp = temp.trim();
		       		document.getElementById('lastUpdate').innerHTML=temp; //show last updated to top of page
		       		//document.getElementById('l'+row).innerHTML=temp;//show last updated at the row which updated
		       		//alert(temp);
					if (temp== 'OK'){
		       			//window.location.href="event-list.php?module="+module;
		       			//frm.action = "event-list.php?module="+selectEvent+"&host_id="+selectHost+"&month="+selectMonth+"&year="+selectYear;
						//frm.method = "POST";
						//window.location.href="bar-rate-input.php?host_id="+selectHost;
						//window.location.href="bar-rate-input.php";
						
		       		}else{
		       			//alert("Ajax Error");
		       			
		       		}
	   			}else{
	   				//enableLoading();
	   			}
    		};
    		req.open('GET', "bar-rate-update.php?br_id="+br_id+"&br_price="+br_price+"&br_date="+br_date+"&rt_id="+rt_id+"&host_id="+host_id);
	     	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
   			req.send(null);
   		}
}

function updateBarRateAjax_bak(br_id,br_price,br_date,rt_id,host_id,row){
		//var frm = document.forms['formName'];
		//var selectEvent = frm.selected_event.value;
		//var selectHost = frm.selected_host.value;
		//var selectMonth = frm.selected_month.value;
		//var selectYear = frm.selected_year.value;
		
		var req = new XMLHttpRequest();
		if (req) {
			req.onreadystatechange = function()
			{
				if (req.readyState == 4 && req.status == 200) {
	      			var temp = req.responseText;
		       		//String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
					//temp = temp.trim();
		       		document.getElementById('lastUpdate').innerHTML=temp; //show last updated to top of page
		       		document.getElementById('l'+row).innerHTML=temp;//show last updated at the row which updated
		       		if (temp== 'OK'){
		       			//window.location.href="event-list.php?module="+module;
		       			//frm.action = "event-list.php?module="+selectEvent+"&host_id="+selectHost+"&month="+selectMonth+"&year="+selectYear;
						//frm.method = "POST";
						//window.location.href="bar-rate-input.php?host_id="+selectHost;
						//window.location.href="bar-rate-input.php";
						
		       		}else{
		       			//alert("Ajax Error");
		       			
		       		}
	   			}else{
	   				//enableLoading();
	   			}
    		};
    		req.open('GET', "bar-rate-update.php?br_id="+br_id+"&br_price="+br_price+"&br_date="+br_date+"&rt_id="+rt_id+"&host_id="+host_id);
	     	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
   			req.send(null);
   		}
}
function updateRoomTypeAjax(){
	var frm = document.forms['formName'];
	var req = new XMLHttpRequest();
	if (req) {
		req.onreadystatechange = function()
		{
			if (req.readyState == 4 && req.status == 200) {
      			var temp = req.responseText;
	       		String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
				temp = temp.trim();
	       		//document.getElementById('lastUpdate').innerHTML=temp; //show last updated to top of page
	       		//document.getElementById('l'+row).innerHTML=temp;//show last updated at the row which updated
	       		//alert(temp);
				if (temp== 'OK'){
	       			//window.location.href="event-list.php?module="+module;
	       			//frm.action = "event-list.php?module="+selectEvent+"&host_id="+selectHost+"&month="+selectMonth+"&year="+selectYear;
					//frm.method = "POST";
					//window.location.href="bar-rate-input.php?host_id="+selectHost;
					window.location.href="room-type-update.php";
	       		}else{
	       			//alert("Ajax Error");
	       		}
   			}else{
   				//enableLoading();
   			}
   		};
   		req.open('POST', "room-type-update.php");
     	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		req.send(null);
		req.send('roomtype='+$_POST['roomtype']);
	}
}
var htmlLoading='';
htmlLoading +='<table height="100" width="663" border="0" cellpadding="1" cellspacing="1" >'
htmlLoading +='<tr>';
htmlLoading +='<td align="center"><img src="images/loading.gif">';
htmlLoading +='</td>';
htmlLoading +='</tr></table>';
function groupByBedroom_ajax(){
	var req = new XMLHttpRequest();
	if (req) {
		req.onreadystatechange = function()
		{
			if (req.readyState == 4 && req.status == 200) {
      			var temp = req.responseText;
	       		String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
				temp = temp.trim();
				if (temp!= ''){
					document.getElementById('htmlRenderTable').innerHTML=temp;
					fillRateOnload();
				  }else{
		       		//alert("Ajax Error");
		       	}
	   		  }else{
	   				document.getElementById('htmlRenderTable').innerHTML=htmlLoading;
	   		  }
    		};
    		req.open('GET', "bar-rate-group-by-bedroom.php");
	     	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
   			req.send(null);

   		}
}
function groupByHotel_ajax(){
	var req = new XMLHttpRequest();
	if (req) {
		req.onreadystatechange = function()
		{
			if (req.readyState == 4 && req.status == 200) {
      			var temp = req.responseText;
	       		String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
				temp = temp.trim();
				if (temp!= ''){
					document.getElementById('htmlRenderTable').innerHTML=temp;
					fillRateOnload();
				  }else{
		       		//alert("Ajax Error");
		       	}
	   		  }else{
	   				document.getElementById('htmlRenderTable').innerHTML=htmlLoading;
	   		  }
    		};
    		req.open('GET', "bar-rate-group-by-hotel.php");
	     	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
   			req.send(null);

   		}
}