//For IE6 - Background flicker fix
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

noConflit(function() {
	noConflit.datepicker.setDefaults(noConflit.extend(noConflit.datepicker.regional['pt-BR']));
	noConflit('.datepicker').datepicker({
		dateFormat: 'dd/mm/yy',
		numberOfMonths: 1,
		showMonthAfterYear: false,
		showButtonPanel: true,	
		changeMonth: true,
		changeYear: true,
		
		showOn: 'button', // choose, focus, button
		buttonImage: base_url+'img/img_busca1.jpg', 
		buttonImageOnly: true

	}).mask("99/99/9999").blur(function(){
		if(validate_date(noConflit(this).val()) == false){
		//	noConflit(this).css({'border-color': 'red'});			
		}else{
			noConflit(this).css({'border-color': ''});				
		}	
	});


	noConflit('.datepicker_search').datepicker({
		dateFormat: 'dd/mm/yy',
		numberOfMonths: 1,
		showMonthAfterYear: false,
		showButtonPanel: true,	
		changeMonth: true,
		changeYear: true,
		
		showOn: 'button', // choose, focus, button
		buttonImage: base_url+'img/img_busca1.jpg', 
		buttonImageOnly: true

	}).focus(function(){	
		noConflit(this).mask("99/99/9999");
	}).blur(function(){
		noConflit(this).unmask();
		if(noConflit(this).val() == ''/* || noConflit(this).val() == '__/__/____'*/){
			noConflit(this).val('dd/mm/aaaa');
		}		
	});
	
	// Mascara para campos de Hora
	noConflit('.timepicker').mask("99:99").blur(function(){
		if(validate_time(noConflit(this).val()) == false){
		//	noConflit(this).css({'border-color': 'red'});			
		}else{
			noConflit(this).css({'border-color': ''});				
		}	
	});	
});

/*
*    Script:    Mascaras em Javascript
*    Autor:    Matheus Biagini de Lima Dias
*    Data:    26/08/2008
*    Obs:    
*/
    /*Função  Pai de Mascaras*/
    function Mascara(o,f){
        v_obj=o
        v_fun=f
        setTimeout("execmascara()",1)
    }
    
    /*Função que Executa os objetos*/
    function execmascara(){
        v_obj.value=v_fun(v_obj.value)
    }
    
    /*Função que Determina as expressões regulares dos objetos*/
    function leech(v){
        v=v.replace(/o/gi,"0")
        v=v.replace(/i/gi,"1")
        v=v.replace(/z/gi,"2")
        v=v.replace(/e/gi,"3")
        v=v.replace(/a/gi,"4")
        v=v.replace(/s/gi,"5")
        v=v.replace(/t/gi,"7")
        return v
    }
    
    /*Função que permite apenas numeros*/
    function Integer(v){
        return v.replace(/\D/g,"")
    }
    
    /*Função que padroniza  telefone (11) 4184-1241*/
    function Telefone(v){
        v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
	    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
	    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
	    return v
    }
    
    /*Função que padroniza telefone (11) 41841241*/
    function TelefoneCall(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2")    
        return v
    }
    
    /*Função que padroniza CPF*/
    function Cpf(v){
        v=v.replace(/\D/g,"")                    
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
                                                 
        v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CEP*/
    function Cep(v){
        v=v.replace(/D/g,"")                
        v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CNPJ*/
    function Cnpj(v){
                v=v.replace(/\D/g,"")                              
                v=v.replace(/^(\d{2})(\d)/,"$1.$2")      
                v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
                v=v.replace(/\.(\d{3})(\d)/,".$1/$2")              
                v=v.replace(/(\d{4})(\d)/,"$1-$2")                        
                return v
        }


    /*Função que padroniza DATA*/
    function Data(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        return v
    }
    
    /*Função que padroniza DATA*/
    function Hora(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1:$2")  
        return v
    }

//Validar CPF
function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }

function validarCPF(cpf){
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
                 return false;
   }
   
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
    
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
                  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
                  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
                  cpf == "88888888888" || cpf == "99999999999"){
                  return false;
   }

   soma = 0;
   for(i = 0; i < 9; i++)
                 soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
                 resto = 0;
   if(resto != parseInt(cpf.charAt(9))){
                 return false;
   }
   soma = 0;
   for(i = 0; i < 10; i ++)
                 soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
                 resto = 0;
   if(resto != parseInt(cpf.charAt(10))){
                 return false;
   }
   return true;
 }

function mailpage()

{
mail_str = "mailto:?subject=Notícia " + document.title;
mail_str += "&body=Oi ";
mail_str +="%0D%0A";
mail_str += "Esta notícia é muito interessante.";
mail_str +="%0D%0A";
mail_str += document.title;
mail_str +="%0D%0A";
mail_str += "Para vê-la, clique neste link:";
mail_str +="%0D%0A";
mail_str += location.href;
location.href = mail_str;
}
function FormataCnpj(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 != 14)
	{
		if (tam == 3)
			campo.value = vr.substr(0, 2) + '.';
		if (tam == 6)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
		if (tam == 10)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
		if (tam == 15)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
	}
}


//Função Ajax para verificar CNPJ sem refresh na página
 
function validarDados(tipo) {

	var cnpj = document.getElementById("Cnpj");
	
	noConflit.ajax({
		type: "POST",
		url: site_url+"estabelecimento/verificarCnpj/"+tipo,
		data: "Cnpj="+cnpj.value,
		success: function(msg){
			
			noConflit('#campo_Cnpj').css("display","block");
			document.getElementById('campo_Cnpj').innerHTML = msg;
		}
	});
 
}


function deletaDados (nome,id,usuario)
{
	if(confirm("Deseja deletar este item?")) {	
		noConflit.ajax({
			type: "GET",
			url: site_url+"estabelecimento/deleta"+nome+"/"+id+"/"+usuario,
			success: function(msg){ 
				
				if(msg != "Erro") 
				{
					document.getElementById(nome).innerHTML = msg;
					
				} else {
					
					alert("Erro")
				}
				
			}
		});
	}
}

 function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){    
     var sep = 0;    
     var key = '';    
     var i = j = 0;    
     var len = len2 = 0;    
     var strCheck = '0123456789';    
     var aux = aux2 = '';    
     var whichCode = (window.Event) ? e.which : e.keyCode;    
     if (whichCode == 13 || whichCode == 8) return true;    
     key = String.fromCharCode(whichCode); // Valor para o código da Chave    
     if (strCheck.indexOf(key) == -1) return false; // Chave inválida    
     len = objTextBox.value.length;    
     for(i = 0; i < len; i++)    
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;    
     aux = '';    
     for(; i < len; i++)    
         if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);    
     aux += key;    
     len = aux.length;    
     if (len == 0) objTextBox.value = '';    
     if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;    
     if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;    
     if (len > 2) {    
         aux2 = '';    
         for (j = 0, i = len - 3; i >= 0; i--) {    
             if (j == 3) {    
                 aux2 += SeparadorMilesimo;    
                 j = 0;    
             }    
             aux2 += aux.charAt(i);    
             j++;    
         }    
         objTextBox.value = '';    
         len2 = aux2.length;    
         for (i = len2 - 1; i >= 0; i--)    
         objTextBox.value += aux2.charAt(i);    
         objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);    
     }    
     return false;    
 } 
 
function FormataCnpj(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 != 14)
	{
		if (tam == 3)
			campo.value = vr.substr(0, 2) + '.';
		if (tam == 6)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
		if (tam == 10)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
		if (tam == 15)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
	}
}
function Formatacep(Campo, teclapres)
{
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("-", "");
	tam = vr.length + 1;
	if (tecla != 8)
	{
		if (tam == 6)
			Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, 5);
	}
}

function select_hospedagem(array)
{
		noConflit("#op_hospedagem").html("");
		noConflit.ajax({
		type: "POST",
		url: site_url+"pacotes/verificarHospedagem",
		data: "cidades="+array,
		success: function(msg){
			
			noConflit("#op_hospedagem").html(msg);
		}
		});
		
	
}
			
