﻿///*-------------------------------------------------------------*/
// JScript File - AdvancedSearch.js, 
/* Nafis Sadykov on 11.03.2007 */

function ShowLocationRows(visible)
{
  var el;
  if (visible)
  {
    cssname = "trVisibleRow";
  }
  else
  {
    cssname = "trHiddenRow";  
  }
  
  el = document.getElementById(trCity_ID);
  el.className = cssname;  
  
  el = document.getElementById(trLocation_ID);
  el.className = cssname; 
  
  el = document.getElementById(trPropertyType_ID);
  el.className = cssname;     
}

function IsByNameTabActive()
{
  var res, el = document.getElementById(trHotelName_ID);
  res = el.className == "trVisibleRow";
  return res;
}

function ShowHotelNameRow(visible)
{
  var el;
  if (visible)
  {
    cssname = "trVisibleRow";
  }
  else
  {
    cssname = "trHiddenRow";  
  }
  
  el = document.getElementById(trHotelName_ID);
  el.className = cssname;
}

function ByLocationTabClicked()
{
  ShowLocationRows(true);
  ShowHotelNameRow(false);
  
  var el;

  el = document.getElementById(lblSearchByLocation_ID);
  el.className = "lblActiveTab";  
  el = document.getElementById(tdByLocationTab_ID);
  el.className = "tdActiveTab";
  
  el = document.getElementById(lblSearchByHotelname_ID);
  el.className = "lblInactiveTab";  
  el = document.getElementById(tdByNameTab_ID);
  el.className = "tdInactiveTab";
  
  el = document.getElementById(hfSearchBy_ID);
  el.value = search_by_location;           
}

function ByNameTabClicked()
{
  ShowLocationRows(false);
  ShowHotelNameRow(true);
  
  var el;

  el = document.getElementById(lblSearchByLocation_ID);
  el.className = "lblInactiveTab";  
  el = document.getElementById(tdByLocationTab_ID);
  el.className = "tdInactiveTab";
  
  el = document.getElementById(lblSearchByHotelname_ID);
  el.className = "lblActiveTab";  
  el = document.getElementById(tdByNameTab_ID);
  el.className = "tdActiveTab";  
  
  el = document.getElementById(hfSearchBy_ID);
  el.value = search_by_name;  
  
  el = document.getElementById(edtHotelName_ID);
  el.focus();
  //el.select();  
}

function ValidateForm()
{
  res = false;
  var searchByName, el; 
  el = document.getElementById(hfSearchBy_ID);
  searchByName = el.value == search_by_name;

  if (searchByName)
  {
    el = document.getElementById(edtHotelName_ID);
    var name = trim(el.value); 
    if (name.length < MinNameLength)
    {
  	  alert("Minimum of " + MinNameLength + " characters is required to search on the Hotel Name!");
      el.focus();
      el.select();
      return res;    
    }
  }
  
  res = true;
  return res;
}

function OnCityComboChanged(Combo)
{
  if (Combo.value != CitiesSeparator)
  {
    __doPostBack(Combo.id, '');
    EnableControls(false);
  }
  else
  {
    Combo.value = LastCity;
  }
}

function OnCityComboFocus(Combo)
{
  LastCity = Combo.value;
}

function EnableControls(enable)
{
  var el, option;
  var disable = !enable;
  el = document.getElementById(btnSearch_ID);
  el.disabled=disable;
  el = document.getElementById(cbCity_ID);
  el.disabled=disable;   
  el = document.getElementById(cbLocation_ID);
  if (disable) 
  {
    option = new Option("...Loading...", "loading", true, true);
    //el.add(option, 0); // this one only works with IE
    el.options[0] = option;
  }
  el.disabled=disable; 
}

function InDateChanged(combo)
{
  CalculateDays(true);
}

function OutDateChanged(combo)
{
  CalculateDays(false);
}

function CalculateDays(InDateChanged)
{
  var res;
  var cbIn = document.getElementById(cbCheckInDate_ID);
  var cbOut = document.getElementById(cbCheckOutDate_ID);  
  
  if (InDateChanged)
  {
    if (cbIn.selectedIndex > cbOut.selectedIndex)  
    {
      cbOut.selectedIndex = cbIn.selectedIndex;
    }  
  }
  else
  {
    if (cbIn.selectedIndex > cbOut.selectedIndex)  
    {
      cbIn.selectedIndex = cbOut.selectedIndex;
    }
  }  
  
  var lblWeekDayIn = document.getElementById(lblWeekDayIn_ID);
  //lblWeekDayIn.innerHTML = cbIn.options[cbIn.selectedIndex].value;  
  
  var dateIn = new Date(cbIn.options[cbIn.selectedIndex].value);
  lblWeekDayIn.innerHTML = "( "+GetDayOfTheWeekString(dateIn.getDay())+" )";
  
  var lblWeekDayOut = document.getElementById(lblWeekDayOut_ID);
  //lblWeekDayOut.innerHTML = cbOut.options[cbOut.selectedIndex].value;  
  
  var dateOut = new Date(cbOut.options[cbOut.selectedIndex].value);
  lblWeekDayOut.innerHTML = "( " + GetDayOfTheWeekString(dateOut.getDay())+" )";  
  
  res = cbOut.selectedIndex - cbIn.selectedIndex + 1;
  
  var lblTotalNights = document.getElementById(lblTotalNights_ID);  
  lblTotalNights.innerHTML = res;
}

function GetDayOfTheWeekString(weekDay)
{
  var res = "";
  switch (weekDay)
  {
    case 0:
      res = "Sun"; 
      break;
    case 1:
      res = "Mon";      
      break;
    case 2:
      res = "Tue";      
      break;
    case 3:
      res = "Wed";      
      break;
    case 4:
      res = "Thu";      
      break;
    case 5:
      res = "Fri";
      break;
    case 6:
      res = "Sat";
      break;                                            
  }
  
  return res;
}

function trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function
/*-----------------------------------------------------------------------------------*/  

