function jsEnabled() {
  $j("body").addClass("js-enabled");
}

function initAuxNav() {
  $j('#login').click( function() {
    if(!$j('#login-panel').is(':visible')) {
      if($j('#flags').is(':visible'))
        $j('#flags').slideUp('fast');

          $j('#login-panel').slideDown('fast');
          return false;
        } else {
      $j('#login-panel').slideUp('fast');
      return false;
    }
  } );

  $j('#choose-country').click( function() {
    if(!$j('#flags').is(':visible')) {
      if($j('#login-panel').is(':visible'))
        $j('#login-panel').slideUp('fast');

          $j('#flags').slideDown('fast');
          return false;
        } else {
      $j('#flags').slideUp('fast');
      return false;
    }

  } );

  $j('#forgot-pwd').click( function() {
    $j('#pwd-form').show();
    $j('#login-form').hide();
    return false;
  } );

  $j('#return-to-login').click( function() {
    $j('#login-form').show();
    $j('#pwd-form').hide();
    return false;
  } );
};

function initAuxAction() {
  $j('#aux-action li').hover(function() {
    $j(this).addClass('aux-action-hover');
  }, function() {
    $j(this).removeClass('aux-action-hover');
   });

   $j('#aux-action li').bind('click', function() {
    var links = $j(this).find('a');
    if (links[0].href) {
      window.location = links[0].href;
    }
  });
}

function initDropDown() {	
	
/*  $j('#d-nav li span').bind('click', function() {
    if($j(this).hasClass('down')) {
      $j(this).removeClass('down');
      $j(this).addClass('up');
      $j('#d-sub-nav').slideDown('fast').show();
      //Note the iframe is required to solve a rendering issue
      //http://weblogs.asp.net/bleroy/archive/2005/08/09/how-to-put-a-div-over-a-select-in-ie.aspx
      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#d-sub-nav').append('<iframe></iframe>');
      }
    } else {
      $j(this).removeClass('up');
      $j(this).addClass('down');
      $j('#d-sub-nav').slideUp('slow');
      
      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#d-sub-nav iframe').remove();
      }
    }
  });*/
$j('#d-btn').bind('click', function() {
    if($j(this).hasClass('down')) {
      $j(this).removeClass('down');
      $j(this).addClass('up');
      $j('#d-sub-nav').slideDown('fast').show();
      //Note the iframe is required to solve a rendering issue
      //http://weblogs.asp.net/bleroy/archive/2005/08/09/how-to-put-a-div-over-a-select-in-ie.aspx
      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#d-sub-nav').append('<iframe></iframe>');
      }
    } else {
      $j(this).removeClass('up');
      $j(this).addClass('down');
      $j('#d-sub-nav').slideUp('slow');

      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#d-sub-nav iframe').remove();
      }
    }
  });
  $j('#gu-btn').bind('click', function() {
    if($j(this).hasClass('down')) {
      $j(this).removeClass('down');
      $j(this).addClass('up');
      $j('#gu-sub-nav').slideDown('fast').show();
      //Note the iframe is required to solve a rendering issue
      //http://weblogs.asp.net/bleroy/archive/2005/08/09/how-to-put-a-div-over-a-select-in-ie.aspx
      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#gu-sub-nav').append('<iframe></iframe>');
      }
    } else {
      $j(this).removeClass('up');
      $j(this).addClass('down');
      $j('#gu-sub-nav').slideUp('slow');

      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#gu-sub-nav iframe').remove();
      }
    }
  });

  $j('#ts').hover(function(){
	  if($j('#d-btn').hasClass('down')) {
      $j('#d-btn').removeClass('down');
      $j('#d-btn').addClass('up');
      $j('#d-sub-nav').slideDown('fast').show();
      //remove gu
      $j('#gu-btn').removeClass('up');
      $j('#gu-btn').addClass('down');
      $j('#gu-sub-nav').slideUp('slow');
      //Note the iframe is required to solve a rendering issue
      //http://weblogs.asp.net/bleroy/archive/2005/08/09/how-to-put-a-div-over-a-select-in-ie.aspx
      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#d-sub-nav').append('<iframe></iframe>');
        $j('#gu-sub-nav iframe').remove();
      }
	  }
	
	}, function(){
  });

  $j('#gu').hover(function(){
    if($j('#gu-btn').hasClass('down')) {
      $j('#gu-btn').removeClass('down');
      $j('#gu-btn').addClass('up');
      $j('#gu-sub-nav').slideDown('fast').show();
      //remove ts
      $j('#d-btn').removeClass('up');
      $j('#d-btn').addClass('down');
      $j('#d-sub-nav').slideUp('slow');
      //Note the iframe is required to solve a rendering issue
      //http://weblogs.asp.net/bleroy/archive/2005/08/09/how-to-put-a-div-over-a-select-in-ie.aspx
      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#gu-sub-nav').append('<iframe></iframe>');
        $j('#d-sub-nav iframe').remove();
      }
    }

  }, function(){
  });
  
  $j('#d-sub-nav').hover(
			function() { $j('#d-sub-nav').show();},
			function() { 
				$j('#d-nav li span').removeClass('up');
      	$j('#d-nav li span').addClass('down');
      	$j('#d-sub-nav').slideUp('slow');
      
      	if($j.browser.msie && $j.browser.version < 7 ) {
        	$j('#d-sub-nav iframe').remove();
      	}
   });
  $j('#gu-sub-nav').hover(
      function() { $j('#gu-sub-nav').show(); },
      function() {
        $j('#d-nav li span').removeClass('up');
        $j('#d-nav li span').addClass('down');
        $j('#gu-sub-nav').slideUp('slow');

        if($j.browser.msie && $j.browser.version < 7 ) {
          $j('#gu-sub-nav iframe').remove();
        }
   });

  $j('.d-nav-item').hover(function(){
		if($j('#d-nav li span').hasClass('up')) {
      $j('#d-nav li span').removeClass('up');
      $j('#d-nav li span').addClass('down');
      $j('#d-sub-nav').slideUp('slow');
      $j('#gu-sub-nav').slideUp('slow');
      //Note the iframe is required to solve a rendering issue
      //http://weblogs.asp.net/bleroy/archive/2005/08/09/how-to-put-a-div-over-a-select-in-ie.aspx
      if($j.browser.msie && $j.browser.version < 7 ) {
        $j('#d-sub-nav iframe').remove();
        $j('#gu-sub-nav iframe').remove();
      }
	  }
	
	},function(){});
  
}

function checkFindBedPanel() {
  var now = new Date();
  var one_day = (1000 * 60 * 60 * 24);

  todaydate = ( now.getDate() < 10 )?'0' + now.getDate():now.getDate();
  todaymonth = ( now.getMonth() < 10 )?'0' + (now.getMonth()+1):(now.getMonth()+1);

  chosendate = document.theForm.selDay.options[document.theForm.selDay.selectedIndex].value;
  chosenmonth = document.theForm.selMonth.options[document.theForm.selMonth.selectedIndex].value;
  chosen = document.theForm.selYear.options[document.theForm.selYear.selectedIndex].value + '' + chosenmonth + '' + '' + chosendate;
  today = now.getFullYear() + '' + todaymonth + '' + '' + todaydate;

  var searchDate = new Date (document.theForm.selYear.options[document.theForm.selYear.selectedIndex].value, chosenmonth-1, chosendate);

  pageTracker._trackEvent("findabed refine",  "datesearch", (document.theForm.selYear.options[document.theForm.selYear.selectedIndex].value + chosenmonth));
  pageTracker._trackEvent("findabed refine", "daysinfuture", (Math.ceil((searchDate.getTime()-now.getTime())/(one_day))));

  if ( chosen < today ) {
    pageTracker._trackEvent("findabed refine", "datesearch", "invalid");
    alert("Please enter dates ahead of today\'s date. Thank you.");
    return false;
  }

  return true;
}

function checkGroup(menu) { 
  if (menu.options[menu.selectedIndex].value == 'GROUP') {
    document.theForm.submit();
  }
}

function ShowDiv(Id) {
  div = document.getElementById(Id);
  if (div.style) {
    div.style.display = 'block';
  } else {
    div.display = 'block';
  }
}

function HideDiv(Id) {
  div = document.getElementById(Id);
  if (div.style) {
    div.style.display = 'none';
  } else {
    div.display = 'none';
  }
}

function ToggleDiv(Id) {
  div = document.getElementById(Id);

  if (div.style) {
    if (div.style.display == 'block') {
      HideDiv(Id);
    } else if (div.style.display == 'none') {
      ShowDiv(Id);
    }
  } else {
    if (div.display == 'block') {
        HideDiv(Id);
    } else if (div.display == 'none') {
        ShowDiv(Id);
    }
  }
}

function OpenWindow( url, width, height ) {
  SmallWin = window.open(url, 'HostelPicture','scrollbars,resizable,height='+height+',width='+width);
  if (window.focus) {
    SmallWin.focus();
  }
  if (SmallWin.opener == null) {
    SmallWin.opener = window;
  }
}

function OpenWindow2( url, width, height ) {
  SmallWin = window.open(url, 'HostelPicture2','height='+height+',width='+width);
  if (window.focus) {
    SmallWin.focus();
  }
  if (SmallWin.opener == null) {
    SmallWin.opener = window;
  }
}

