//Funcoes do Site
	function PesquisarClipping()
	{
		var filtro = $('#buscar_clipping').val();
		filtro = filtro.replace(/Procurar Clipping/gi, '');
		filtro = filtro.replace(/Find Clipping/gi, '');
		
		ajaxLoader('lista_clipping');
		paginacaoAjax('ajax/clipping.asp','1','1','&buscar=' + filtro + '&id=lista_clipping&cfg_rewrite_linguagem=<% = cfg_idioma_atual %>', null);
		
		return false;
	}
	
	function redireciona(pLingua)
	{		
		var valor = document.getElementById('buscar').value.removeAcentos();
		
		if ( ( valor == 'Search in site' ) || ( valor == 'Procurar no site' ) ) {
			document.getElementById('buscar').select();
			return false;
		}
		
		var termo = ( ( cfg_idioma_atual == 'en' ) ? '/search/' : '/buscar/' );
		location.href = cfg_url_do_site + cfg_idioma_atual + termo + valor;		
		return false;
	}
	
	var xmlRetorno = null;
	var RetornoAjax = null;
	var dateList = null;
	var aDatasPossiveis = null;
	
	//function teste(){ return 'no arquivo'; }
	formataData_DatePicker = function(pData){
		var dia = pData.substr(6, 2);
		var mes = pData.substr(4, 2);
		var ano = pData.substr(0, 4);
		return (mes + '/' + dia + '/' + ano);
	}
	formataData_Br = function(pData){
		var data_separada = pData.split('/');
		return ( data_separada[1] + '/' + data_separada[0] + '/' + data_separada[2]);
	}
	
	getDataInicial = function() {
		
		aDatasPossiveis = new Array();
		//var dataHoje = new Date();
		var _dataHoje = new Date();
		var dataHoje = new Date( _dataHoje.getFullYear(), _dataHoje.getMonth(), _dataHoje.getDate(), 0, 0, 0, 0 );
		
		$(dateList).each(function() {
			var dataformatada = formataData_DatePicker(this);
			var data_each = new Date(dataformatada);
						
			if ( data_each >= dataHoje ) {
				aDatasPossiveis.push( data_each );
			}
		});
		
		if ( aDatasPossiveis.length > 0 ) {
			
			var _date = new Date(aDatasPossiveis[0]);
			var _dia = _date.getDate();
			var _mes = _date.getMonth()+1;
			var _ano = _date.getFullYear();
			
			return (
				( ( _mes < 10 ) ? ('0' + _mes) : ( _mes ) ) + '/' +
				( ( _dia < 10 ) ? ('0' + _dia) : ( _dia ) ) + '/' +
				_ano
			)
			
		} else {
			return getDataHoje();
		}
		
	}
		
	getDataHoje = function(){
		var _dia = new Date().getDate();
		var _mes = new Date().getMonth()+1;
		var _ano = new Date().getFullYear();
		
		return (
			( ( _mes < 10 ) ? ('0' + _mes) : ( _mes ) ) + '/' +
			( ( _dia < 10 ) ? ('0' + _dia) : ( _dia ) ) + '/' +
			_ano
		)
	}
	
	function Concais() { }
		
		Concais.formataDataBr = function(pData) {
			var _dia = pData.getDate();
			var _mes = pData.getMonth()+1;
			var _ano = pData.getFullYear();
			
			return (
				( ( _dia < 10 ) ? ('0' + _dia) : ( _dia ) ) + '/' +
				( ( _mes < 10 ) ? ('0' + _mes) : ( _mes ) ) + '/' +
				_ano
			)
		}
//------------------- Programação de Navios -------------------
		Concais.ProgramacaoNavios = function() { }
			
			Concais.ProgramacaoNavios.MontaCalendario = function ()
			{
				var url_ajax = cfg_url_do_site + 'ajax/datas-programacao-navios.asp';
				var pars_ajax = '';
				var aRetorno = new Array();
				
				RetornoAjax = jQuery.ajax( {
					type:		'GET',
					dataType:	'xml',
					data:		pars_ajax,
					url:		url_ajax,
					success:	function(data) {
						
						xmlRetorno = data;
						$(xmlRetorno).find('registro').find('dt_programacao').each(function(){ aRetorno.push($(this).text()); });
						dateList = aRetorno;
						
						$('#datepicker_carregando').css('display', 'none');
						
						var dataInicial = null;
						
						dataInicial = getDataInicial();
						
						if ( cfg_idioma_atual == 'pt-br' )
						{ $.datepicker.setDefaults($.datepicker.regional['pt-br']); }
						
						$('#datepicker').datepicker({
							inline: true,
							defaultDate: dataInicial,
							beforeShowDay: function(dateToShow){   
								return [($.inArray($.datepicker.formatDate('yymmdd', dateToShow),dateList) >= 0), ""];
								//FORMATA A DATA A E PEGA OS DIAS A SEREM MOSTRADOS
							},
							onSelect: function(dateText, inst) {
								Concais.ProgramacaoNavios.BuscaProgramacao(dateText);
							}
						});
						
						Concais.ProgramacaoNavios.BuscaProgramacao(dataInicial);
						
					}
				});
			}
			
			Concais.ProgramacaoNavios.BuscaProgramacao = function (pData) {
				var url_ajax = cfg_url_do_site + 'ajax/programacao-navios.asp';
				var pars_ajax = 'dt_programacao=' + pData;
				var aRetorno = '';
				
				RetornoAjax = jQuery.ajax( {
					type:		'GET',
					dataType:	'xml',
					data:		pars_ajax,
					url:		url_ajax,
					error:function (xhr, ajaxOptions, thrownError){
						/*alert(xhr.status);
						alert(ajaxOptions);
						alert(thrownError);*/
					},
					success:	function(data) {						
						xmlRetorno = data;
						$(xmlRetorno).find('registro').each(function() {
							
							dia_programacao = $(this).find('dia_programacao').text();
							mes_programacao = parseInt($(this).find('mes_programacao').text())-1;
							mes_programacao = (  (cfg_idioma_atual == 'pt-br') ? Meses().Portugues.Siglas[mes_programacao] : Meses().Portugues.Siglas[mes_programacao] );
							nm_navio = $(this).find('nm_navio').text();
							url_nm_navio = $(this).find('url_nm_navio').text();
							nm_pt_atracacao = $(this).find('nm_pt_atracacao').text();
							nm_en_atracacao = $(this).find('nm_en_atracacao').text();
							hh_chegada_programacao = $(this).find('hh_chegada_programacao').text();
							hh_saida_programacao = $(this).find('hh_saida_programacao').text();
							
							nm_atracacao = ( (cfg_idioma_atual == 'pt-br') ? nm_pt_atracacao : nm_en_atracacao );
							
							aRetorno += '<li>';
							aRetorno += '	<span class="iconDate">';
							aRetorno += '		<strong class="day">' + dia_programacao + '</strong>';
							aRetorno += '		' + mes_programacao;
							aRetorno += '	</span>';
							aRetorno += '	<p><strong><a href="' + cfg_url_navio + url_nm_navio + '" style="text-decoration: underline;">' + nm_navio + '</a></strong><br />';
							aRetorno += ( ( nm_atracacao == '-' ) ? '' : '	' + nm_atracacao + '<br />' );
							aRetorno += '	' + Idioma().chegada +': ' + hh_chegada_programacao + ' - ' + Idioma().saida + ': ' + hh_saida_programacao + '</p>';
							aRetorno += '	<img class="clear" src="images/aside-linha.png" alt="Concais" />';
							aRetorno += '</li>';
							
						});						
						$('.listaCalendario').html(aRetorno);
					}
				});
				
			}

//------------------- Programação de Navios -------------------

//------------------- Formulário de Contato -------------------
	Concais.Contato = function(pIdForm) {
		
		var value = '';
		
		$('#' + pIdForm + ' input').each( function() {
			var $this = $(this);
			value = $this.val();
			
			if ( value != '' )
			{
				$this.attr('lang', value);
				$this.focus(	function () { limpa_se_igual(this, $(this).attr('lang')); });
				$this.blur( 	function () { suja_se_vazio(this,  $(this).attr('lang')); });
			}
			
		});
		
	}
//------------------- Formulário de Contato -------------------

//------------------- Tamanho da Fonte ------------------------
	Concais.TamanhoFonte = function(pTamanho) {
		
		 $('.content').attr('id', pTamanho);
		
		/*if ( pTamanho == '' ) { $('article').removeClass() }
		else { $('article').attr('class', 'maior'); }*/
		
		var url_ajax = cfg_url_do_site + 'ajax/tamanho-fonte.asp'
		var pars_ajax = 'id=' + pTamanho;
		
		RetornoAjax = jQuery.ajax( {
			type:		'GET',
			dataType:	'html',
			data:		pars_ajax,
			url:		url_ajax,
			error:		function (xhr, ajaxOptions, thrownError){ /*alert(thrownError)*/ },
			success:	function(data){ /*alert('Ok');*/ }
		});
		
	}
//------------------- Tamanho da Fonte ------------------------

//------------------- Planilha de Escalas ----------------------
	Concais.PlanilhaEscalas = function() {
		var url_ajax = cfg_url_do_site + 'ajax/data-planilha.asp'
		var pars_ajax = '';
		
		RetornoAjax = jQuery.ajax( {
			type:		'GET',
			dataType:	'html',
			data:		pars_ajax,
			url:		url_ajax,
			error:		function (xhr, ajaxOptions, thrownError){ /*alert(thrownError)*/ },
			success:	function(data){
				data_separada = data.split('[|]');
				
				$('#planilha_data').html('Atualizado em: ' + data_separada[0]);
				$('#link_planilha').attr('href', (cfg_url_planilha + data_separada[1]) );
			}
		});
		
	}
	
	
//------------------- Planilha de Escalas ----------------------

//------------------- Formulário de News -----------------------
	Concais.FormNews = function(pIdForm) {
		
		var value = '';
		
		$('#' + pIdForm + ' input').each( function() {
			var $this = $(this);
			value = $this.val();
			/*
			try {
				console.log(value);
			} catch (ex) { }
			*/
			if ( value != '' )
			{
				try {
				$this.attr('lang', value);
				$this.focus(	function () { limpa_se_igual(this, $(this).attr('lang')); });
				$this.blur( 	function () { suja_se_vazio(this,  $(this).attr('lang')); }); }
				catch (ex) { }
			}
			
		});
		
		$('#img_submit_news').click( function() {
			
			if ( ( $('#' + pIdForm +' input[name="nome"]').val().trim() == '' ) || ( $('#' + pIdForm +' input[name="nome"]').val().trim() == $('#' + pIdForm +' input[name="nome"]').attr('lang').trim() ) ){
				alert( ( ( cfg_idioma_atual == 'en' ) ? 'Please, type the Name' : 'Por favor, informe o Nome') );
				$('#' + pIdForm +' input[name="nome"]').focus();
				return false;
			}
			
			if ( ( $('#' + pIdForm +' input[name="email"]').val().trim() == '' ) || ( $('#' + pIdForm +' input[name="email"]').val().trim() == $('#' + pIdForm +' input[name="email"]').attr('lang').trim() ) ){
				alert( ( ( cfg_idioma_atual == 'en' ) ? 'Please, type the E-mail' : 'Por favor, informe o E-mail') );
				$('#' + pIdForm +' input[name="email"]').focus();
				return false;
			}
			
			if ( !ValidaEmail( $('#' + pIdForm +' input[name="email"]').val().trim() ) ){
				alert( ( ( cfg_idioma_atual == 'en' ) ? 'Please, check the E-mail' : 'Por favor, verifique o E-mail') );
				$('#' + pIdForm +' input[name="email"]').focus();
				return false;
			}			
			
			if ( ( $('#' + pIdForm +' input[name="cidade"]').val().trim() == '' ) || ( $('#' + pIdForm +' input[name="cidade"]').val().trim() == $('#' + pIdForm +' input[name="cidade"]').attr('lang').trim() ) ){
				alert( ( ( cfg_idioma_atual == 'en' ) ? 'Please, type the City' : 'Por favor, informe a Cidade') );
				$('#' + pIdForm +' input[name="cidade"]').focus();
				return false;
			}
			
			//alert('ok');
			$('#' + pIdForm).submit();
			
			return false;
			
		});
		
	}
	
//------------------- Formulário de News -----------------------
