// JavaScript Document
//======================Check Occupancy============					  
var xmlHttp
var clientid="";
var tourid ="";
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function check_occupancy(no_of_room, tour_id, dep_date, current_occp_id) {
		
var selectmenu=document.getElementById(current_occp_id).value;

if (selectmenu==3){
		if(!confirm('We are unable to give you instant confirmation of your reservation as triple occupancy is usually not possible for Small Group Tours. Please submit an inquiry in the form below or call us at 512 345 1122.')) {
			//document.getElementById('div_form2').style.display='block';
			document.getElementById(current_occp_id).value	= ' ';
			//document.getElementById('tour_total_price').style.display = 'none';
		}else {
			document.getElementById('div_reserve').style.display='none';
			document.getElementById('div_form2').style.display='block';
			}
		return false;
	} else {
		single	= 0;
		double	= 0
		for(i=1;i<=no_of_room;i++){
			val	= document.getElementById('occp['+i+']').value;
			if(val==' '){
			} else{
				if(val==1){
					single++;
				}else {
					double++;
				}
			//guests	= eval(guests) + eval(val);
			}
		}
		if(double!=0){
		double_guest	= double*2;	
		} else{
			double_guest	= 0;
		}
		total_guest	= eval(single)+eval(double_guest)
		show_total_price(tour_id, dep_date, single, double);
		group_guest_list(total_guest);
		
	}
}
	//======================Function using for no_of_room_calculate============			
	
	
	//============ group_tour_calendar ============
	function show_total_price(tour_id, dep_date, single, double) {
		
		var strURL="group_total_price.php?tour_id="+tour_id+"&dep_date="+dep_date+"&single="+single+"&double="+double;
		//alert(strURL);
		var req = GetXmlHttpObject();
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
						//alert(req.responseText);
						if((single==0)&&(double==0)){
						document.getElementById('tour_total_price').style.display = 'none';
						} else {
							document.getElementById('tour_total_price').style.display = '';
						}
						document.getElementById('tour_total_price').innerHTML=req.responseText;						
			//=========== first time click on the destinations show first tab with selected bg ===================

			
						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}	
				
				else {
	document.getElementById('tour_total_price').innerHTML='<img align="center" src="images/ajax-loader.gif" style="padding:55px;" >';
					
				}
					
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}
	
	
	//======================= fetch extra fields for reserve in group tour ==============================
	
	
	//============ group_tour_calendar ============
	function addition_fields(no_of_room, tour_id, dep_date) {
	
		var strURL="group_reserve_ajax.php?&rooms="+no_of_room+"&tour_id="+tour_id+"&dep_date="+dep_date;
		//alert(strURL);
		var req = GetXmlHttpObject();
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
						//alert(req.responseText);
						if(no_of_room==' '){
							document.getElementById('additional_fields').style.display = 'none';
						} else {
				document.getElementById('additional_fields').style.display = '';
						document.getElementById('additional_fields').innerHTML=req.responseText;			
						
						
												
								rad=document.getElementById('no_of_rooms').value;
								amount=1000*rad;
						//		alert(amount);
						document.getElementById('total_amount').value='$'+amount;
						}
			//=========== first time click on the destinations show first tab with selected bg ===================

			
						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}	
				
				else {
	document.getElementById('additional_fields').innerHTML='<img align="center" src="images/ajax-loader.gif" style="padding:55px;" >';
					
				}
					
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}
	
	
	//============ group_tour_calendar ============
	function group_guest_list(no_of_guests) {
	
		var strURL="group_guest_name_list.php?&total="+no_of_guests;
	//	alert(strURL);
		var req = GetXmlHttpObject();
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
						//alert(req.responseText);
						if(no_of_guests==0){
							document.getElementById('guest_list').style.display = 'none';
						} else {
						document.getElementById('guest_list').style.display = '';
						document.getElementById('guest_list').innerHTML=req.responseText;		
						document.form_reserve.number_of_guests.value = no_of_guests;
						}
			//=========== first time click on the destinations show first tab with selected bg ===================
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}	
				
				else {
	document.getElementById('guest_list').innerHTML='<img align="center" src="images/ajax-loader.gif" style="padding:55px;" >';
					
				}
					
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}
