//SCROLLING

var defaultStep=2
var step=defaultStep
var timerDown;
var timerUp;
function scrollDivDown(id)
{
	document.getElementById(id).scrollTop+=step
	timerDown=setTimeout("scrollDivDown('" + id + "')",10)
}

function scrollDivUp(id)
{
	document.getElementById(id).scrollTop-=step
	timerUp=setTimeout("scrollDivUp('" + id + "')",10)
} 

function clearTheTimeout(whichWay)
{
	if(whichWay == "up")
	{
		clearTimeout(timerUp);	
	}
	if(whichWay == "down")
	{
		clearTimeout(timerDown);	
	}
}


$(document).ready(function($){
	if(window.location.hash == "#showSubmission") {
		showTab("submittedTab");
		jQuery('#intNav').addClass('hiddenTab');
                                            jQuery('#contentTab').addClass( 'hiddenTab');
	}
    var layout = jQuery("#layout");
    var layoutHeightCheck = jQuery("#layoutHeightCheck");
    
    var textHeight = layoutHeightCheck[0].offsetTop - layout[0].offsetTop;
    
    if(textHeight > 222) {
        jQuery('.scroll').show();
    }
    
    jQuery("#datepickerUtreise").datepicker({
                           
		altField: '#utreiseDate',
		altFormat: "d-m-yy",
		onSelect: function(date) {
                                           
		}
	});
    
	jQuery("#datepickerHjemreise").datepicker({
		altField: '#hjemreiseDate',
		altFormat: "d-m-yy",
		onSelect: function(date) {
                                                var returnDateArray = date.split( "-");
                                                var returnDate = new Date( returnDateArray[0], returnDateArray[1]-1, returnDateArray[2]);
                                                var utreise = $('#utreiseDate').val();
                                                var brokenDate = utreise.split( "-");
                                                var utreiseDate = new Date( brokenDate[2], brokenDate[1]-1, brokenDate[0]);    
                                                if ( returnDate < utreiseDate ){
                                                    alert( "Hjemreisedato kan ikke være tidligere enn utreisedato.");
                                                }
 
		}
	});
     
      
});

function showTab(idToShow, tabToChange) {
	jQuery('#' + idToShow).removeClass('hiddenTab');
	if(tabToChange != undefined) {
		jQuery('#layout li').removeClass('currentNavTab');
	}
	jQuery('#' + tabToChange).addClass('currentNavTab');
	
	jQuery('.dynamicTab').each(function() {
		if(this.id != idToShow) {
			jQuery('#' + this.id).addClass('hiddenTab');
		}
	});
	
	if(idToShow != "datesTab") {
		jQuery('#intNav').removeClass('hiddenTab');
		jQuery('.scroll').hide();
	}
	else {
		jQuery('#intNav').addClass('hiddenTab');
		jQuery('.scroll').show();
	}
                var layout = jQuery("#layout");
                var layoutHeightCheck = jQuery("#layoutHeightCheck");
    
                var textHeight = layoutHeightCheck[0].offsetTop - layout[0].offsetTop;
    
                if(textHeight > 222) {
                    jQuery('.scroll').show();
                }
}



