
function manipulaCalendario(dia, mes, ano, coddecorador){
	
	if (document.getElementById("div_"+dia+"_"+mes).className == 'calendario_data'){
		document.getElementById("div_"+dia+"_"+mes).className = 'calendario_sel';
	}else{
		document.getElementById("div_"+dia+"_"+mes).className = 'calendario_data';
	}
	makeRequest("manDecoradorAgenda.php?uid="+coddecorador+"&dia=" + dia + "&mes=" + mes + "&ano=" + ano, "div_"+dia+"_"+mes)
}

var dive="";
function makeRequest(url, div) {
 
	http_request = false;
	dive = div;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} 

	if (!http_request) {
		alert('Não pode criar uma instância do XMLHTTP');
		return false;
	}
	
	document.getElementById(div).innerHTML = '';

	http_request.open('GET', url, true);
	http_request.onreadystatechange = alertContents;
	http_request.send(null);

}

function alertContents() {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			document.getElementById(dive).innerHTML = http_request.responseText;
			
		} else {
			document.getElementById(dive).innerHTML = 'X';

		}

		
	}

}



function trocacategoria(galeria){
	GTR_divAjax='conteudo';
	document.galerias.action = 'lisDecoradorImagem.php?cod=' + galeria;
	document.galerias.submit();
}

function limpaDiv(div){
	document.getElementById(div).innerHTML = "";
}

// Faz o calculo do DV do CPF para verificar se está correto ou nao
function ValidaCPF(numCPF) {
    numCPF = numCPF.replace(/\D/g,"");

    if (! (numCPF.length == 11)) {
        return false;
    }

    if (numCPF != '') {
        x = 0;
        soma = 0;
        dig1 = 0;
        dig2 = 0;
        texto = "";
        numCPF1="";
        len = numCPF.length; x = len -1;
        for (var i=0; i <= len - 3; i++) {
            y = numCPF.substring(i,i+1);
            soma = soma + ( y * x);
            x = x - 1;
            texto = texto + y;
        }
        dig1 = 11 - (soma % 11);
        if (dig1 == 10) dig1=0 ;
        if (dig1 == 11) dig1=0 ;
        numCPF1 = numCPF.substring(0,len - 2) + dig1 ;
        x = 11; soma=0;
        for (var i=0; i <= len - 2; i++) {
            soma = soma + (numCPF1.substring(i,i+1) * x);
            x = x - 1;
        }
        dig2= 11 - (soma % 11);
        if (dig2 == 10) dig2=0;
        if (dig2 == 11) dig2=0;
        //alert ("Digito Verificador : " + dig1 + "" + dig2);
        if (!((dig1 + "" + dig2) == numCPF.substring(len,len-2))) {
            return false;
        }
    } else {
        return false;
    }
    return true;
}

function verificaCPF(numCPF){
	if (numCPF.length >= 11){
		if (ValidaCPF(numCPF)){
			document.getElementById('gravar').disabled=false;
			document.getElementById('consulta_cpf').innerHTML = 'CPF válido';
			document.getElementById('consulta_cpf').style.backgroundColor="green";
		}else{
			document.getElementById('gravar').disabled=true;
			document.getElementById('consulta_cpf').innerHTML = '<b>CPF inválido, corrija por favor.</b>';
			document.getElementById('consulta_cpf').style.backgroundColor="red";
		}
	}else{
		document.getElementById('gravar').disabled=true;
		document.getElementById('consulta_cpf').innerHTML = '<b>CPF inválido, corrija por favor.</b>';
		document.getElementById('consulta_cpf').style.backgroundColor="red";
	}
}
function verificarForm(modo){
	if (modo == 1){
		var nn_dessenha			= document.cadform.nn_dessenha.value;
		var nn_conf_dessenha	= document.cadform.nn_conf_dessenha.value;
		if(nn_dessenha == nn_conf_dessenha) { 
			if (gtr_submit('cadform', 'false'))  { 
				GTR_divAjax='conteudo'; 
				return true; 
			} else { 
				return false;
			}
		} else {
			alert('Senha não confere.');
			document.cadform.nn_conf_dessenha.focus();
			return false;
		}
	}else{
		if (gtr_submit('cadform', 'false'))  { 
			GTR_divAjax='conteudo'; 
			return true; 
		} else { 
			return false;
		}
	}
}




function verificarFormCadGaleria(){
	var legenda = document.cadform.legenda.value;
	var imagem = document.cadform.imagem.value;
	var video = document.cadform.video.value;
	
	if (legenda == ''){
		alert('Informe a legenda');
		return false
	}
	else  {
		if ( imagem == "" && video == "" )  {
			alert('Você deve informar uma imagem ou um vídeo');
			return false;
		}
		else  {
			if ( imagem != "" )  { // É imagem
				// verifica extenção da imagem
				var extensao = imagem.substr(imagem.length - 3,3);
				if (extensao.toUpperCase() != 'JPG') {
					alert('Envie apenas imagens JPG');
					return false;
				}
			}
			else {
				if ( video.indexOf("?v=") > -1 )  {
					video	= video.substring(video.indexOf("?v=")+3, 100);
					if ( video.indexOf("&") > -1 )  {
						video	= video.substring(0, video.indexOf("&"));
					}
					document.cadform.video.value=video;
				}
			}
		}
		
		if (gtr_submit('cadform', 'false'))  { 
			GTR_divAjax='conteudo'; 
			return true; 
		} else { 
			return false;
		}
		
	}
}

function verificarFormEditarLegenda()  {
	var legenda = document.cadform.legenda.value;
	if (legenda == ''){
		alert('Informe a legenda');
		return false
	}
	return true;
}



function verificarFormCadDecorador(){
	var nn_dessenha			= document.cadform_decorador.nn_dessenha.value;
	var nn_conf_dessenha	= document.cadform_decorador.nn_conf_dessenha.value;
	//var nn_desendereco_site	= document.cadform_decorador.nn_desendereco_site.value;
	if (document.cadform_decorador.aceita.checked){
		if(nn_dessenha == nn_conf_dessenha && nn_dessenha != '') {
			if (gtr_submit('cadform_decorador', 'false'))  { 
				GTR_divAjax='conteudo'; 
				return true; 
			} else { 
				return false;
			}
		} else {
			alert('As senhas digitadas não estão iguais ou não foram preenchidas.');
			document.cadform_decorador.nn_conf_dessenha.focus();
			return false;
		}
	}else{
		alert("Você deve concordar com o aviso legal");
		return false;
	}
}



function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function validaEndereco(v){
	v=v.replace(/[^a-z0-9]/,"");
    return v;
}


// Página: cadFaleConosco.php
function alternaFormulario(tipo)  {
	obj = document.getElementById('documento');
	obj2= document.getElementById('tiponome');
	if (tipo == "2")  {
		obj.innerHTML = "CNPJ: *";
		obj2.innerHTML = "Empresa: *";
		document.forms['formulario0'].GTR_LBL_nn_descpf.value = "CNPJ";
		document.forms['formulario0'].GTR_LBL_nn_desnome.value = "Empresa";
	}
	else  {
		obj.innerHTML = "CPF: *";
		obj2.innerHTML = "Nome: *";
		document.forms['formulario0'].GTR_LBL_nn_descpf.value = "CPF";
		document.forms['formulario0'].GTR_LBL_nn_desnome.value = "Nome";
	}
}



// Página: cadNewsletter.php
function manipulaCombo(pais){
	if (pais != 274){
		document.cadform.codestado.disabled = true;
		document.cadform.nn_codcidade.disabled = true;
		
		document.cadform.codestado.selectedIndex = 0;
		document.cadform.nn_codcidade.selectedIndex = 0;
	}else{
		document.cadform.codestado.disabled = false;
		document.cadform.nn_codcidade.disabled = false;
	}
}

function verificarFormNewsletter(){
	var f = document.cadform_news;	
	
	var nome	= f.desnome;
	var email	= f.emlemail;
	var tipo	= f.codmailing_tipo;
	var pais	= f.codpais;
	var estado	= f.codestado;
	var cidade	= f.nn_codcidade;
	
	var reg		= /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	
	if (nome.value.length == 0){
		alert("Preencha seu nome");
		nome.focus();
		return false;
	}
	
	if (email.value.length == 0){
		alert("Preencha seu e-mail");
		email.focus();
		return false;
	}else{
		if (reg.test(email.value) == false){
			alert("Preencha um e-mail válido");
			email.focus();
			return false;
		}
	}
	
	if (tipo.value.length == 0){
		alert("Informe tipo");
		tipo.focus();
		return false;
	}
	
	if (pais.value.length == 0){
		alert("Informe seu país");
		pais.focus();
		return false;
	}
	
	if (pais.value == '274'){
		if (estado.value.length == 0){
			alert("informe seu Estado");
			estado.focus();
			return false;
		}
	}
	
	
	if (gtr_submit('cadform_news', 'false'))  { 
		GTR_divAjax='conteudo'; 
		return true; 
	} else { 
		return false;
	}
}

// Página: lisDecoradorCertificado.php

function verificarFormDecCert(){
	if (gtr_submit('cadform', 'false'))  { 
		GTR_divAjax='conteudo'; 
		return true; 
	} else { 
		return false;
	}
}

// Página: lisDecoradorGaleria.php
function verificarFormGaleria(){
	if (document.getElementById('nn_desnome').value == ''){
		alert('Informe o nome da Galeria');
		return false;
	}else{
		if (gtr_submit('cadform', 'false'))  { 
			//GTR_divAjax='Resultado'; 
			return true; 
		} else { 
			return false;
		}
	}
}

// Página: lisDecoradorImagem.php

function alternaUpload(d)  {
	img = document.getElementById("dv_foto");
	vid = document.getElementById("dv_video");
	vi2 = document.getElementById("dv_video2");
	if ( d=="dv_foto" )  {
		img.style.display	= "block";
		vid.style.display	= "none";
		vi2.style.display	= "none";
	}
	else  {
		img.style.display	= "none";
		vid.style.display	= "block";
		vi2.style.display	= "block";
	}
}

// Página: manProdutoIndique.php
function alterna_indicacao(t)  {
	i	= document.getElementById("indicado");
	e	= document.getElementById("formulario_indicar");
	i.style.display=t=="d"?"block":"none";
	e.style.display=t!="d"?"block":"none";
}

// Página: detProdutoDetalhe.php

function esconde(){
	document.getElementById('indiquebloco').style.display="none";
}
function aparece(){
	alterna_indicacao('e');
	document.getElementById('indiquebloco').style.display="block";
}

// Página: lisProdutoBuscaResultado.php
function GtrAjaxCombo(div, tabela, clausula, proximoFilho)  {
	if (proximoFilho=="undefined")  {
		proximoFilho = "";
	}
	document.getElementById(div).innerHTML = 'Aguarde, carregando...';
	makeRequest('gtrAjaxCombo.php?tabela='+tabela+'&clausula='+clausula+'&proximoFilho='+proximoFilho, div);
}

// Página: detAreaDecorador.php
function fecha_pendencia()  {
	document.getElementById('pendencias').style.display="none";
}

function minisite()  {
	//fecha_pendencia();
	GTR_AjaxClick("cadMiniSite.php","conteudo");
}

// Página: 
