//Hotel Filter code(Deepak Singh)
function hotelfilter()
{		
		if(document.getElementById("filterHotel"))
		{
		document.getElementById('filterHotel').style.display="";
		document.getElementById('filterHotel').innerHTML='<div style="margin:0 auto;border:2px solid #1E67A1; background-color:#fff; padding:4px 2px; width:100px;"><b>Updating</b> &nbsp;<img style="vertical-align:middle" src="/ttrs/railtourism/Media/images/indicator.gif" /></div>';
		}
        var xmlHttp;
        try
        {  // Firefox, Opera 8.0+, Safari
         xmlHttp=new XMLHttpRequest();
        }
        catch (e)
        {  // Internet Explorer
            try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e)
                {
                    alert("Your browser does not support AJAX!");
                    return false;
                }
            }
        }
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState==4)
            {
				var count= new Array(6);
				count[0]=parseInt(document.BookTicketForm.count0.value);
				count[1]=parseInt(document.BookTicketForm.count1.value);
				count[2]=parseInt(document.BookTicketForm.count2.value);
				count[3]=parseInt(document.BookTicketForm.count3.value);
				count[4]=parseInt(document.BookTicketForm.count4.value);
				count[5]=parseInt(document.BookTicketForm.count5.value);
				try
				{
				var allhotel=new Array();
				var allindex=0;
				for(var j=5;j>=0;j--) //for all category 5-star to Unrated Hotel
				{
				if(count[j]==0) continue;
				for(var i=0;i<count[j];i++)     //for each hotel in a star's category
				{
				id1=j.toString()+i.toString();
				allhotel[allindex]=id1;
				allindex++;
				} // end for i
				} //end for j Here we get All Hotels
				for(var hidei=0;hidei<allhotel.length;hidei++)
				{
				document.getElementById(allhotel[hidei]).style.display = 'none';
				}
				//Filter Logic Start for star-rating
				var ratinghotels=new Array();
				var ratingindex=0;


				for(var stari=0;stari<allhotel.length;stari++)
				{
				starhotel=parseInt(allhotel[stari].charAt(0));
				if(document.BookTicketForm.indstarrating[(5-starhotel)].checked)
				{
				ratinghotels[ratingindex]=allhotel[stari];
				ratingindex++;
				}
				}
				//Filter Logic End for star-rating */
				//alert('Filter For Star Rating End.');

				//Filter Logic Start for Amenities
				var amenityHotel=new Array();
				var amenityiindex=0;
				for(var amenityi=0;amenityi<ratinghotels.length;amenityi++)
				{
				var  imageid="";
				var amenitycount=0;
				var amenityflag=0;
				for (k=0; k<document.BookTicketForm.indamenity.length; k++)
				{
				if (document.BookTicketForm.indamenity[k].checked==true)
				{
				amenitycount++;
				var amenity=document.BookTicketForm.indamenity[k].value;
				imageid=ratinghotels[amenityi].toString()+'xImage'+amenity.toString();
				try
				{
				if(document.getElementById(imageid))
				{
				amenityflag++;
				}
				}
				catch(err)
				{

				}
				}
				}
				if(amenitycount==amenityflag)
				{
				amenityHotel[amenityiindex]=ratinghotels[amenityi];
				amenityiindex++;
				}
				}
				ratinghotels.length=0;
				//Filter Logic End for Amenities
				// Rate Slider Start ------>
				var minrate=parseInt(document.BookTicketForm.slider1knob1.value);
				var maxrate=parseInt(document.BookTicketForm.slider1knob2.value);
				var areafilter=document.BookTicketForm.areafilter.value;
				//document.BookTicketForm.area.value;
				//alert(areafilter);
				var rateid='';
				var areaid='';
				var price='';
				var areas='';
				var rateHotel=new Array();
				var rateindex=0;
				for(var rate=0;rate<amenityHotel.length;rate++)
				{
				rateid='RS.'+amenityHotel[rate];
				areaid='Area.'+amenityHotel[rate];
				price=document.getElementById(rateid).innerHTML;
				areas=document.getElementById(areaid).innerHTML;
				price=parseInt(price.substring(3,price.length));
				if((price>=minrate) && (price <= maxrate))
				{
				if(areafilter=='0')
				{
				rateHotel[rateindex]=amenityHotel[rate];
				rateindex++;
				}
				else if(areafilter==areas)
				{
				rateHotel[rateindex]=amenityHotel[rate];
				rateindex++;
				}			
				}
				}
				amenityHotel.length=0;//To destroy array
				// Rate Slider End 
				for(var displayi=0;displayi<rateHotel.length;displayi++)
				{
				document.getElementById(rateHotel[displayi]).style.display = '';
				}
				//alert(rateHotel);
				if(document.getElementById("matchfound"))
				{
				var size='<b><font color=blue>'+rateHotel.length+' Match Found</font></b>';
				document.getElementById('matchfound').innerHTML=size;
				}
				document.getElementById('sortnav').style.display = '';
				document.getElementById('notfound').style.display = 'none';
				document.getElementById('hotelmap').style.display = '';
				if(rateHotel.length==0)
				{
				document.getElementById('sortnav').style.display = 'none';
				document.getElementById('notfound').style.display = '';
				document.getElementById('hotelmap').style.display = 'none';
				}
				//changes made on 29/01/2009 end 
				if(document.getElementById("pageloadtext"))
				{
				document.getElementById('pageloadtext').innerHTML='';
				}
				allhotel.length=0;//To destroy array
				rateHotel.length=0;//To destroy array
				document.getElementById('filterHotel').innerHTML="";
				document.getElementById('filterHotel').style.display="none";
				return true;
				}//end try
			catch(err)
			{   
				return false;
			}
            }
        }
		var a="www.railtourismindia.com";
        xmlHttp.open("post",a,true);
        xmlHttp.send(null);
}
