
/**
 * Fallback if console.log() does not exist - http://ajax-prototype.blogspot.com/2006/12/workaround-to-make-firebug-consolelog.html
 *
 */
try { console.log('init console... done'); } catch(e) { console = { log: function(str) {
	$('#debug').append(str+'<br/>');
} } }


$(document).ready(function(){


	// header drop down links
	if ($.browser.msie) {
		$('#topDropdownLinks').change(function(){
			var location = $(this).children("[@selected]").attr('value');
			var linkclass = $(this).children("[@selected]").attr('class');

			if(linkclass) {
				window.open(location);
			} else {
				window.location = location;
			}
			
		});
	} else {	
		$("#topDropdownLinks option").click(function($option){
			if($(this).hasClass("new")) {
				window.open(this.getAttribute("value"));
			} else {
				window.location = this.getAttribute("value");
			}
		});
	}

	// Print Link
	$("div.content a.printThis").click(function(){
		window.print();
	});

	// Add standard table classes for eZ content area
	$("div.ezMatrix table").addClass("standardTable");

	// empty on click
	$("#orderEmail").focus(function(){
		this.setAttribute('value','');
	});

	// tune dem vesselDatas
	$(".column1 table.vesselData tr:odd").addClass('odd');

	// open blank
	$("a.open_blank").attr('target','_blank');

	// open booking
	$("#bookingLinks a").attr('target','booking');
	
	//company main background
	if($('.corpMainContainer').length){
		$('.content').addClass('corpMainBack');
	}


	$(".mainContent .autoHeightWrapper").each(function(thisWrapper){
	
		var maxHeight = 0;
		
		$(this).find("div.contentHeight").each(function() {
			maxHeight = Math.max(maxHeight, $(this).height()); 
			console.log('max' + maxHeight);
		});
		
		$(this).find('.contentHeight').height(maxHeight);
		
		
	});

});


function weeklyTimeTableCheckSelection() {

	var departure = $('#departureCountry option:selected');
	var departure_code = departure.val();
	
	var arrival = $('#arrivalCountry option:selected');
	var arrival_code = arrival.val();	

	if(departure_code == 'all' && arrival_code == 'all') {
		$('#weeklySelectionError').css('display','block');
		return false;
	}
	else {
		$('#weeklySelectionError').css('display','none');
		return true;	
	}
	
}

function onlineTimeTableCheckSelection() {

	var departure = $('#loadingCountry option:selected');
	var departure_code = departure.val();
	
	var arrival = $('#dischargeCountry option:selected');
	var arrival_code = arrival.val();	

	var departurePort = $('#loadingPort option:selected');
	var departurePort_code = departurePort.val();
	
	var arrivalPort = $('#dischargePort option:selected');
	var arrivalPort_code = arrivalPort.val();	


	if(departure_code == '-1' && arrival_code == '-1' && departurePort_code == '-1' && arrivalPort_code == '-1') {
		$('#onlineSelectionError').css('display','block');
		return false;
	}
	else {
		$('#onlineSelectionError').css('display','none');
		return true;	
	}

	
}