function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }
    else {
     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}
var documentHeightInit
function setFooter() {
	
	var windowHeight = getWindowHeight()
	var documentHeight = $(document).height()
	var bodyHeight = $('body').height();
	var contentHeight = $('#content').height()
	var footerHeight = $('#footer').height()
	var headerHeight = $('#header').height()
	
	if (bodyHeight<=windowHeight){
		$('#content').css("height", windowHeight-footerHeight-headerHeight-1);
	}
	if (windowHeight<documentHeight && documentHeight>documentHeightInit){
		$('#content').css("height","auto")
	}
}

window.onload = function() {
	documentHeightInit = $(document).height();
	setFooter();
	addCalendarTips()
}
$(window).resize(function(){
 /*if (!$.browser.msie)*/setFooter();
});
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

$(window).ready(function(){
	documentHeightInit = $(document).height();
 setFooter();

  var coach = getUrlVars()["coach"];
  var url_path = window.location.href;
  var coach_pos = url_path.indexOf("coach");
  
  if ((coach == "1.do") || (coach_pos != '-1')) {
	$('div.show_coach').css({'display':'block'});
	$('div.hide_coach').css({'display':'none'});

	$('#user_coachFirstname').attr("disabled", "disabled").parent().append('<input type="hidden" name="f_user_coachFirstname" id="f_user_coachFirstname" />');
	$('#user_coachLastname').attr("disabled", "disabled").parent().append('<input type="hidden" name="f_user_coachLastname" id="f_user_coachLastname" />');
	$('#user_coachEmail').attr("disabled", "disabled").parent().append('<input type="hidden" name="f_user_coachEmail" id="f_user_coachEmail" />');

	$('#f_user_firstname').keyup(function(event) {
 		if (event.keyCode == '13') {
     			event.preventDefault();
   		}

		$('#f_user_coachFirstname').val($('#f_user_firstname').val());
		$('#user_coachFirstname').val($('#f_user_firstname').val());
   	});

	$('#f_user_lastname').keyup(function(event) {
 		if (event.keyCode == '13') {
     			event.preventDefault();
   		}

		$('#f_user_coachLastname').val($('#f_user_lastname').val());
		$('#user_coachLastname').val($('#f_user_lastname').val());
   	});

	$('#f_user_email').keyup(function(event) {
 		if (event.keyCode == '13') {
     			event.preventDefault();
   		}

		$('#f_user_coachEmail').val($('#f_user_email').val());
		$('#user_coachEmail').val($('#f_user_email').val());
   	});

	$('#f_user_coachLink').append('<option value="COACH" selected="selected">COACH</option>');

	$('#coach_holder').css({'display':'none'});
  } else {
	$('#user_coachFirstname').attr('id', 'f_user_coachFirstname');
	$('#user_coachLastname').attr('id', 'f_user_coachLastname');
	$('#user_coachEmail').attr('id', 'f_user_coachEmail');
  }
});

//----------------
//CALENDAR
//----------------
function getCalendar(dateToShow){
	$.ajax({url:dateToShow,type:"GET",data: "",success:function(data){
						$("#feature_calendar").html(data);
						addCalendarTips();
					}});
}
function addCalendarTips(){
		$(".day_overlayer").each(function(e){
			$(this).parent().mouseover(function(e){					
				$(this).children(".day_overlayer").css("display","block");
				$(this).children("ul").css("margin-top","-5px");
				$(this).children("ul").css("margin-left","5px")});
			$(this).parent().mouseout(function(e){					
				$(this).children(".day_overlayer").css("display","none")});
		})
}



