//Hotel Filter code(Deepak Singh)
function hotelfilter()
{   
     if(document.getElementById("pageloadtext"))
       {
           document.getElementById('pageloadtext').innerHTML='<img src="/hotel/Media/images/loadinghoteldetails.gif" style="width:20px;height:20px;" align="absmiddle"><b>We are searching for the best hotel deals as per your specific requirement,Please wait...</b>';
       }
    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++;
				}
			}	
			/*
				for (k=0; k<document.BookTicketForm.indstarrating.length; k++)
				{
					if (document.BookTicketForm.indstarrating[k].checked==true)
					{
						star=document.BookTicketForm.indstarrating[k].value;

                        try
						{   for(var stari=0;stari<allhotel.length;stari++)
                            {
                                if(star==parseInt(allhotel[stari].charAt(0)))
                                {
                                ratinghotels[ratingindex]=allhotel[stari];
                                ratingindex++;
                                }
                            }
                        }
						catch(err)
						{

                        }
					}
				}
			//alert('hi11');
			*/
			

            //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 = '';
            }

            if(document.getElementById("matchfound"))
            {
                    var size='<b><font color=blue>'+rateHotel.length+' Match Found</font></b>';
                    document.getElementById('matchfound').innerHTML=size;
            }
			document.getElementById('sortid').style.display = '';
			document.getElementById('notfound').style.display = 'none';
			if(rateHotel.length==0)
            {
             document.getElementById('sortid').style.display = 'none';
			 document.getElementById('notfound').style.display = '';
            }
            //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

           return true;
        }//end try
		catch(err)
		{   
            return false;
		}

  }