$(document).ready(function() { 	 
	$('a#print').click(function() { 	        
	window.print(); 	        
	return false; 	    
	}); 
});

function escreveFlash(nomeFlash, largura, altura, idComponente){	
	var so = new SWFObject(nomeFlash, "sotester", largura, altura, "9");
	so.addParam("wmode", "transparent");
	so.addParam("menu","false");
	so.write(idComponente);
}

function organizaImagens(classCSS){
	imagens = $('.'+classCSS);
	maior = 0;

	imagens.each(
		function x(){
			if( $(this).height() > maior){
				maior = $(this).height();
			}
		}
	);
		
	imagens.each(function(){
			$(this).height(maior);
	});

	maior = 0;
	imagens.each(
			function x(){
				if( $(this).width() > maior){
					maior = $(this).width();
				}
			}
		);
			
		imagens.each(function(){
				$(this).width(maior);
		});	


}

function incluirNewsLetter(){
	var email = document.getElementById('newsLetter.email').value;
	var path = document.getElementById("contextPath").value;
	$.getJSON(path+"CadastrarNewsLetter.jsp?newsLetter.email="+email, function(json){
		if(json.actionErrors)
			alert(json.actionErrors);
		else{		
			alert("E-mail cadastrado com sucesso!");
			document.getElementById('newsLetter.email').value = '';
		}
	});
}

function mascaraData(dataCasamento, mask){
	var i = dataCasamento.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i);
	if (texto.substring(0,1) != saida)
	  {
		dataCasamento.value += texto.substring(0,1);
	  }
}

function validaProcura(){
	var nome = document.getElementById('razaoSocial').value;
	var data = document.getElementById('dataCasamento').value;	
	if(nome != ''){
		if(data != ''){
			if(!verificaData(data)){
				alert("Data inválida!");
				document.getElementById('dataCasamento').value = '';
				return false;
			}
			return true;
		}
		return true;		
	}else{		
		alert("Por favor preencher o campo nome, \nPelo menos um nome!");
		return false;
	}		
	return false;
}

function verificaData(data) {
	if(data.length < 7 || data.length > 10) return false;
		pos0 = data.indexOf("/");
	if(pos0 == -1) return false;
		pos1 = data.indexOf("/", pos0 + 1);
	if(pos1 == -1) return false;
	if(data.indexOf("/", pos1 + 1) != -1) return false;
	dia = data.substring(0,pos0);
	dia = (dia.charAt(0) == "0") ? dia.charAt(dia.length - 1) : dia;
	mes = data.substring(pos0 + 1, pos1);
	mes = (mes.charAt(0) == "0") ? mes.charAt(mes.length - 1) : mes;
	ano = data.substring(pos1 + 1, data.length);
	ano = (ano.charAt(0) == "0") ? ano.charAt(ano.length - 1) : ano;
	if(isNaN(dia) || isNaN(mes) || isNaN(ano)) return false;
	if(parseInt(ano) >= 0 && parseInt(ano) < 1900) return false;
	if(parseInt(ano) > 2100 || parseInt(ano) < 0 || parseInt(mes) > 12 || parseInt(mes) < 1) return false;
	numero = ((parseInt(ano) - 1884) / 4)
	if(numero == Math.floor(numero)) {
		dias = "312931303130313130313031";
		}
	else {
		dias = "312831303130313130313031";
		}
	diamax = parseInt(dias.substring((mes-1)*2,((mes-1)*2)+2));
	if(parseInt(dia) < 1 || parseInt(dia) > diamax) return false;
	return true;
}
