function createRequestObject()
{	
	var request_o;										// Declare the variable to hold the object.
	var browser = navigator.appName;					// Find the browser name
	if(browser == "Microsoft Internet Explorer")
	{
		try
		{
			request_o =  new ActiveXObject("Msxml2.XMLHTTP");   // Create the object using MSIE's method	
		}
		catch (e)
		{
			try {
               request_o = new ActiveXObject("Microsoft.XMLHTTP"); // Create the object using MSIE's method	
            } catch (e) {}
		}		  	
	}
	else
	{
		request_o = new XMLHttpRequest();                    // Create the object using other browser's method		
	}

	if (!request_o) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
	return request_o;										// Return the object
}

/* You can get more specific with version information by using parseInt(navigator.appVersion) Which will
   extract an integer value containing the version of the browser being used. */


/* The variable http will hold our new XMLHttpRequest object. */

var f_id ;
var disp_cost_id ;
// GetFileContent method: validates a login request
function changePrice(id,field_id,disp_room_cost)
{
	var http = createRequestObject();
	f_id = field_id ;
	disp_cost_id = disp_room_cost ;
	if (id!=5)
	{
		document.frm_booking.chk_full_1.disabled=true;
		document.frm_booking.no_of_beds_1.disabled=true;
	}
	else
	{
		document.frm_booking.chk_full_1.disabled=false;
		document.frm_booking.no_of_beds_1.disabled=false;
	}
	// open the http connection
	http.open('GET', 'te.php?id='+id,true);	
	//http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	// where to go
	http.onreadystatechange = function(){handleHttpValidateLogin(http);}
	http.send(null);
}
	
var tot ;
var sum=0 ;

function handleHttpValidateLogin(http)
{
	if(http.readyState == 4)
	{
		document.getElementById(f_id).innerHTML = http.responseText ;
		document.getElementById(disp_cost_id).innerHTML = http.responseText ;
	}
}

//retriving room description of the selected type
var descid;
function roomDesc(id1,desc_id,f_id)
{
	if (id1==5)
		document.getElementById(f_id).style.display = '';
	var http = createRequestObject();
	descid = desc_id;
	http.open('GET', 'description.php?id_ds='+id1,true);

	// where to go
	http.onreadystatechange = function(){handleResponse(http);}
	http.send(null);
}

function handleResponse(http)
{
	if(http.readyState == 4)
	{
		document.getElementById(descid).innerHTML = http.responseText ;
	}
}
//end of room description function

// edit hotel information
var hotel_i_no;
function edit_hotel_info(hotelid)
{
	hotel_i_no = hotelid;
	document.frm_hotel.action = 'edit_hotel.php?id_hotel='+hotel_i_no+'&mode=edit_hotel';
	document.frm_hotel.submit();
}
// end of hotel information

// delete hotel info
function del_hotel_info(h_id)
{
	if ( confirm("Do you want to delete the hotel?") )
	{
		document.frm_hotel.action = 'hotelinfo.php?mode=delete_hotel&hotelid='+h_id;
		document.frm_hotel.submit();
	}
}
// end of delete hotel info

// add hotel
function add_hotel()
{
	//alert(document.frm_hotel.tb_hotel_name.value+' and '+document.frm_hotel.tb_location.value) ;
	var http = createRequestObject();
	
	http.open('GET', 'http://localhost/hotelreserve/admin/addhotel.php?h_name='+document.frm_hotel.tb_hotel_name.value+'&h_location='+document.frm_hotel.tb_location.value,true);
	http.onreadystatechange = function(){handleHttpAddHotel(http);}
	http.send(null);
}

function handleHttpAddHotel(http)
{
	if(http.readyState == 4)
	{
		//document.getElementById('add_hotel').style.display = 'none';
		//document.getElementById('hotel_list').style.display = '';
		document.location.href = 'hotelinfo.php';
	}
}
// end of add hotel function

function sel_Hotel_loc(htid)
{
	document.room_no.action = "room_num_info.php?mode=roomdisplay&ht_id="+htid;
	document.room_no.submit();
}

function del_room_cat(category)
{
	if (confirm("Do you want to delete this record?"))
	{
		document.frm_room.action="roominfo.php?mode=del_rm_cat&catd="+category;
		document.frm_room.submit();
	}
}

function del_room_num(rm_id,hid1)
{
	if (confirm("Do you want to delete this record?"))
	{
		document.room_no.action="room_num_info.php?mode=del&roomid="+rm_id+"&hid1="+hid1;
		document.room_no.submit();
	}
}

// select hotel name and location to display the booking information
function hotel_select(indx_val)
{
	document.frm_booking_info.action = 'booking_info.php?mode=booking&hotel_no='+indx_val;
	document.frm_booking_info.submit();
}

// view customer information
function customer_info(cust_id)
{
	window.open("view_customer_info.php?customer_id="+cust_id,"customerdetails","width=450,height=400");
}

// change status of the booking
var hotelid_booking;
function change_status(book_id,hotelid)
{
	hotelid_booking = hotelid;
	if ( confirm("Do you want to change the status of booking?") )
	{
		var booking = 'yes'; 
		status_op(book_id,booking);
	}
	else
	{
		booking = 'no';
		status_op(book_id,booking);
	}
}

// ajax implementation for booking status change
function status_op(id,con)
{
	var http = createRequestObject();
	
	http.open('GET', 'bookingstatuschange.php?bookid='+id+'&condition='+con,true);
	http.onreadystatechange = function(){handleHttpChngStat(http);}
	http.send(null);
}

function handleHttpChngStat(http)
{
	if(http.readyState == 4)
	{
		//alert(http.responseText);
		document.location.href = 'booking_info.php?mode=booking&hotel_no='+hotelid_booking;
	}
}
// end

function test(a,b)
{
	alert("Inside test function "+a +" "+b);
}