 // JavaScript Document

var w=1
var h=1

if (document.getElementById || document.all)
document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;line-height:18px; padding:5px;background:url(imagens/pictograma/box_dialogo.png);z-index:2;font-family:Arial, Helvetica, sans-serif;font-size:11px;"></div>')

function gettrailobj()
{
	if (document.getElementById) return document.getElementById("trailimageid").style
	else if (document.all) return document.all.trailimagid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{
	document.onmousemove=""
	document.getElementById('trailimageid').innerHTML = ""
	gettrailobj().visibility="hidden"
	gettrailobj().left=-1000
	gettrailobj().top=0
}


function showtrail(width,height,file)
{
	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1)
	{
		w=width
		h=height
		
		// followmouse()
	
		document.getElementById('trailimageid').innerHTML = file;
		document.onmousemove=followmouse
		gettrailobj().visibility="visible"
		gettrailobj().width=w+"px"
		gettrailobj().height=h+"px"


	}
}


function followmouse(e)
{

	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1)
	{

		var xcoord=60
		var ycoord=-10

		if (typeof e != "undefined")
		{
			xcoord+=e.pageX
			ycoord+=e.pageY
		}
		else if (typeof window.event !="undefined")
		{
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}

		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if (xcoord+w+3>docwidth)
		xcoord=xcoord-w-(20*2)

		if (ycoord-truebody().scrollTop+h>truebody().clientHeight)
		ycoord=ycoord-h-20;

		gettrailobj().left=xcoord+"px"
		gettrailobj().top=ycoord+"px"

	}

}
/*fim*/


 
 function validaCPF(cpf) {
		
		 erro = new String;
		 cpf = cpf.substring(0,11)
		 if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificação do CPF! \n\n";
		 var nonNumbers = /\D/;
		 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";
		 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
				 erro += "Número de CPF inválido!"
	   }
	   var a = [];
	   var b = new Number;
	   var c = 11;
	   for (i=0; i<11; i++){
			   a[i] = cpf.charAt(i);
			   if (i < 9) b += (a[i] * --c);
	   }
	   if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	   b = 0;
	   c = 11;
	   for (y=0; y<10; y++) b += (a[y] * c--);
	   if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	   if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
			   erro +="Digito verificador com problema!";
	   }
	   if (erro.length > 0){
			   //alert(erro);
			   return false;
	   }
	   return true;
}



function validaCNPJ(CNPJ) {
  erro = new String;
  if (CNPJ.length < 18) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
  if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
  if (erro.length == 0) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
  }
  //substituir os caracteres que nao sao numeros
  if(document.layers && parseInt(navigator.appVersion) == 4){
  x = CNPJ.substring(0,2);
  x += CNPJ.substring(3,6);
  x += CNPJ.substring(7,10);
  x += CNPJ.substring(11,15);
  x += CNPJ.substring(16,18);
  CNPJ = x; 
  } else {
  CNPJ = CNPJ.replace(".","");
  CNPJ = CNPJ.replace(".","");
  CNPJ = CNPJ.replace("-","");
  CNPJ = CNPJ.replace("/","");
  }
  var nonNumbers = /\D/;
  if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n"; 
  var a = [];
  var b = new Number;
  var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
  for (i=0; i<12; i++){
  a[i] = CNPJ.charAt(i);
  b += a[i] * c[i+1];
  }
  if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
  b = 0;
  for (y=0; y<13; y++) {
  b += (a[y] * c[y]); 
  }
  if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
  if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
  erro +="Digito verificador com problema!";
  }
  if (erro.length > 0){
  //alert(erro);
  return false;
  } else {
 // alert("CNPJ valido!");
  }
  return true;
}



function validaFormGeral(id)
{
	if(id != "")

	{

		//obj = document.getElementById(id).getElementsByTagName("select");	

		obj = $("#"+id + " .obrigatorio")

	}

	else

	{

		//obj = document.getElementsByTagName("select");

		obj = $(".obrigatorio")

	}	

	
	
	for (i=0;i<obj.length;i++)

	{

		if(obj[i].value == "" && obj[i].type != "radio" && obj[i].type != "checkbox")
		{

			alert("Preencha o campo "+obj[i].title)

			//objFocus = obj[i]
			obj[i].focus()
			
			return false

			break;

		}
		if( obj[i].type == "radio" || obj[i].type == "checkbox")
		{
			
			if( $("input[name='" + obj[i].name + "']:checked").length ==0 )	
			{
				alert("Selecione - "+obj[i].title)

				//objFocus = obj[i]
				obj[i].focus()
				
				return false
	
				break;		
			}
		}
		

	}
	
	if (validaEmails() == false)

	{

		return false

	}

	if (validaDatas() == false)

	{

		return false

	}

	if (validaValorFloat() == false)

	{

		return false

	}
	if( $("input[name='cpf']").length > 0)
	{
		if( $("input[name='cpf']").val() != "")
		{
			var wcpf = $("input[name='cpf']").val()
			wcpf = wcpf.replace(".","")
			wcpf = wcpf.replace(".","")
			wcpf = wcpf.replace(".","")
			wcpf = wcpf.replace("-","")	
			
			if( validaCPF(wcpf)	== false )
			{
				objFocus = $("input[name='cpf']")
				objFocus.focus()
				alert("CPF inválido, digite novamente")
				return false;
			}
		}
	}
	if( $("input[name='cnpj']").length > 0)
	{
		if( $("input[name='cnpj']").val() != "")
		{
			var wcpf = $("input[name='cnpj']").val()
						
			if( validaCNPJ(wcpf) == false )
			{
				objFocus = $("input[name='cnpj']")
				objFocus.focus()
				alert("CNPJ inválido, digite novamente")
				return false;
			}
		}
	}
	if ( ( $("input[name='senha2']").length > 0 ||  $("input[name='senhac']").length > 0) && ( $("#senha").length > 0 ))
	{							
		var senhaConf = "";
		if( $("input[name='senha2']").length > 0)
		{
			senhaConf = $("input[name='senha2']").val()
		}
		else
		{
			senhaConf = $("input[name='senhac']").val()	
		}
		
		if( senhaConf != $("#senha").val() )
		{
			objFocus = $("#senha")
			objFocus.focus()
			alert("Senhas não correspondem, digite novamente");
			return false;
		}
	}	
	
	return true

}
function validaEmails()
{
	obj = document.getElementsByTagName("input");
	for (i=0;i<obj.length;i++)
	{		
		if (obj[i])
		{
			if( (obj[i].alt == "email") && (obj[i].value != "") )  
			{
				if (validaEmail(obj[i].value) == false)
				{
					alert("E-mail inválido");
					obj[i].focus();
					return false
					break;
				}
			}
			
		}
	}
	return true;		
}
function validaFormGeral2(id)
{
		
	
	if(validaInput(id) == true)
	{
		if (validaDatas() == false)
		{
			return false;	
		}
		else
		{
			if(validaSelect(id) == true)
			{
				if(validaTextArea(id) == true)
				{
					if (validaValorFloat() == false)
					{
						return false;
					}
					else
					{
						return true;
					}
				}
				else
				{
					return false;	
				}
			}
			else
			{
				return false;	
			}
		}	
	}
	else
	{
		return false;	
	}	
}
function validaValorFloat()
{
	obj = document.getElementsByTagName("input");
	for (i=0;i<obj.length;i++)
	{		
		if (obj[i])
		{
			if( (obj[i].alt == "valor") && (obj[i].value != "") )  
			{
				if (isFloat(obj[i].value) == false)
				{
					alert("Valor inválido");
					obj[i].focus();
					return false
					break;
				}
			}
			
		}
	}
	return true;
}

function validaData(data)
{
	var expre =	/^(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[0-2])\/(19|20)?\d{2}$/;
	if (expre.test(data) == false)
	{
		return false;
	}
	return true
}
function isNumeric(valor)
{
   	var valor_text;
    var vetor;
    var cont;

    valor_text = valor;
    vetor = "";
    cont = 0;    

    for(var i = 0; i < valor_text.length; i++)
    {
  		if (valor_text.charCodeAt(i) < 43 || valor_text.charCodeAt(i) > 58)
	  	{
		  vetor = vetor + valor_text.charAt(i);
		  cont++;
	 	}
	}
    
    if(cont == 0)
    {
  		return true;    
    }
    else
    {
  		return false;
    }
}
function validaEmail(email)
{
	
	var reTipo = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	return reTipo.test(email);

}


function validaCont(id)
{
	if (validaFormGeral(id) == false)
	{
		return false;
	}
	if (document.getElementById("mensagem").value == "")
	{
		alert("Preencha o campo Mensagem");
		document.getElementById("mensagem").focus();
		return false;
	}
}
function validaDatas()
{
	
	obj = document.getElementsByTagName("input");
	for (i=0;i<obj.length;i++)
	{		
		if (obj[i])
		{
			if( (obj[i].value != "") && (obj[i].alt == "data") )
			{
				if( validaData(obj[i].value) == false)
				{
					alert(obj[i].title + " inválida")
					obj[i].focus();
					return false
					break;
				}
			}

		}
	}
	return true;
	
}
function tipo_arq(qtdIni,qtdFin,tipo,extensoes)
{
	//Tipo - S - quando obrigatorio insercao de foto - N -  somente verifica a axtensao do arquivo
	
	cont = 0;
	for(var i = qtdIni; i <= qtdFin; i++)
	{
		foto = document.getElementById("arquivo" + i);
		if(foto)
		{
			if (foto.value != "" )
			{		
				wfoto = foto.value
				indice = wfoto.indexOf(".");
				indice = indice + 1; 
				//wfoto = wfoto.substr(indice);
				wfoto = wfoto.substring(wfoto.length-3)
				wfoto = wfoto.toLowerCase();
				
				vetExtensao = extensoes.split("|")
				erro = true
				for(y=0;y<vetExtensao.length;y++)
				{
					if(wfoto == vetExtensao[y])
					{
						erro = false		
					}
				}
				if (erro == true)
				{
					alert(foto.title + " - extensão não permitida");
					objFocus = obj[i]
					return false;
					break;
					
				}
				
				cont = parseInt(cont) + 1;
			}
			
		}
		
	}	
	if (tipo == "S")
	{
		if (cont <= 0 )
		{
			alert("Nenhum arquivo inserido");
			return false;
		}
	}
	return true
	
}

function validaEventos()
{			
	
	if(document.getElementById("tipo").value == "")
	{
		alert("Preencha o campo Tipo de evento");			
		document.getElementById("tipo").focus();
		return false;
	}
	if(validaFormGeral() == false)
	{
		return false;				
	}
	
	if(document.getElementById("mensagemCov").value == "")
	{
		alert("Preencha o campo Mensagem ao convidados");			
		document.getElementById("mensagemCov").focus();
		return false;
	}
	
	foto5 = document.getElementById("imagem")
	if( (foto5) && (document.getElementById("imagem").value != "") )
	{					
		var validos = /(jpg|jpeg|JPG|JPEG)/;
		var campo = document.getElementById("imagem").value
		var ext = campo.substring(campo.length-3,campo.length);
		if ( !validos.test( ext ) ) {
			alert('este tipo de arquivo nao eh permitido: '+ext);
			document.getElementById("imagem").focus();
			return false;
	   }			
	}
	
	if(document.getElementById("banco").value != "")
	{
		if(document.getElementById("banco").value == 0)
		{
			if(document.getElementById("nome_outro_banco").value == "")
			{
				alert("Preencha o campo Nome banco");
				document.getElementById("nome_outro_banco").focus();
				return false
			}			
									   
		}
		if(document.getElementById("agencia").value == "")
		{
			alert("Preencha o campo agência");
			document.getElementById("agencia").focus();
			return false
		}
		if(document.getElementById("conta").value == "")
		{
			alert("Preencha o campo Conta");
			document.getElementById("conta").focus();
			return false
		}
		if(document.getElementById("nome_titular").value == "")
		{
			alert("Preencha o campo Nome titular");
			document.getElementById("nome_titular").focus();
			return false
		}
		
		if(document.getElementById("tipoDoc1").checked == true)
		{
			
			if(document.getElementById("cpf_t").value == "")	
			{
				alert("Preencha o campo CPF")	
				return false;
				document.getElementById("cpf_t").focus();	
			}
			wcpf = document.getElementById("cpf_t").value;
			wcpf = wcpf.replace(".","")
			wcpf = wcpf.replace(".","")
			wcpf = wcpf.replace(".","")
			wcpf = wcpf.replace("-","")
			if( validaCPF(wcpf) == false)
			{
				alert("CPF inválido");
				document.getElementById("cpf_t").focus();
				return false;
			}
			document.getElementById("cpf_titular").value = document.getElementById("cpf_t").value;
		}
		if(document.getElementById("tipoDoc2").checked == true)
		{
			
			if(document.getElementById("cnpj_t").value == "")	
			{
				alert("Preencha o campo CNPJ")	
				return false;
				document.getElementById("cnpj_t").focus();	
			}
			wcnpj = document.getElementById("cpf_t").value;
			
			if( validaCNPJ(wcnpj) == false)
			{
				alert("CNPJ inválido");
				document.getElementById("cnpj_t").focus();
				return false;
			}	
			document.getElementById("cpf_titular").value = document.getElementById("cnpj_t").value;
		}
		
	}
	else
	{
		alert("Selecione um banco")	
		return false;
		document.getElementById("banco").focus();
	}
	
	
	
	
}

function validaFornec()
{
	
	if( $("#tipo1").attr("checked"))
	{
		if( validaFormGeral('pessoaF') )
		{
			return validaFormGeral('geral')
		}
		else
		{
			return false
		}
	}
	else
	{
		if( validaFormGeral('pessoaJ'))
		{
			return validaFormGeral('geral')
		}
		else
		{
			return false
		}
	}
			
}

function validaProfissional(id)
{
	if(validaFormGeral(id))
	{
		if( tipo_arq("1","1","N","jpg|") )
		{
			/*obj = document.getElementById("selececaoFranquia").getElementsByTagName("input")
			erro = true
			for(i=0;i<obj.length;i++)
			{
				if(obj[i].checked == true)
				{
					erro = false
					break
				}
			}
			if(erro == true)
			{
				alert("Selecione a(s) franquia(s) que o profissional terá acesso")
				return false
			}*/
			return true		
		}
		else
		{
			return false
		}
	}
	else
	{
		return false
	}
	
}



