function setLocale(locale){
	window.location = '/users/locale/' + locale;
}

function summaryPanelHeights(){
	maxHeight = 0;
	$('.summaryPanel').each(function(){
		thisHeight = $(this).height();
		if(thisHeight > maxHeight){
			maxHeight = thisHeight;
		}
	});
	
	if($('.summaryPanelHeight').length > 0){
		thisHeight = $('.summaryPanelHeight').height();
		if(thisHeight > maxHeight){
			maxHeight = thisHeight;
		}
	}

	$('.summaryPanel').each(function(){
		$(this).height(maxHeight);
	});
	
	maxHeight = 0;
	$('.siteMap').each(function(){
		thisHeight = $(this).height();
		if(thisHeight > maxHeight){
			maxHeight = thisHeight;
		}
	});
	
	$('.siteMap').each(function(){
		$(this).height(maxHeight);
	});
}

var RecaptchaOptions = {
    theme: 'clean',
	lang: '<?php if(Configure::read("Config.locale")) { echo substr(Configure::read("Config.locale"), 0, 2); } else { echo "en"; } ?>'
};

function splitDate(selectedDate){
	selectedDate = selectedDate.replace('.', '/');
	selectedDate = selectedDate.replace('.', '/');
	selectedDate = selectedDate.replace('-', '/');
	selectedDate = selectedDate.replace('-', '/');
	selectedDate = selectedDate.split('/');
	return selectedDate;
}

function processDate(localeFormat,selectedDate){
	selectedDate = splitDate(selectedDate);
	outputDate = new Array();
	
	$.each(localeFormat,function(i,v) {
		if(v == 'dd'){
			outputDate[2] = selectedDate[i];
		}else if(v == 'mm'){
			outputDate[1] = selectedDate[i];
		}else if(v == 'yy'){
			outputDate[0] = selectedDate[i];
		}
	});
	
	return outputDate[0] + '-' + outputDate[1] + '-' +outputDate[2];
}

function str_pad(value){
	if(value.toString().length == 1){
		value = '0' + value;
	}
	return value;
}

function preloadDate(subtract){
	localeDateFormatSplit = splitDate(localeDateFormat);
	
	var startDate = new Date();
	startDate.setDate(startDate.getDate()-subtract);
	day = str_pad(startDate.getDate());
	month = str_pad(startDate.getMonth()+1);
	year = startDate.getFullYear();
	
	startDate = localeDateFormat.replace('dd', day);
	startDate = startDate.replace('mm', month);
	startDate = startDate.replace('yy', year);
	
	var endDate = new Date();
	day = str_pad(endDate.getDate());
	month = str_pad(endDate.getMonth()+1);
	year = endDate.getFullYear();

	endDate = localeDateFormat.replace('dd', day);
	endDate = endDate.replace('mm', month);
	endDate = endDate.replace('yy', year);

	return new Array(startDate,endDate);
}

$(document).ready(function() {
	$(".list tr:last-child").addClass('rowLast');
	$(".listNobase tr:last-child").addClass('rowLastNone');
	$("button, input:submit, a", ".buttons").button();
	$("select, input:checkbox, input:radio").uniform();
	$(".showTooltip").tooltip({effect: 'slide'}).dynamic({ bottom: { direction: 'down', bounce: true } });
	$('.searchField').each(function(){
		if($(this).val() == ''){
			$(this).val($(this).next('input:hidden').val());
			$(this).css("color","#CCC");
		}
		$(this).focus(function(){
			if($(this).val() == $(this).next('input:hidden').val()){
				$(this).val('');
				$(this).css("color","#000");
			}
		});
		$(this).blur(function(){
			if($(this).val() == ''){
				$(this).val($(this).next('input:hidden').val());
				$(this).css("color","#CCC");
			}
		});
	});
	summaryPanelHeights();
});
