/******************************************************************************
 * File name:search_hotel.js
 * Description: This file contains all the validation and javascript functions
 *				related to hotel search functionality 
 *******************************************************************************/
var xmlHttp;
var hotelJSONData;
var indexArray;
var ratingSelectedByUser;
var typeSelectedByUser;
var locationSelectedByUser;
var nameSelectedByUser;
var totalHotelcount;
/***********************************************************************
 * Function Name : show_rating
 * Description   : To display rating stars as user moves the slider
 * Arguments     : None
 * Return values : None
 ***********************************************************************/
function show_rating() {
  var formObj = document.forms[0];
  //get the rating selected by user
  var rating = formObj.rating.value;
  //convert this value in Number format
  var num = new Number(rating);
  rating = num.toFixed(1);
  switch(rating) {
		  case '0.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
			//apply_filter('yatra_rating', (rating/2));  
			return_selected_rating((rating/2));
			break;
		  case '1.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_blue_half.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
			//apply_filter('yatra_rating', (rating/2));  
			return_selected_rating((rating/2));
			break;
		 case '2.0':
			 document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			 document.getElementById('starimg2').src="/images/xhotelv2/star_grey.gif";
			 document.getElementById('starimg3').src="/images/xhotelv2/star_grey.gif";
			 document.getElementById('starimg4').src="/images/xhotelv2/star_grey.gif";
			 document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
			 //apply_filter('yatra_rating', (rating/2));  
			 return_selected_rating((rating/2));
			 break;
		 case '3.0':
			 document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			 document.getElementById('starimg2').src="/images/xhotelv2/star_blue_half.gif";
			 document.getElementById('starimg3').src="/images/xhotelv2/star_grey.gif";
			 document.getElementById('starimg4').src="/images/xhotelv2/star_grey.gif";
			 document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
			 //apply_filter('yatra_rating', (rating/2));  
			 return_selected_rating((rating/2));
			 break;

		case '4.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
			//apply_filter('yatra_rating', (rating/2));  
			return_selected_rating((rating/2));
			break;

		case '5.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_blue_half.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";     
			//apply_filter('yatra_rating', (rating/2));  
			return_selected_rating((rating/2));
		    break;


		case '6.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_grey.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
			//apply_filter('yatra_rating', (rating/2));
			return_selected_rating((rating/2));
			break;

		case '7.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_blue_half.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
			//apply_filter('yatra_rating', (rating/2));
			return_selected_rating((rating/2));
			break;

		case '8.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
			//apply_filter('yatra_rating', (rating/2));
			return_selected_rating((rating/2));
		    break;

		case '9.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_blue_half.gif";
			//apply_filter('yatra_rating', (rating/2));
			return_selected_rating((rating/2));
			break;

		case '10.0':
			document.getElementById('starimg1').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg2').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg3').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg4').src="/images/xhotelv2/star_blue.gif";
			document.getElementById('starimg5').src="/images/xhotelv2/star_blue.gif";
			//apply_filter('yatra_rating', (rating/2));
			return_selected_rating((rating/2));
		    break;
}

}
/***********************************************************************
 * Function Name : set_city_name
 * Description   : To set city name in parent window when user selects 
 *                 any city in find city popup
 * Arguments     : City Name
 * Return values : None
 ***********************************************************************/
 function set_city_name(CityName) {
	 document.getElementById('city').style.color = "#000000";
	 document.getElementById('city').value=CityName;
	document.getElementById('CityValidations').innerHTML="";
	 global_city_found = 1;
	 city_found = 0;

	 document.getElementById('city').focus();
	 
         set_default_advanceparam();
}
/***********************************************************************
 * Function Name : get_advanced_search_fields
 * Description   : Ajax request function for hotel search
 * Arguments     : City Name
 * Return values : None
 ***********************************************************************/
function get_advanced_search_fields(City) {
	var validCity = validate_city_name(City);
	//if city is not valid open find city popup.
	if(validCity == 0 || City =='' ){
		//To set the hotel type,location,name and hotel count as default 
		if(City==''){
			//To set default Adavance search param
			 set_default_advanceparam();
			 return false;
		}
		     
		//Call to find city pop up
		findcity(1);
         
                		
	}else{  
		
        if(City != ""){
  		  xmlHttp=GetXmlHttpObject(); //create xmlHttp request object
		  if(xmlHttp==null){
		 	alert ("Browser does not support HTTP Request");
			return false;
		  }
		 
          //disable the city text field till the xml response is obtained
          document.getElementById('city').disabled=true;		 
		  //server side script 	  
		  var url='/Hotelv2/ajax/get_hotels_incity.html?city='+City; 
		  url=url+'&random='+Math.random();
		  xmlHttp.onreadystatechange=state_changed;
		  xmlHttp.open("GET",url,true);
		  xmlHttp.send(null); //send the request
        } 
	}
}
/***********************************************************************
 * Function Name : state_changed
 * Description   : To handle the ajax response
 * Arguments     : None
 * Return values : None
 ***********************************************************************/
function state_changed(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {

        //enable the city text as reponse is received
        document.getElementById('city').disabled=false;

		var HotelDetails = xmlHttp.responseText;       
        // Any response recevied from server is terminated by character <!---->. This 
        // was causing problem while converting the response into json object. To tackle
        // this, split the response by <!----> and then use first element of the result  
        // which is acutal response
	HotelDetails = HotelDetails.replace(/<!--.*?-->/gi,"");
	HotelDetails = HotelDetails.replace(/\n/gi,"");
        HotelDetails = HotelDetails.replace(/<script(.*)/gi,"");
        HotelDetails = HotelDetails.replace(/<Script(.*)/gi,"");	
        var hotelDataArray = HotelDetails.split('<!---->'); 
        if(hotelDataArray[0] == 0) {
                        document.getElementById('hdFindCityStatus').value=1;
			//Call to find city pop up
			//findcity(1);
			if(document.getElementById('hotelformdiv').style.display != 'none'){
			document.getElementById('city').focus();                 
			}
        }  
        else {
                 document.getElementById('hdFindCityStatus').value=0; 
		//convert JSON string to JSON object  
		hotelJSONData= JSON.parse(hotelDataArray[0]);        
		
         // Commented slier related code as rating slider will not be there in on index page
         //initMoveSliderBack();
		//process JSON object
		process_data(hotelJSONData);
        }
	}
}
/***********************************************************************
 * Function Name : reset_slider
 * Description   : To reset slider position wheneever user changes the city 
                   name
 * Arguments     : None
 * Return values : None
 ***********************************************************************/
function reset_slider(){

      ratingSelectedByUser=null;
      document.getElementById('starimg1').src="/images/xhotelv2/star_grey.gif";
      document.getElementById('starimg2').src="/images/xhotelv2/star_grey.gif";
      document.getElementById('starimg3').src="/images/xhotelv2/star_grey.gif";
      document.getElementById('starimg4').src="/images/xhotelv2/star_grey.gif";
      document.getElementById('starimg5').src="/images/xhotelv2/star_grey.gif";
}

/***********************************************************************
 * Function Name : process_data
 * Description   : To process JSON object for hotels information
 * Arguments     : JSON object containing hotel's information
 * Return values : None
 ***********************************************************************/
function process_data(hotelJSONData){
	//create index array. Initiatlly it will contain all indices of JSON array
    var i;
	indexArray = new Array();   
 
	for(i=0; i< hotelJSONData.length ;i++){
		indexArray[i]=i;           
	}
 
	//update hotel list count
	update_hotel_count(indexArray.length);
	//populate advance search fields
	populate_hotel_type_list(hotelJSONData, indexArray);
}
/***********************************************************************
 * Function Name : populate_hotel_type_list
 * Description   : To populate Hotel Type drop down list based on 
 *                 hotels information
 * Arguments     : JSON object containing hotels information,
				   Index Array containing indices to be used to populate
                   hotel types dropdown   
 * Return values : None
 ***********************************************************************/
function populate_hotel_type_list(hotelJSONData, indexArray){
	var index;
	var hotelTypeArray = new Array();
	var typeIndex;
	//traverse the JSON array for given indices
	for(index=0; index<indexArray.length; index++) {
		var hotel_type = hotelJSONData[indexArray[index]].type; //get the hotel type
		if(typeof hotel_type != 'undefined') {
			var typelist = hotel_type.split('|'); //split the value by | to get individual type:
			var x;
            var flag=false;
			for(x=0; x<typelist.length; x++) {
               //check if type already exists in the hoteltypeArray
               flag = check_in_array(typelist[x],hotelTypeArray);
               if (flag == false)
                 hotelTypeArray.push(typelist[x].toLowerCase()); //Add the new type to the type array
			}
		}   
	}
        hotelTypeArray=hotelTypeArray.sort();
	//create the option list for hotel type
	//var typeOptions="<select name='hotel_type_list' id='HHT' class='dd_advanceOption' multiple='multiple' size='3' OnChange=apply_filter('type',this)>";
    var typeOptions = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"; 
    var row = 0;
	var typeSelectedFlag=0;
	for(typeIndex=0; typeIndex<hotelTypeArray.length; typeIndex++){
		//typeOptions+="<option value='"+hotelTypeArray[typeIndex]+"'>"+hotelTypeArray[typeIndex]+"</option>";
		var setSelectedOption='';
		if(selectedHotelType!=''){
			var selectedHotelTypeArray=new Array();			
			selectedHotelTypeArray=selectedHotelType.split(',');			
			var selectedHotelTypeFlag =check_in_array(hotelTypeArray[typeIndex],selectedHotelTypeArray);
			
			if(selectedHotelTypeFlag==true){	
				setSelectedOption='checked';
				typeSelectedFlag=1;
			}
		}
		
        if(row % 2  == 0)
          typeOptions+="<tr>";
		if(hotelTypeArray[typeIndex]!=''){
			typeOptions+="<td width='4%' align='left'><input type='checkbox' name='hotel_type_list[]' "+setSelectedOption+" onClick=apply_filter('type','hotel_type_list') value='"+hotelTypeArray[typeIndex]+"'></td><td width='45%'>"+uppercase_firstletter(hotelTypeArray[typeIndex])+"</td>";
			row++;
		}
         
        if(row % 2 == 0){
          typeOptions+="</tr>";     
          row = 0; 
        } 
	}
	//typeOptions+="</select>";    
	typeOptions+="</table>";
	
	//set the selected hotel type as ''
	selectedHotelType='';
	//populate the drop down list for hotel type
	document.getElementById('typeDiv').innerHTML=typeOptions;
	//function to populate the location

    //call apply filter if typeSelectedFlag is set to 1
	if(typeSelectedFlag==1){
		apply_filter('type','hotel_type_list');
	}
    //As per discussion on 17th jun 2008 this functionality is removed now
      /*else{
		populate_location_list(hotelJSONData, indexArray);
	}*/
}
/***********************************************************************
 * Function Name : populate_location_list
 * Description   : To populate Hotel location drop down list based on
                   available hotel information
 * Arguments     : JSON object containing hotels information,
				   Index Array containing indices to be used to populate
                   hotel types dropdown   
 * Return values : None
 ***********************************************************************/
function populate_location_list(hotelJSONData, indexArray){
	var index;
	var locationArray = new Array();
	var locIndex;
	//traverse the JSON array for given indices
	for(index=0 ;index<indexArray.length; index++) {
		var location = hotelJSONData[indexArray[index]].location; //get the location
		if(typeof location != 'undefined') {
   		  var locationlist = location.split('|'); //split the value by | to get individual location
		  var x;
		  for(x=0; x<locationlist.length; x++) {
             //check if type already exists in the locationArray
             flag = check_in_array(locationlist[x],locationArray);
             if(flag == false)
               locationArray.push(locationlist[x]);//Add the new location to the location array 		      
             }
		}
	}
        //sort the locationArray
        var locationSortedArray=new Array(); 
        locationSortedArray=locationArray.sort();	
	var locationSelectedFlag=0
	//create the option list for location
	var locOptions="<select name='location_list' id='HHL_1' class='dd_advanceOption' OnChange=apply_filter('location',this)>";
	locOptions+="<option value=''>-- select location --</option>";
	for(locIndex=0; locIndex<locationSortedArray.length; locIndex++) {
		var setSelectedOption='';
		if(locationSortedArray[locIndex]==selectedHotelLocation){	
			setSelectedOption='selected';
			locationSelectedFlag=1;
		
		}
             if(locationSortedArray[locIndex]!=''){
			locOptions+="<option value='"+locationSortedArray[locIndex]+"' "+setSelectedOption+">"+locationSortedArray[locIndex]+"</option>";
		}
	}
	locOptions+="</select>";
	
	
	//set the selected hotel location as ''
	selectedHotelLocation='';
	//populate the drop down list for hotel location
	document.getElementById('locDiv').innerHTML=locOptions;
    if(locationSelectedFlag==1){
		apply_filter('location',document.getElementById('HHL_1'));
	}else{
		populate_hotel_name_list(hotelJSONData, indexArray);
	}
}
/***********************************************************************
 * Function Name : populate_hotel_name_list
 * Description   : To populate Hotel Name drop down list based on
                   available hotel information
 * Arguments     : JSON object containing hotels information,
				   Index Array containing indices to be used to populate
                   hotel names
 * Return values : None
 ***********************************************************************/
function populate_hotel_name_list(hotelJSONData, indexArray){
	  var index;
	  var hotelNameArray = new Array();
	  var nameIndex;
	  //traverse the JSON array for given indices
	  for (index=0; index<indexArray.length; index++) {
		  var hotelname = hotelJSONData[indexArray[index]].hotel_name; //get the location
		  if(typeof hotelname != 'undefined') {
            //check if name already exists in the hotelNameArray
            flag = check_in_array(hotelname,hotelNameArray);
            if (flag == false) 
			hotelNameArray.push(hotelname); //Add the new location to the location array
		}
	}
    //sort the hotelNameArray to display sorted list 
    hotelNameArray=hotelNameArray.sort();
	//create the option list for location	
	var nameOptions="<select name='hotel_name_list' id='HHN' class='dd_advanceOption' OnChange=apply_filter('name',this)>";
	nameOptions+="<option value=''>-- select hotel name --</option>";
	for(nameIndex=0; nameIndex<hotelNameArray.length; nameIndex++) {
		var setSelectedOption='';
		if(hotelNameArray[nameIndex]==selectedHotelName){	
			setSelectedOption='selected';
		}
		nameOptions+="<option value='"+hotelNameArray[nameIndex]+"' "+setSelectedOption+">"+hotelNameArray[nameIndex]+"</option>";
		
	}
	nameOptions+="</select>";
	//set the selecte hotel name as ''
	selectedHotelName='';
      
	//populate the drop down list for hotel name
	document.getElementById('nameDiv').innerHTML=nameOptions;
	//update hotel list count 
        totalHotelCount=indexArray.length;
	update_hotel_count(indexArray.length);
}

/***********************************************************************
 * Function Name : apply_filter
 * Description   : To apply filter based on hotel rating, type and 
                   location     
 * Arguments     : modified filed name and field object
 * Return values : None
 ***********************************************************************/
function apply_filter(fieldName,fieldObject){
	var index;
	var i;
	if(typeof indexArray != 'undefined'  && indexArray.length > 0){
		switch(fieldName) {
			/*case 'yatra_rating':
				var filteredIndexArray = new Array();
				//iterate JSON array to check the selected rating
				for (index=0; index <indexArray.length; index++){
					var rating = hotelJSONData[indexArray[index]].yatra_rating;
					ratingSelectedByUser=fieldObject;
					if(rating <= ratingSelectedByUser) {
						filteredIndexArray.push(index);
					}
				}
				//populate the drop down list for hotel type
				populate_hotel_type_list(hotelJSONData, filteredIndexArray);
				break;*/
			case 'type': 
				var filteredIndexArray = new Array();
				typeSelectedByUser=getCheckedTypes();
				//iterate JSON array to check the selected type
				for(index=0; index <indexArray.length; index++){
					var type = hotelJSONData[indexArray[index]].type;
					//var rating = hotelJSONData[indexArray[index]].yatra_rating;
					if(typeof type != 'undefined') {
						type = type.toLowerCase();
						var typeFound=false;
						//var ratingFound = true;
						for (i=0; i<typeSelectedByUser.length; i++) {
							if(type.indexOf(typeSelectedByUser[i].toLowerCase()) != -1){
								typeFound=true;
							}							

						}
                           
						/*check if user has selected any rating if yes, check if it 
						  matches with the hotels rating*/
                        //comment rating related code as slider will not be there on index page
                        /*
					 	if (ratingSelectedByUser != null) {
							if(rating > ratingSelectedByUser)
								ratingFound = false;
						}*/
						/*if type matches with the hotes rating and type
						  add it to filteredIndexArray*/
						if (typeFound == true || typeSelectedByUser.length==0){							
                  					filteredIndexArray.push(index);
                                          }
					}
				}          
				//populate the drop down list for hotel location
                            //As per discussion on 17th jun 2008 this functionality is removed now.
				//populate_location_list(hotelJSONData, filteredIndexArray);
                            //Update hotel count
                            update_hotel_count(filteredIndexArray.length);
				break;
		  case 'location':
			  var filteredIndexArray = new Array();
			  locationSelectedByUser=getOptions(fieldObject);
             		  typeSelectedByUser=getCheckedTypes();
			  for(index=0; index <indexArray.length; index++){
				  var location = hotelJSONData[indexArray[index]].location;
				  var type = hotelJSONData[indexArray[index]].type;
				  if(typeof location != 'undefined') {
					  location = location.toLowerCase();
					  var locFound=true;
					  var typeFound = true;
					  //var ratingFound = true;
					  for(i=0; i<locationSelectedByUser.length; i++){
                                                  
						  if (location.indexOf(locationSelectedByUser[i].toLowerCase()) == -1)
							  locFound = false;
						  else
							  continue;
					  }
					  /*check if user has selected any type if yes, check if it
						matches with the hotels type*/
					 if(typeof typeSelectedByUser != 'undefined' && typeSelectedByUser!='') {
                                                type=type.toLowerCase();   
						for(i=0; i<typeSelectedByUser.length; i++) {
							if(type.indexOf(typeSelectedByUser[i].toLowerCase()) == -1)
								typeFound = false;
							else
								continue;
						}
					}                   
                  /*check if user has selected any rating if yes, check if it
                   matches with the hotels rating*/
                  /*if(ratingSelectedByUser!= null) {
                    if(rating > ratingSelectedByUser)
                      ratingFound = false;
                  }*/
				  /*if rating type and location matches with the hotes rating, type
					and location, add it to filteredIndexArray*/
                  		if(locFound == true && typeFound == true)
                    			filteredIndexArray.push(index);
			}
		}
			//populate the drop down list for hotel name
			populate_hotel_name_list(hotelJSONData, filteredIndexArray);
			break;
		  case 'name':                    
                	if(fieldObject.value==''){
				update_hotel_count(totalHotelCount);
			}else{
               			 nameSelectedByUser=getOptions(fieldObject); 
                		//update hotel count based on number of hotels selected                			
                		update_hotel_count(nameSelectedByUser.length);
			}
                break;
		}
	}
}
/***********************************************************************
Function Name : check_in_array
Description   : To check if particular value exists in the input 
                array
Input         : value to lookup in array, lookup Array
Output        : true if value exists in lookup array else false
************************************************************************/
function check_in_array(lookupValue, lookupArray) {
  var y;
  for (y=0; y<lookupArray.length; y++) {
      if (lookupValue.toLowerCase() == lookupArray[y].toLowerCase())
      return true;
  }
  return false;
}
/***********************************************************************
 * Function Name : getOptions
 * Description   : To get all selected options in select box
 * Arguments     : select box field object
 * Return values : Array containing all selected values
 ***********************************************************************/
function getOptions(sel){
  var opts = new Array();
  for(i=0; i<sel.length; i++) {
      if (sel.options[i].selected && sel.options[i].value != '0') {
         opts.push(sel.options[i].value);
      }
   }
  return opts;
}

/***********************************************************************
 * Function Name : getCheckedTypes
 * Description   : To get all checked hotel types
 * Arguments     : check box field names
 * Return values : Array containing all checked values
 ***********************************************************************/
function getCheckedTypes(){
  var el = document.getElementsByName('hotel_type_list[]');
  var opts = new Array();
  for(i=0; i<el.length; i++) {
      if (el[i].checked == true) {
         opts.push(el[i].value);
      }
   }
  return opts;
}

/***********************************************************************
 * Function Name : update_hotel_count
 * Description   : To update hotels count
 * Arguments     : count
 * Return values : None
 ***********************************************************************/
function update_hotel_count(count){
	if(count==1)
		//comment as per requirement change
		//document.getElementById('hotelCount').innerHTML="<span class=\"totalhotels\">"+count+"</span><br/>Hotel listed";
		document.getElementById('hotelCount').innerHTML="";
	else
		//document.getElementById('hotelCount').innerHTML="<span class=\"totalhotels\">"+count+"</span><br/>Hotels listed";
		document.getElementById('hotelCount').innerHTML="";
}

/***********************************************************************
 * Function Name : listview and mapview
 * Description   : To Change Image on click
 * Return values : None
 ***********************************************************************/
function listview(){
	document.getElementById('listviewbtn').src='/images/xhotelv2/srv_tab_listview_hover.gif';
	document.getElementById('mapviewbtn').src='/images/xhotelv2/srv_btn_mapview_normal.gif';	
}
function mapview(){
	document.getElementById('listviewbtn').src='/images/xhotelv2/srv_tab_listview_normal.gif';
	document.getElementById('mapviewbtn').src='/images/xhotelv2/srv_btn_mapview_hover.gif';	
}
/***********************************************************************
 * Function Name : default_hotel_type
 * Description   : To set the HTML string for hotel type
 * Arguments     : None
 * Return values : HTML string for hotel type
 ***********************************************************************/
function default_hotel_type(){
	var str='';
	str="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
	str+="<tr><td><input type=\"checkbox\" name=\"business\" checked DISABLED/>Business Hotel</td>";
	str+="<td><input type=\"checkbox\" name=\"resort\" checked DISABLED/>Resort</td>";
	str+="</tr><tr><td><input type=\"checkbox\" name=\"BB\" checked DISABLED/>Family</td>";
	str+="<td><input type=\"checkbox\" name=\"luxury\" checked DISABLED/>Luxury</td></tr>";
	str+="</table>";
	return str;
}
/***********************************************************************
 * Function Name : default_hotel_location
 * Description   : To set the HTML string for hotel location
 * Arguments     : none
 * Return values : HTML string for hotel location
 ***********************************************************************/
function default_hotel_location(){
	var str='';
	str="<select name=\"location_list\" id=\"HHL\" DISABLED>";
	str+="<option value='' selected>-- select location --</option><option></option>";
	str+="</select>";
	return str;
	

}
/***********************************************************************
 * Function Name : default_hotel_name
 * Description   : To set the HTML string for hotel name
 * Arguments     : none
 * Return values : HTML string for hotel name
 ***********************************************************************/
function default_hotel_name(){
	var str='';
	str="<select name=\"hotel_name_list\" id=\"HHN\" DISABLED>";
	str+="<option value='' selected>-- select hotel name --</option></select>";
	return str;
}
/***********************************************************************
 * Function Name : set_advance_searchparam
 * Description   : To set the Advance search parameter
 * Arguments     : none
 * Return values : 
 ***********************************************************************/
function set_advance_searchparam(){
	//set the hdhoteltype variable with current checked hotel types
	document.getElementById('hdhoteltype').value='';
	var hotelTypes=getCheckedTypes();	
	if(hotelTypes!=''){
	    document.getElementById('hdhoteltype').value=hotelTypes;
	}   
   //set the hdhotellocation variable with current selected location list
	var locationList=document.getElementsByName('location_list');
	for(i=0; i<locationList.length; i++) {    
		 document.getElementById('hdhotellocation').value=locationList[i].value;
	 }
   
  //set the hdhotellocation variable with current selected hotel name
  var hotelNameList=document.getElementsByName('hotel_name_list');
  for(i=0; i<hotelNameList.length; i++) {	 
	document.getElementById('hdhotelname').value=hotelNameList[i].value;	  
  }
  if(document.getElementById('hdFindCityStatus').value==1){
	return false;
  }else{
  	return true;
  }
 
}
/***********************************************************************
 * Function Name : set_booking_details
 * Description   : To set the booking details as user selected on index page
				   from index page
 * Arguments     : city,cidate,codate,broadbandconnection
 * Return values : 
 ***********************************************************************/
function set_booking_details(city,cidate,codate,broadband,isseo){
    if(!isseo){
	//set the hotel form header
    document.getElementById('findhotelhead').innerHTML='<div style=\"width:174px;float:left;\"><h1>	Modify Your Search</h1></div><div style=\"width:25px;float:right;\"><span id=\"msplus\" style=\"display:\"><a href=\"javascript:modifySearch(\'hotelformdiv\');\" style=\"color:#ffffff;font-size:14px;font-weight:bold;text-decoration:none;\">[+]</a></span><span id=\"msminus\" style=\"display:none\"><a href=\"javascript:modifySearch(\'hotelformdiv\');\" style=\"color:#ffffff;font-size:14px;font-weight:bold;text-decoration:none;\">[&ndash;]</a></span></div>';
	//hide the modify search component
	document.getElementById('hotelformdiv').style.display='none'; 
	}
	//set the city name
	document.getElementById('city').value=city;	
	//To set the check in date
	document.getElementById('cidate').value=cidate;
	//To set the check out date 
	document.getElementById('codate').value=codate;
	//To set the broadband connection radio button as per user checked on index page
	//if(broadband=='Yes')
		//document.hotelform.radiobutton[0].checked=true;
	//else
		//document.hotelform.radiobutton[1].checked=true;
}
/***********************************************************************
 * Function Name : set_guest_details
 * Description   : To set the guest detail parameter as per user selected 
				   from index page
 * Arguments     : cidate,codate
 * Return values : 
 ***********************************************************************/
function set_guest_details(noOfRoom,adult1,chdroom1,adult2,chdroom2,adult3,chdroom3,adult4,chdroom4,chdAge1_1,chdAge1_2,
	chdAge2_1,chdAge2_2,chdAge3_1,chdAge3_2,chdAge4_1,chdAge4_2){
	//To set the Guest details    
	document.hotelform.room.options[noOfRoom-1].selected = true;
	document.hotelform.adt1.options[adult1-1].selected = true;
	document.hotelform.chdroom1.options[chdroom1].selected = true;
 	if(chdAge1_1!='')
		document.hotelform.adt1_chdage1.options[chdAge1_1].selected = true;
	if(chdAge1_2!='')
		document.hotelform.adt1_chdage2.options[chdAge1_2].selected = true;
       
      if(noOfRoom>1){
		document.hotelform.adt2.options[adult2-1].selected = true;
		document.hotelform.chdroom2.options[chdroom2].selected = true;
		if(chdAge2_1!='')
			document.hotelform.adt2_chdage1.options[chdAge2_1].selected = true;
		if(chdAge2_2!='')
			document.hotelform.adt2_chdage2.options[chdAge2_2].selected = true;
       }
       if(noOfRoom>2){
		document.hotelform.adt3.options[adult3-1].selected = true;
		document.hotelform.chdroom3.options[chdroom3].selected = true;
		if(chdAge3_1!='')
			document.hotelform.adt3_chdage1.options[chdAge3_1].selected = true;
		if(chdAge3_2!='')
			document.hotelform.adt3_chdage2.options[chdAge3_2].selected = true;
	}
	if(noOfRoom>3){
		document.hotelform.adt4.options[adult4-1].selected = true;
		document.hotelform.chdroom4.options[chdroom4].selected = true;
		if(chdAge4_1!='')
			document.hotelform.adt4_chdage1.options[chdAge4_1].selected = true;
		if(chdAge4_2!='')
			document.hotelform.adt4_chdage2.options[chdAge4_2].selected = true;                         
	}
	//call to childAge display function
	SetupAdultChildDiv();
	
}
/***********************************************************************
 * Function Name : set_default_advanceparam()
 * Description   : To set default advance parameter
 * Arguments     : 
 * Return values : 
 ***********************************************************************/
function set_default_advanceparam(){

	strDefaultHotelType=default_hotel_type();
       //As per discussion on 17th jun this functionality is removed now. 
	//strDefaultHotelLocation=default_hotel_location();
	//strDefaultHotelName=default_hotel_name();
	document.getElementById('typeDiv').innerHTML=strDefaultHotelType;
	//document.getElementById('locDiv').innerHTML=strDefaultHotelLocation;
	//document.getElementById('nameDiv').innerHTML=strDefaultHotelName;
	//document.getElementById('hotelCount').innerHTML="<span class=\"totalhotels\">0</span><br />Hotels listed";
	document.getElementById('hotelCount').innerHTML="";
}
/**************************************************************************************
 * Function Name : modifySearch
 * Description   : This function is use for hide and block the modify search form
 * Arguments     : divid
 * Return values : 
 ***************************************************************************************/
function modifySearch(divId){
	divId = document.getElementById(divId);
	if(divId.style.display == 'none'){
		divId.style.display = 'block';
		document.getElementById('msplus').style.display='none';
		document.getElementById('msminus').style.display='';
		if(document.getElementById('resultbox')){
			document.getElementById('resultbox').style.height='253px';
		}
	}else{
		divId.style.display = 'none';
		document.getElementById('msplus').style.display='';
		document.getElementById('msminus').style.display='none';
		if(document.getElementById('resultbox')){
			document.getElementById('resultbox').style.height='523px';
		}
    }
 }

/***********************************************************************
 * Function Name : price_grid
 * Description   : To display price grid of a room basis on nightl rate
 * Arguments     : Object Of NightlyRate
 * Return values : grid row
 ***********************************************************************/
function price_grid(nr, st, dur) {
	var avgst = (st/dur);
	var str = "<tr>";
	var toggle=false;
	for (var d=1; d<=dur; d++) {
		var bg_class = toggle?'whitebg':'greybg';
		toggle ^= 1;

		if(d==8 || d==15){ str += "<tr>"; } 
		if(d==1 && dur>=7){ str += "<td id=\"whitebg\">Wk<br/> 1</td>"; }
		if(d==8 && dur>7){ str += "<td id=\"whitebg\">Wk<br/> 2</td>"; }
		if(nr && nr[d]){
		str += "<td id=\""+bg_class+"\">Rs.<br/>"+(parseInt(nr[d])+parseInt(avgst))+"</td>";
		}
	}
	str += "</tr>";
	return str;
}
