function getRand(){
	var data = new Date();
	var randomico = Math.round(data.getTime()+''+Math.random(1,9999));
	while (randomico == Math.round(data.getTime()+''+Math.random(1,9999))){
		randomico = Math.round(data.getTime()+''+Math.random(1,9999));
	}
	return randomico;
}

function accordionMenu(lista,nomeObj){
	if(lista=="media") {
		opcoes = new Array('sem_destinos','destinos','famosos');
	}
	if(lista=="regiao") {
		opcoes = new Array('regiao1','regiao2','regiao3','regiao4','regiao5');
	}
	
	for(i=0;i<opcoes.length;i++){
		try {
			objLista = document.getElementById(opcoes[i]);
			objLista.style.display= "none";
		}catch(e) {}
	}
	
	obj = document.getElementById(nomeObj);
	obj.style.display="block";
}

function fecharComentario(){
	document.getElementById('containerComentario').style.display = 'none';	
}

function abreComentarios(){
	document.getElementById('containerComentario').style.display = 'block';	
}

function fecharFormPromocao(){
	document.getElementById('form3').style.display = 'block';	
	document.getElementById('form1').style.display = 'none';	
	if (document.getElementById('form2'))
		document.getElementById('form2').style.display = 'none';	
	document.getElementById('containerFormPromocao').style.display = 'none';	
}

function abreFormPromocao(){
	document.getElementById('containerFormPromocao').style.display = 'block';	
}

function abreFormEnvieAmigo(){
	document.getElementById('containerFormEnvieAmigo').style.display = 'block';	
}

function fecharFormEnvieAmigo(){
	document.getElementById('containerFormEnvieAmigo').style.display = 'none';	
}

function abreFormSend(){
	if (document.getElementById('form2'))
		document.getElementById('form2').style.display = 'block';	
	else{
		fecharFormPromocao();
		//abreComentarios();
		abreFormPromocao();
	}
	document.getElementById('form3').style.display = 'none';	
}

function abreFormSendPromo()
{
	if (document.getElementById('form2'))
		document.getElementById('form2').style.display = 'block';	
	document.getElementById('form3').style.display = 'none';	
	document.getElementById('containerFormPromocao').style.display = 'block';	
}

function abreFormCad(){
	document.getElementById('form1').style.display = 'block';	
	if (document.getElementById('form2'))
		document.getElementById('form2').style.display = 'none';
	document.getElementById('form3').style.display = 'none';	
	document.getElementById('containerFormPromocao').style.display = 'block';	
}


function NotNumber(e, objForm) {
	var oEvent = e? e : window.event;
	nEvent = oEvent.keyCode || oEvent.which;
	//alert(nEvent);
	var arrPermiticao = [8,9,13,35,36,37,38,39,40,46,48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105,110,188,190];	
	for(i=0; i < arrPermiticao.length; i++) {
		if(nEvent == arrPermiticao[i]) {
			matchEvent = 1;
			break;
		} else {
			if(typeof(oEvent.preventDefault) == 'function') {
				matchEvent = 0;
				continue;
			} else {
				matchEvent = 0;
				continue;
			}
		}
	}
	if(matchEvent == 0) {
		return(false);
	}
	return true;
}

function verificaPasso1()
{
	document.getElementById('form1').style.display='none';
	if(document.getElementById('form2')){
		document.getElementById('form2').style.display='block';			
	} else {
		document.getElementById('containerFormPromocao').style.display='none';					
		abreComentarios();
		
	}
}
function validaArquivo(oForm){
	
	if (document.getElementById('titulo').value == ''){
		window.alert('Você informar o título.');
		document.getElementById('titulo').focus();
		return false;
	}
	
	/*if (document.getElementById('thumbFile').value == ''){
		window.alert('Você deve selecionar uma imagem.');
		document.getElementById('thumbFile').focus();
		return false;
	}*/
	
	if (document.getElementById('resposta').value == ''){
		window.alert('Você deve responder a pergunta.');
		document.getElementById('resposta').focus();
		return false;
	}

	if(document.getElementById('liaceito').checked == ""){
		window.alert('Para finalizar o cadastro é necessário estar de acordo com os termos do regulamento!');
		document.getElementById('liaceito').focus();
		return false
	}
	
	if (SwfuUpload()){	
		oForm.submit();
		return true;
	}
	else
		return false;
}


function validaArquivo2(oForm){
	
	if (document.getElementById('titulo').value == ''){
		window.alert('Você informar o título.');
		document.getElementById('titulo').focus();
		return false;
	}
	
	/*if (document.getElementById('thumbFile').value == ''){
		window.alert('Você deve selecionar uma imagem.');
		document.getElementById('thumbFile').focus();
		return false;
	}*/
	
	if (document.getElementById('resposta').value == ''){
		window.alert('Você deve responder a pergunta.');
		document.getElementById('resposta').focus();
		return false;
	}

	if(document.getElementById('liaceito').checked == ""){
		window.alert('Para finalizar o cadastro é necessário estar de acordo com os termos do regulamento!');
		document.getElementById('liaceito').focus();
		return false
	}
	
	if(document.getElementById('tipo').value == 1)
	{
		
		
	}
	if(document.getElementById('tipo').value == 3)
	{
		oForm.submit();
		return true;
	}
	else{
		if (SwfuUpload()){	
			oForm.submit();
			return true;
		}
		else
			return false;	
	}
}

function validaEnvieamigo(oForm) {
	if (document.getElementById('nome').value == '') {
		window.alert('Você deve preencher o campo de nome.');
		document.getElementById('nome').focus();
		return false;
	}
	if (document.getElementById('nome_to').value == '') {
		window.alert('Você deve preencher o campo de nome do seu amigo.');
		document.getElementById('nome_to').focus();
		return false;
	}
	if (document.getElementById('email').value == '' || isEmail(document.getElementById('email').value) == false){
		window.alert('Você deve preencher o campo de e-mail corretamente.');
		document.getElementById('email').focus();
		return false;
	}
	if (document.getElementById('email_to').value == '' || isEmail(document.getElementById('email_to').value) == false){
		window.alert('Você deve preencher o campo de e-mail do seu amigo corretamente.');
		document.getElementById('email_to').focus();
		return false;
	}
	oForm.submit();
	return true;
	
}

function validaLogin(oForm)
{
	if (document.getElementById('emailLogin').value == '')
	{
		window.alert('Você deve preencher o campo email.');
		document.getElementById('emailLogin').focus();
		return false;
	}
	
	if (document.getElementById('senhaLogin').value == '')
	{
		window.alert('Você deve preencher o campo senha.');
		document.getElementById('senhaLogin').focus();
		return false;
	}
	oForm.submit();
	return true;
}

function isEmail(m) {
	var Email = m;
	if(!Email.match(/^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/)) {
		return(false);
	}
	return(true);
}
function isDate(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat);
	
	if (matchArray == null)return false;
	
	month = matchArray[3];
	day = matchArray[1];
	year = matchArray[5];
	
	if (month < 1 || month > 12)return false;	
	if (day < 1 || day > 31)return false;	
	if ((month==4 || month==6 || month==9 || month==11) && day==31)return false;
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap))return false;
	}
	return true;
}

function FormataCPF(Campo, teclapres)
{
	 var tecla = teclapres.keyCode;
	
	 var vr = new String(Campo.value);
	 vr = vr.replace(".", "");
	 vr = vr.replace(".", "");
	 vr = vr.replace("-", "");
	
	 tam = vr.length + 1 ;
	
	 if (tecla != 9 && tecla != 8){
		 if (tam > 3 && tam < 7)
		 Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		 if (tam >= 7 && tam < 10)
		 Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		 if (tam >= 10 && tam < 13)
		 Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + ' - ' + vr.substr(15,tam-15);
	 }

}

function checkCPF(number)
{
	var invalid		= new Array('00000000000','11111111111','22222222222','33333333333','44444444444','55555555555','66666666666','77777777777','88888888888','99999999999');
	var CPF_LENGTH	= 11;
	
	number		= number.replace(/[^0-9]/g,'');
	if(number.length != CPF_LENGTH)return false;
	for(var counter = 0;counter < invalid.length;counter++)
		if(number == invalid[counter])return false;
	
	var digito1 = 0;
	var digito2 = 0;
	
	number = number.split('');
	for(counter = 0;counter < CPF_LENGTH - 2;counter++)
	{
		digito1 += number[counter] * (CPF_LENGTH - (counter + 1));
		digito2 += number[counter] * (CPF_LENGTH - counter);
	}
	
	digito1 = digito1 % CPF_LENGTH;
	
	if(digito1 > 1)digito1 = CPF_LENGTH - digito1;
	else digito1 = 0;
	
	digito2 = (digito2 + (digito1 * 2)) % CPF_LENGTH;
	if(digito2 > 1)digito2 = CPF_LENGTH - digito2;
	else digito2 = 0;
	
	if(digito1 != number[9] || digito2 != number[10])return false;
	return true;
}



function validaCadastro(oForm){
	if (document.getElementById('nome').value == ''){
		window.alert('Você deve preencher o campo nome.');
		document.getElementById('nome').focus();
		return false;
	}
	if (document.getElementById('cpf').value == ''){
		window.alert('Você deve preencher o campo CPF.');
		document.getElementById('cpf').focus();
		return false;
	}
	
	if(!checkCPF(document.getElementById('cpf').value)){
		window.alert("CPF inválido.");
		document.getElementById('cpf').value = "";
		document.getElementById('cpf').focus();
		return false;
	}
	
	if (document.getElementById('email').value == ''){
		window.alert('Você deve preencher o campo email.');
		document.getElementById('email').focus();
		return false;
	} else {
		if(!isEmail(document.getElementById('email').value)){
			window.alert('Email inválido.');
			document.getElementById('email').focus();
			return false;
		}
	}
	if (document.getElementById('senha'))
	{
		if (document.getElementById('senha').value == ''){
			window.alert('Você deve preencher o campo senha.');
			document.getElementById('senha').focus();
			return false;
		}
		if (document.getElementById('senha').value.length<5){
			window.alert('A sua senha deve ter mais do que 5 caracteres.');
			document.getElementById('senha').focus();
			return false;
		}
	}
	if (document.getElementById('cidade').value == ''){
		window.alert('Você deve preencher o campo cidade.');
		document.getElementById('cidade').focus();
		return false;
	}
	if (document.getElementById('foto'))
	{
		if (document.getElementById('foto').value == ''){
			window.alert('Você deve selecionar uma foto.');
			document.getElementById('foto').focus();
			return false;
		}
	}
	if (document.getElementById('dia').value == ''){
		window.alert('Você deve preencher o campo dia.');
		document.getElementById('dia').focus();
		return false;
	}
	if (document.getElementById('mes').value == ''){
		window.alert('Você deve preencher o campo mês.');
		document.getElementById('mes').focus();
		return false;
	}
	if (document.getElementById('ano').value == ''){
		window.alert('Você deve preencher o campo ano.');
		document.getElementById('ano').focus();
		return false;
	}
	if(!isDate(document.getElementById('dia').value+'/'+document.getElementById('mes').value+'/'+document.getElementById('ano').value)){
		window.alert('Data inválida.');
		document.getElementById('dia').focus();
		return false;
	}
	if (!document.getElementById('masculino').checked && !document.getElementById('feminino').checked){
		window.alert('Você deve selecionar o sexo.');
		return false;
	}
	if (document.getElementById('ddd_telefone').value == ''){
		window.alert('Você deve preencher o campo DDD do telefone.');
		document.getElementById('ddd_telefone').focus();
		return false;
	}
	if (document.getElementById('telefone').value == ''){
		window.alert('Você deve preencher o campo telefone.');
		document.getElementById('nome').focus();
		return false;
	}
	
	oForm.submit();
	return true;
}

function validaComente(oForm){
	if (document.getElementById('nome').value == ''){
		window.alert('Você deve preencher o campo nome.');
		document.getElementById('nome').focus();
		return false;
	}
	if (document.getElementById('email').value == ''){
		window.alert('Você deve preencher o campo email.');
		document.getElementById('email').focus();
		return false;
	} else {
		if(!isEmail(document.getElementById('email').value)){
			window.alert('Email inválido.');
			document.getElementById('email').focus();
			return false;
		}
	}
	if (document.getElementById('senha').value == ''){
		window.alert('Você deve preencher o campo senha.');
		document.getElementById('senha').focus();
		return false;
	}
	if (document.getElementById('senha').value.length<5){
		window.alert('A sua senha deve ter mais do que 5 caracteres.');
		document.getElementById('senha').focus();
		return false;
	}	
	if (document.getElementById('cidade').value == ''){
		window.alert('Você deve preencher o campo cidade.');
		document.getElementById('cidade').focus();
		return false;
	}
	if (document.getElementById('foto').value == ''){
		window.alert('Você deve selecionar uma foto.');
		document.getElementById('foto').focus();
		return false;
	}
	oForm.submit();
	return true;
}

function validaFaleConosco(oForm){
	if (document.getElementById('contato_nome').value == ''){
		window.alert('Você deve preencher o campo nome.');
		document.getElementById('contato_nome').focus();
		return false;
	}
	if (document.getElementById('contato_email').value == ''){
		window.alert('Você deve preencher o campo email.');
		document.getElementById('contato_email').focus();
		return false;
	} else {
		if(!isEmail(document.getElementById('contato_email').value)){
			window.alert('Email inválido.');
			document.getElementById('contato_email').focus();
			return false;
		}
	}
	
	if (document.getElementById('contato_mensagem').value == ''){
		window.alert('Você deve escrever uma mensagem.');
		document.getElementById('contato_mensagem').focus();
		return false;
	}
	oForm.submit();
	return true;
}



var AvaliacaoMultiple = {
	list: [],
	init: function(source)
	{
			var pos			= AvaliacaoMultiple.list.length;
			AvaliacaoMultiple.list[pos] = source.getElementsByTagName('img');
			source.pos		= pos;
	},
	over: function(source)
	{
		var pos = source.parentNode.pos;
		var idx = 0;
		if(pos == null)return;

		
		for(var counter = 0;counter < AvaliacaoMultiple.list[pos].length;counter++)
			if(AvaliacaoMultiple.list[pos][counter] == source){idx = counter;break;}
		
		for(var counter = 0;counter < AvaliacaoMultiple.list[pos].length;counter++)
			AvaliacaoMultiple.list[pos][counter].setAttribute('src',counter <= idx ? '_images/estrela_on.gif' : '_images/estrela_off.gif');
	},
	action: function(idPromocao, nota){
		
		var request	= getRequestObject(window.AvaliacaoMultipleOK);
		request.startRequest('POST','_services/set_avaliacao.php',new Array(new RequestParam('idPromocao',idPromocao),new RequestParam('nota',nota)));
		
	}
};

function AvaliacaoMultipleOK(source,responseBody){
	alert('Sua avaliação foi computada com sucesso e tem caráter meramente participativo, não interferindo no resultado do concurso. Obrigado!');
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}

function modalFaleConosco() {
	
	var left_pos = (screen.width / 2)  - 260
	
	//document.getElementById('conteinerFaleConosco').style.display = 'block'
	document.getElementById('faleconosco').style.display = 'block'
	//document.getElementById('conteinerFaleConosco').style.left = left_pos + 'px'
	document.getElementById('faleconosco').style.left = left_pos + 'px'
}

function fecharFormFaleConosco() {
	//document.getElementById('conteinerFaleConosco').style.display = 'none'
	document.getElementById('faleconosco').style.display = 'none'
	document.getElementById('form_faleconosco').reset();
}
