function ComparaDatas(data1, data2){

	if (isEmpty(data1) || isEmpty(data2)){
		alert(funcoesjs1);
		return false;
	}
	else{
		
		var modelo = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
		var bate1 = data1.match(modelo);
		var bate2 = data2.match(modelo);
		
		if (bate1 == null) {
		alert(funcoesjs2);
		return false;
		}
		
		if (bate2 == null) {
		alert(funcoesjs3);
		return false;
		}
		
		var month1 = bate1[3];
		var day1 = bate1[1];
		var year1 = bate1[4];
		
		var month2 = bate2[3];
		var day2 = bate2[1];
		var year2 = bate2[4];

		
		var datanew1 = new Date(year1,month1-1,day1);
	 	var datanew2 = new Date(year2,month2-1,day2);
	 	var hoje = new Date();
/*	 	
		if (datanew1<=hoje){
			alert(funcoesjs4);
			return false;
		}
*/		
		if (datanew1>datanew2){
			alert(funcoesjs5);
			return false;
		}
		return true;
	}
}

function PopulaInfo() {
	var eventoid = document.getElementById("eventoid").value;
	if(eventoid!=""){
		$.post("../includes/buscaeventos2.php",
		{eventoide:eventoid},
		function(valorev){
			$("div[name=resultadoevento]").html(valorev);
		}
	)
	}
	else{
		$("div[name=resultadoevento]").html('');
	}
}

function PopulaServico() {
	var eventoid = document.getElementById("eventoid").value;
	if(eventoid!=""){
		$.post("../includes/buscaservicos.php",
		{eventoide:eventoid},
		function(valorev){
			$("select[name=servicoid]").html(valorev);
		}
	)
	}
	else{
		$("select[name=servicoid]").html('<option value="">'+funcoesjs6+'</option>');
	}
}

function PopulaServico2() {
	var eventoid = document.getElementById("eventoid").value;
	if(eventoid!=""){
		$.post("../includes/buscaservicos2.php",
		{eventoide:eventoid},
		function(valorev){
			$("div[name=resultadoleilao]").html(valorev);
		}
	)
	}
	else{
		$("div[name=resultadoleilao]").html('<p style="text-align:center;">'+funcoesjs7+'</p>');
	}
}

function PopulaLocalidade() {
	var estado = document.getElementById("estadoid").value;
	if(estado!=""){
		$.post("../includes/buscalocalidade.php",
		{estadoe:estado},
		function(valor2){
			$("select[name=localidadeid]").html(valor2);
		}
	)
	}
	else{
		$("select[name=localidadeid]").html('<option value="">'+funcoesjs8+'</option>');
	}
}

function PopulaLocalidadeEdita(idlocal) {
	var estado = document.getElementById("estadoid").value;
	if(estado!=""){
		$.post("../includes/buscalocalidadeedita.php",
		{estadoe:estado,
		idlocale:idlocal},
		function(valor2){
			$("select[name=localidadeid]").html(valor2);
		}
	)
	}
	else{
		$("select[name=localidadeid]").html('<option value="">'+funcoesjs8+'</option>');
	}
}


function PopulaLocalidades() {
		var estado = document.getElementById("estadoid").value;
	if(estado!=""){
		$.post("../includes/buscalocalidades.php",
		{estadoe:estado},
		function(valor3){
			$("div[name=localidadeid2]").html(valor3);
		}
	)
	}
	else{
		$("select[name=localidadeid2]").html('');
	}
}

function SalvaFoto() {
		var arquivo = document.getElementById("carregarimagen").value;
	if(arquivo!=""){
		$.post("../includes/salvafoto.php",
		{arquivoe:arquivo},
		function(valor3){
			$("div[name=fotoaparece]").html('<img src="'+valor3+'"><br /><input type = "file" name="carregarimagen" id="carregarimagen" onchange="javascript:SalvaFoto();"></div>');
		}
	)
	}
	else{
		$("select[name=fotoaparece]").html('<img src="images/fotoevento.gif"><br /><input type = "file" name="carregarimagen" id="carregarimagen" onchange="javascript:SalvaFoto();"></div>');
	}
}

function PopulaEvento() {
	var categoria = document.getElementById("tipoevento").value;
	if(categoria!=""){
		$.post("../includes/buscaeventos.php",
		{categoriae:categoria},
		function(valor){
			$("select[name=categoriaevento]").html(valor);
		}
	)
	}
	else{
		$("select[name=tipoevento]").html('<option value="">'+funcoesjs9+'</option>');
	}
}

function PopulaEvento2() {
	var categoria = document.getElementById("tipoevento").value;
	if(categoria!=""){
		$.post("../includes/buscaeventos.php",
		{categoriae:categoria},
		function(valor){
			$("select[name=categoriaevento]").html(valor);
		}
	)
	}
}

function ColocarSelecao(servico,user,evento,categ) {
		$.post("../includes/adicionafavorito.php",
		{servicoe:servico,
		eventoe:evento,
		catege:categ,
		usere:user},
		function(valor){
				$("div[name=selecao]").html(valor);
				if (evento.length>0){
					window.location="detalhesevento.php?id="+evento+"&sec=pes";
				}
			}
	)
}

function ExcluirSelecao(servico2,user2) {
		$.post("../includes/excluifavorito.php",
		{servico2e:servico2,
		user2e:user2},
		function(valor){
			$("div[name=selecao]").html(valor);
		}
	)
}

function cleanbx(elementoid, valororiginal) 
{
var idlimpa = elementoid;
var valor = valororiginal;

if (document.getElementById(idlimpa).value == valororiginal){  
    document.getElementById(idlimpa).value = "";  
}
}

function preenchebx(texto, elementoid2) 
{
var textoaparece = texto;
var idpreenche = elementoid2;

if (document.getElementById(idpreenche).value == ""){  
    document.getElementById(idpreenche).value = textoaparece;
}
}

function isCPFCNPJ(campo){
   if( isEmpty( campo ) ){
	   return false;
   }
	
   if (campo.length==11){
	   var pType=1;
   } else if(campo.length==14){
	   var pType=2;
	} else{
	   return false;
}
   var campo_filtrado = "", valor_1 = " ", valor_2 = " ", ch = "";
   var valido = false;
        
   for (i = 0; i < campo.length; i++){
      ch = campo.substring(i, i + 1);
      if (ch >= "0" && ch <= "9"){
         campo_filtrado = campo_filtrado.toString() + ch.toString();
         valor_1 = valor_2;
         valor_2 = ch;
      }
      if ((valor_1 != " ") && (!valido)) valido = !(valor_1 == valor_2);
   }
   if (!valido) campo_filtrado = "12345678912";

   if (campo_filtrado.length < 11){
      for (i = 1; i <= (11 - campo_filtrado.length); i++){campo_filtrado = "0" + campo_filtrado;}
   }
   
	if(pType == 1){
		
		if ( ( campo_filtrado.substring(9,11) == checkCPF( campo_filtrado.substring(0,9) ) ) && ( campo_filtrado.substring(11,12)=="") ){return true;}
	}

	if((pType == 2) || (pType == 0)){
		if (campo_filtrado.length >= 14){
			if ( campo_filtrado.substring(12,14) == checkCNPJ( campo_filtrado.substring(0,12) ) ){ return true;}
		}
	}
	
	return false;
}

function checkCNPJ(vCNPJ){
   var mControle = "";
   var aTabCNPJ = new Array(5,4,3,2,9,8,7,6,5,4,3,2);
   for (i = 1 ; i <= 2 ; i++){
      mSoma = 0;
      for (j = 0 ; j < vCNPJ.length ; j++)
         mSoma = mSoma + (vCNPJ.substring(j,j+1) * aTabCNPJ[j]);
      if (i == 2 ) mSoma = mSoma + ( 2 * mDigito );
      mDigito = ( mSoma * 10 ) % 11;
      if (mDigito == 10 ) mDigito = 0;
      mControle1 = mControle ;
      mControle = mDigito;
      aTabCNPJ = new Array(6,5,4,3,2,9,8,7,6,5,4,3);
   }
   return( (mControle1 * 10) + mControle );
}

function checkCPF(vCPF){
   var mControle = ""
   var mContIni = 2, mContFim = 10, mDigito = 0;
   for (j = 1 ; j <= 2 ; j++){
      mSoma = 0;
      for (i = mContIni ; i <= mContFim ; i++)
         mSoma = mSoma + (vCPF.substring((i-j-1),(i-j)) * (mContFim + 1 + j - i));
      if (j == 2 ) mSoma = mSoma + ( 2 * mDigito );
      mDigito = ( mSoma * 10 ) % 11;
      if (mDigito == 10) mDigito = 0;
      mControle1 = mControle;
      mControle = mDigito;
      mContIni = 3;
      mContFim = 11;
   }
   return( (mControle1 * 10) + mControle );
}

function isEmpty(pStrText){
	var	len = pStrText.length;
	var pos;
	var vStrnewtext = "";

	for (pos=0; pos<len; pos++){
		if (pStrText.substring(pos, (pos+1)) != " "){
			vStrnewtext = vStrnewtext + pStrText.substring(pos, (pos+1));
		}
	}

	if (vStrnewtext.length > 0)
		return false;
	else
		return true;
}

function VerEmail(texto){
	var inputStr = texto;
	var regmtch = new RegExp(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
	if (!inputStr.match(regmtch)){
		return false;
  }
  return true;
}

var VerificaCaracteres="\\/;:.>,<]}~^[{´`=+§\"\'|ºª*&%¢$£#³²@!¹?°-";

function Proibidos(texto){
   for(i=0; i<texto.length; i++){
      if (VerificaCaracteres.indexOf(texto.charAt(i),0)!=-1){
         return false;
      }
   }
   return true;
} 

function VerificaFiltro(msg) {
        var obj = document.getElementsByTagName("input");
		var cont = 0;
        for (var i=0; i < obj.length; i++) {
        if (obj[i].type == "checkbox")
              if(obj[i].checked == true) cont++;
        }
        if (cont == 0){
			alert(msg);
			return false;
		}
		return true;
    }
    
function MarcaDesmarca(opcao) {
        var obj = document.getElementsByTagName("input");
		if (opcao=="marcar"){
			for (var i=0; i < obj.length; i++) {
			if (obj[i].type == "checkbox")
				obj[i].checked = 1;
			}
		}
		else{
			for (var i=0; i < obj.length; i++) {
			if (obj[i].type == "checkbox")
				obj[i].checked = 0;
			}
		}

    }
   
function BuscaAvancada() {
        document.getElementById("buscaavancada").value ='sim';
		return true;
    }

function EscondeAparece() {
	if ($("#aparece").val()=='escondido'){
			$("#CampoMaisOpcoes").show("fast");
			$("#chegar-tit").hide("fast");
			$("#chegar-map").hide("fast");
			$("#aparece").val('aparecido');
	}
	else{
		$("#CampoMaisOpcoes").hide("fast");
		$("#chegar-tit").show("fast");
		$("#chegar-map").show("fast");
		$("#aparece").val('escondido');
	}
}

function EscondeApareceEmail() {
	if ($("#verenviaremail").val()=='escondido'){
			$("#enviaemail").show("fast");
			$("#verenviaremail").val('aparecido');
	}
	else{
		$("#enviaemail").hide("fast");
		$("#verenviaremail").val('escondido');
	}
}

function RecomendaEmail() {
	if ($("#nome").val() == "" || $("#emailde").val() == "" || $("#emailpara").val() == "" ){
		alert(funcoesjs10);
		return false;
	}
	if (!VerEmail($("#emailde").val()) || !VerEmail($("#emailpara").val())){
			alert(funcoesjs11);
			return false;
	}
	else {
		var meuemail = $("#emailde").val();
		var email = $("#emailpara").val();
		var nome = $("#nome").val();
		var id = $("#servicoid").val();
		$("#verenviaremail").val('escondido');
		$("#resultado").show("fast");
		$("#nome").val("");
		$("#emailde").val("");
		$("#emailpara").val("");
		$("#enviaemail").hide("fast");
		$.post("../includes/mandaemail.php",
		{meuemaile:meuemail, emaile:email, nomee:nome, ide:id},
		function(retorno){
			$("#resposta").html(retorno);
		}
	)
	}
}

function PendenteSalas(id) {
		$.post("../includes/pendentesalas.php",
		{solicitacaoide:id},
		function(valorsolicita){
		}
	)
}

function PendenteServ(id,categoriaid,indiceid) {
		$.post("../includes/pendenteserv.php",
		{solicitacaoide:id,
		indiceide:indiceid,
		categoriaide:categoriaid},
		function(valorsolicita){
		}
	)
}

function SimNao(id) {
		$.post("../includes/simnao.php",
		{solicitacaoide:id},
		function(valorsolicita){
		}
	)
}

function Contato(id) {
		$.post("../includes/contato.php",
		{solicitacaoide:id},
		function(valorsolicita){
		}
	)
}

function Contrato(id) {
		$.post("../includes/contrato.php",
		{solicitacaoide:id},
		function(valorsolicita){
		}
	)
}

function ocult_mselec(){
	var q = parseInt(document.getElementById("qtdml").value);

	for (var i = 5; i < q; i++)	{
		if (document.getElementById('mselec'+i)) {			
		document.getElementById('mselec'+i).style.display = "none";	} }
	document.getElementById('inone').value = 0;	
	document.getElementById('voltaexeb').style.display = "none";
	document.getElementById('vermais').style.display = "";	
}		

function exib_mselec(){
	var inic = parseInt(document.getElementById("inone").value);
	var ml = parseInt(document.getElementById("qtdml").value);

	if ( inic < 1) 
	{	var i = 5; 
		inic = 5;
	} else { 
		var i = inic;
	}

	while ( i <= inic+4 && i <= ml)
	{			
		if (document.getElementById('mselec'+i)){
		document.getElementById('mselec'+i).style.display = "";		
		}
		i++;
	}			
	document.getElementById('inone').value = i;
//	document.getElementById('voltaexeb').style.display = "";	
	if (i >= ml){
		document.getElementById('vermais').style.display = "none";	}
}

