﻿// START Common

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function toggleDivByCheckbox( divId, checkBoxId)
{
  var divObj = document.getElementById(divId);
  var checkBoxObj = document.getElementById(checkBoxId);
  if (checkBoxObj.checked)
  {
    divObj.style.display = '';
  }
  else
  {
    divObj.style.display = 'none';
  }
}

function setElementPermanentPosition()
{
  var winW = 630, winH = 460;
  
  if (parseInt(navigator.appVersion)>3) {
  if (navigator.appName=="Netscape") {
    winW = window.innerWidth;
    winH = window.innerHeight;
  }
  if (navigator.appName.indexOf("Microsoft")!=-1) {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;
  }
  }
}

// END Common


//function dontCloseMe(evt)
//{
//  evt.cancelBubble = true;
//  if (evt.returnValue) evt.returnValue = false;
//  if (evt.stopPropagation) evt.stopPropagation();
//  return false;
//}

// START DepartureAirportBox

function AirportChange(aDepartureAirportExtendedDiv, aMostUsedAirportDropdown, aAlternativeAirportDiv)
{
  var obj = document.getElementById(aDepartureAirportExtendedDiv);
  if (obj == undefined) return;
  var alternative = document.getElementById(aAlternativeAirportDiv);
  var dropDown = document.getElementById(aMostUsedAirportDropdown);
  var value = dropDown.options[dropDown.selectedIndex].value;
  if (obj)
  {
    if (value == '-1')
    {
      obj.style.display = 'block';
    }  
    else
    {
       obj.style.display = 'none';
    }
  }
  if (alternative)
  {
    if (value.length > 3)
    {
      alternative.style.display = 'none';
    }
    else
    {
      alternative.style.display = 'block';
    }
  }
}

function AlternativeChange(flip, aAlternativeExtendedDiv, aAlternativeVisible)
{
  var obj = document.getElementById(aAlternativeExtendedDiv);
  if (obj == undefined) return;
  var hid = document.getElementById(aAlternativeVisible);
  var value = hid.value;          
  if (flip == 1)
  {
    value = (value == 1 ? 0 : 1);
    hid.value = value;
  }
  
  if (obj)
  {
    if (value == 1)
    {
     
      obj.style.display = 'block';

    }  
    else
    {
       obj.style.display = 'none';
    
    }
  }
}

// END DepartureAirportBox


// START StayLengthBox

function StayLengthUpdate()
{
}

// END StayLengthBox

// START FlightSearchResultBox
function ExpandFlightSearchResultRow(expandCheckBox, collapsedRow, expandedRow)
{
    if(navigator.appName == "Microsoft Internet Explorer")
	  {//"block"
	      window.document.getElementById(expandedRow).style.display = "block";
	  }
	  else
	  {//"table-row"
	      window.document.getElementById(expandedRow).style.display = "table-row";
	  }
	  window.document.getElementById(collapsedRow).style.display = "none"
	  window.document.getElementById(expandCheckBox).checked = false;
}

function CollapseFlightSearchResultRow(collapseCheckBox, collapsedRow, expandedRow)
{
    if(navigator.appName == "Microsoft Internet Explorer")
	  {//"block"
	      window.document.getElementById(collapsedRow).style.display = "block";
	  }
	  else
	  {//"table-row"
	      window.document.getElementById(collapsedRow).style.display = "table-row";
	  }
	  window.document.getElementById(expandedRow).style.display = "none"
	  window.document.getElementById(collapseCheckBox).checked = true;
}
// END FlightSearchResultBox

// START FlightSearchResultForm
function ExpandAllFlightResults()
{
    if(expandedItems != undefined && collapsedItems != undefined)
    {
        for(index in expandedItems)
        {
            if(navigator.appName == "Microsoft Internet Explorer")
	          {//"block"
	              window.document.getElementById(expandedItems[index]).style.display = "block";
	          }
	          else
	          {//"table-row"
	              window.document.getElementById(expandedItems[index]).style.display = "table-row";
	          }
        }
        for(index in collapsedItems)
        {
	          window.document.getElementById(collapsedItems[index]).style.display = "none"
        }
    }
}

function CollapseAllFlightResults()
{
    if(expandedItems != undefined && collapsedItems != undefined)
    {
        for(index in collapsedItems)
        {
            if(navigator.appName == "Microsoft Internet Explorer")
	          {//"block"
	              window.document.getElementById(collapsedItems[index]).style.display = "block";
	          }
	          else
	          {//"table-row"
	              window.document.getElementById(collapsedItems[index]).style.display = "table-row";
	          }
        }
        for(index in collapsedItems)
        {
	          window.document.getElementById(expandedItems[index]).style.display = "none"
        }
    }
}

function ToggleAllFlightResults(toggleCheckBox)
{
    if(window.document.getElementById(toggleCheckBox).checked == true)
    {
        ExpandAllFlightResults();
    }
    else
    {
        CollapseAllFlightResults();
    }
}
// END FlightSearchResultForm

// START DatePicker
function CalendarOpenNew(fram, d, m) 
{
  dv = document.getElementById(d).value; 
  mv = document.getElementById(m).selectedIndex;
  document.getElementById(fram).src = 'calendar.aspx?dv='+dv+'&mv='+mv+'&d='+d+'&m='+m;
  return false;
}
// END DatePicker

//START Accomodation Criteria

function ShowNRooms(dropdownId)
{
  var element = document.getElementById(dropdownId + "_RoomsNumberDropDown");
  if (element == undefined) return;
  var selected = element.value;
     
  var i;
  
  for(i = 1; i <= selected ; i++)
  {
    document.getElementById(dropdownId + "_Room" + i).style.display = "block";
    document.getElementById(dropdownId + "_Room" + i).style.visibility = "visible";
  }
  
  for(; i <= 4 ; i++){
    document.getElementById(dropdownId + "_Room" + i).style.display = "none";
    document.getElementById(dropdownId + "_Room" + i).style.visibility = "hidden";
  }
} 

function ShowNRooms2(numberDropDownId, dropdownId1, dropdownId2, dropdownId3, dropdownId4)
{
  var element = document.getElementById(numberDropDownId);
  if (element == undefined) return;
  var selected = element.value;
     
	document.getElementById(dropdownId1).style.display = "block";
  document.getElementById(dropdownId1).style.visibility = "visible";
  
	document.getElementById(dropdownId2).style.display = (selected >= 2 ? "block" : "none");
  document.getElementById(dropdownId2).style.visibility = (selected >= 2 ? "visible" : "hidden");
  
  document.getElementById(dropdownId3).style.display = (selected >= 3 ? "block" : "none");
  document.getElementById(dropdownId3).style.visibility = (selected >= 3 ? "visible" : "hidden");
  
  document.getElementById(dropdownId4).style.display = (selected >= 4 ? "block" : "none");
  document.getElementById(dropdownId4).style.visibility = (selected >= 4 ? "visible" : "hidden");
} 

//END Accomodation Criteria

// START PopUpWindow
function PopUpWindow(ObjectIdText,ObjectIdHidden,PopUpUrl,SearchTarget) 
{
   window.open(PopUpUrl+'?ObjectID1='+ ObjectIdText +'&ObjectID2=' + ObjectIdHidden + '&SearchTarget=' + SearchTarget,'','toolbar=0,menubar=0,location=0,scrollbars=1,width=450,height=500');
}

function PopUpWindowSeatMap(PopUpUrl,FlightNumber) 
{
   window.open(PopUpUrl+'?FlightNum='+ FlightNumber,'','toolbar=0,menubar=0,location=0,scrollbars=1,width=735,height=600');
}

function PopUpWindowBasic(PopUpUrl) 
{
   window.open(PopUpUrl,'','toolbar=0,menubar=0,location=0,scrollbars=1,width=450,height=550');
}

function PopUpWindowWithSizeAndLoc(PopUpUrl,Top,Left,width,height) 
{
   window.open(PopUpUrl,'','toolbar=0,menubar=0,location=0,scrollbars=1,left='+Left+',top='+Top+',width='+width+',height='+height+'\'');
}

function PopUpWindowWithSize(PopUpUrl,width,height) 
{
   window.open(PopUpUrl,'','toolbar=0,menubar=0,location=0,scrollbars=1,width='+width+',height='+height+'\'');
}

function PopDownWindow(ParentWindowObjectID1,value1,ParentWindowObjectID2,value2)
{
   window.opener.document.getElementById(ParentWindowObjectID1).value = value1;
   window.opener.document.getElementById(ParentWindowObjectID2).value = value2;
   window.close();
}

// END PopUpWindow

// START AlwaysVisiblePanel
function SetMenuOffset(ObjectID,TopStartUpPosition,WaitScrollOffset) 
{ 
   var alwaysVisiblePanel = document.getElementById(ObjectID);
      alwaysVisiblePanel.style.position = 'absolute';
   
	 if (!alwaysVisiblePanel) 
	    return;
	   
	 var currentOffset = document.documentElement.scrollTop || document.body.scrollTop;
	
	 if(currentOffset > TopStartUpPosition && currentOffset > WaitScrollOffset)
	 {
	    alwaysVisiblePanel.style.top = currentOffset - WaitScrollOffset + 5 + 'px';
//	    alwaysVisiblePanel.style.top = currentOffset + 'px';
	 }
	 else
	 {
	    alwaysVisiblePanel.style.top = TopStartUpPosition + 'px';
	 }
}
// END AlwaysVisiblePanel

// START PriceControlItem

function SwitchImage(ImageID,ImgUrl)
{
   document.getElementById(ImageID).src = ImgUrl;
}

// END PriceControlItem

// temp

function GetDiscountPrices(handlerUrl,objId)
{
var xmlHttp;
try
  {
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//      document.write(xmlHttp.responseText);
        document.getElementById(objId).innerHTML = xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET",handlerUrl, true);
  xmlHttp.send(null);
  }
  
 
// hides ajax popup
// id - clientID popup extendera (nie divu)
function hideModalPopupViaClientID(id) {
  var modalPopupBehavior = $find(id);
  modalPopupBehavior.hidePopup(); 
  return false;
}

function isPageValid()
{
  return (typeof(ValidatorOnSubmit) == 'function' && ValidatorOnSubmit() == true);
}

function trackPageView(page)
{
  if (window._gat != undefined && window.pageTracker != undefined) 
  { 
	  pageTracker._trackPageview(page); 
	}
	else 
	{
	  if (window.urchinTracker != undefined)
	  {
	    urchinTracker(page);
	  }
	}
}

 function MakeLegendInvisible(objectId) 
{
   document.getElementById(objectId).style.display = 'none';
}
 function MakeLegendInvisible2(objectId) 
{
   document.getElementById(objectId).style.visibility = 'hidden';
}
function MakeLegendVisible(objectId) 
{
   document.getElementById(objectId).style.display = 'block';
}

function checkExactDays()
{
  onlyExactDays=false;
  filterFlightTariffs();
}


//START scrollable articles
function ScrollUp(scrollStep,objID)
{
  if(ArticleScrollPosition > MaxScrollValue)
  {
   ArticleScrollPosition -= scrollStep;
   document.getElementById(objID).style.top =  ArticleScrollPosition + 'px';
  }
}

function ScrollDown(scrollStep,objID)
{
  if(ArticleScrollPosition < 0)
  {
     ArticleScrollPosition += scrollStep;
   document.getElementById(objID).style.top = ArticleScrollPosition + 'px';
}
}

function StopScroll()
{
 clearTimeout(sleepTime);
} 

function StopScrollUp()
{
 scrollUpwards = 0;  
 StopScroll();
}

function StartScrollUp()
{
 scrollUpwards = 1;
 TimedArticleListScroll();         
}

function StopScrollDown()
{
 scrollDownwards = 0;  
 StopScroll();
}

function StartScrollDown()
{
 scrollDownwards = 1;
 TimedArticleListScroll();         
}
//END scrollable articles

function DisableOffsetCalendarMonths(calendarDropDown, shift)
{
  for(n=0;n<calendarDropDown.options.length;n++)
  {
    if(shift > n)
      calendarDropDown.options[n].disabled = true;                  
  }  
}
function EnableOffsetCalendarMonths(calendarDropDown)
{
  for(n=0;n<calendarDropDown.options.length;n++)
  {
    calendarDropDown.options[n].disabled = false;                  
  }  
}

//START kalendariky - pomocne skripty
function updateOffsets(newDate, offsetValue, offsetControl2MonthDropDown, offsetControl2DayBox, offsetControlMonthDropDown, offsetControlDayBox, StayLengthOtherDatePicker_DayBox, StayLengthOtherDatePicker_MonthDropDown, DayBox, MonthDropDown, stayLengthDropDown)
{
if (offsetControl2MonthDropDown != '' )
{
var calendarDate = newDate;
var d = new Date();
var shift = calendarDate.getMonth() - d.getMonth() + (calendarDate.getFullYear() - d.getFullYear())*12 ; 
var shiftControl = document.getElementById(offsetControl2MonthDropDown);
shiftControl.value = shift;
var dayControl = document.getElementById(offsetControl2DayBox);
dayControl.value = calendarDate.getDate();
if (dayControl.onchange != undefined) dayControl.onchange();
}

if (offsetControlMonthDropDown != '' )
{
//TODO: PROBLEM
var calendarDate = newDate;
calendarDate.setDate(calendarDate.getDate() + offsetValue);
var d = new Date();
var shift = calendarDate.getMonth() - d.getMonth() + (calendarDate.getFullYear() - d.getFullYear())*12 ; 
var shiftControl = document.getElementById(offsetControlMonthDropDown);
shiftControl.value = shift;
var dayControl = document.getElementById(offsetControlDayBox);
dayControl.value = calendarDate.getDate();
EnableOffsetCalendarMonths(shiftControl);
DisableOffsetCalendarMonths(shiftControl, shift);
if (dayControl.onchange != undefined) dayControl.onchange();
}

if (StayLengthOtherDatePicker_DayBox != '' && stayLengthDropDown != '')
{
var one_day=1000*60*60*24;
var calendarDate = newDate;
var d = new Date();

var day1 = document.getElementById(DayBox).value;
var shift1 = parseInt(document.getElementById(MonthDropDown).value);
var month1 = d.getMonth() + shift1 + 1;
var year1 = d.getFullYear();
if (month1 > 12) {year1++; month1 -= 12;}
var date1 = new Date(year1, month1-1, day1);

var day2 = document.getElementById(StayLengthOtherDatePicker_DayBox).value;
var shift2 = parseInt(document.getElementById(StayLengthOtherDatePicker_MonthDropDown).value);
var month2 = d.getMonth() + shift2 + 1;
var year2 = d.getFullYear();
if (month2 > 12) {year2++; month2 -= 12;}
var date2 = new Date(year2, month2-1, day2);

var shiftDays = Math.abs((date2-date1)/one_day);
document.getElementById(stayLengthDropDown).value = shiftDays;
}
}

function updateStayDropDown(stayLengthDropDown, StayLengthOtherDatePicker_DayBox, stayLengthOtherDatePicker_MonthDropDown, MonthDropDown, DayBox) {
var shiftDays = parseInt(document.getElementById(stayLengthDropDown).value);
var one_day=1000*60*60*24;
var d = new Date();

var day1 = document.getElementById(StayLengthOtherDatePicker_DayBox).value;
var shift1 = parseInt(document.getElementById(stayLengthOtherDatePicker_MonthDropDown).value);
var month1 = d.getMonth() + shift1 + 1;
var year1 = d.getFullYear();
if (month1 > 12) {year1++; month1 -= 12;}
var date1 = new Date(year1, month1-1, day1);

var date2 = date1;
date2.setDate(date2.getDate() + shiftDays);

{
var shift = date2.getMonth() - d.getMonth() + (date2.getFullYear() - d.getFullYear())*12 ; 
var shiftControl = document.getElementById(MonthDropDown);
shiftControl.value = shift;
var dayControl = document.getElementById(DayBox);
dayControl.value = date2.getDate();
if (date2.onchange != undefined) date2.onchange();
}

}

function updateCalendar(CalendarJS_ClientVar, DayBox, MonthDropDown, CalendarJS_HiddenClientId, OffsetValue, offsetControl2MonthDropDown, offsetControl2DayBox, offsetControlMonthDropDown, offsetControlDayBox, StayLengthOtherDatePicker_DayBox, StayLengthOtherDatePicker_MonthDropDown, stayLengthDropDown) {
if (CalendarJS_ClientVar != undefined)
{
var day = document.getElementById(DayBox).value;
var shift = parseInt(document.getElementById(MonthDropDown).value);
var d = new Date();
var month = d.getMonth() + shift + 1;
var year = d.getFullYear();
if (month > 12) {year++; month -= 12;}
document.getElementById(CalendarJS_HiddenClientId).value = year+"-"+month+"-"+day;
updateOffsets(new Date(year, month-1, day), OffsetValue, offsetControl2MonthDropDown, offsetControl2DayBox, offsetControlMonthDropDown, offsetControlDayBox, StayLengthOtherDatePicker_DayBox, StayLengthOtherDatePicker_MonthDropDown, DayBox, MonthDropDown, stayLengthDropDown);
}
} 


function showVek(RoomTypeDropDownList, AgeArea, CotsDropDownList)
      {
        var element = document.getElementById(RoomTypeDropDownList);
        var area = document.getElementById(AgeArea);
        if(element.selectedIndex == 2 || element.selectedIndex == 5)
        { area.style.display = 'inline'; }
        else
        { area.style.display = 'none'; }
        var cots = document.getElementById(CotsDropDownList);
        if(element.selectedIndex == 0)
          {cots.style.display = 'none';}
        else
          {cots.style.display = 'block';}
      }
//END - kalendariky - pomocne skripty

// Search Criteria Multiform Tab Scripts - START
function ChangeTabSelection(tabId, clsName)
{
      try
      {
        jsTabStrip.SelectTab(tabId, clsName);
      }
      catch (e)
      {

      }
}

function JSTabStrip()
{
  var tabObjectsArray;
  var container;
  var currentSelection = "";
  
  this.Initialize = Initialize;
  this.AddTabObject = AddTabObject;
  this.SelectTab = SelectTab;
  
  function Initialize(contId)
	{
	  this.tabObjectsArray	= new Array();
	  this.container = $get(contId);	  
	}
	
	function AddTabObject(tabId)
	{
	  if(typeof(this.tabObjectsArray) == "undefined")
	    this.Initialize();
	    
	    this.tabObjectsArray.push($get(tabId));
	}
	
	function SelectTab(tabId, clsName)
	{
	  if(typeof(this.tabObjectsArray) == "undefined")
	    this.Initialize();
	    
	  if(this.tabObjectsArray.length == 0)
	    this.AddTabObject(tabId);
	    
	  for(n = 0;n < this.tabObjectsArray.length; n++)
	  {
      if(this.tabObjectsArray[n].id == tabId)
	    {
	      this.tabObjectsArray[n].style.display = 'block';
	      this.container.className = clsName;
	    }
	    else
	    {
	      this.tabObjectsArray[n].style.display = 'none';
	    }
	  }
	}
}
// Search Criteria Multiform Tab Scripts - END

function GetDatePart(fullDate)
{
	return new Date(fullDate.getFullYear(), fullDate.getMonth(), fullDate.getDate());
}