// limpa o iFrame (abre um apagina em branco)
// uso: limpaPagina('iDados','branco.asp','document');
function limpaPagina(idObjeto,url,escopo) {
	with(eval(escopo)) {
		document.getElementById(idObjeto).src = url;
	}
}

function toggle(show, hide) {
var mostrar = document.getElementById(show);
var esconder = document.getElementById(hide);

esconder.style.display = "none";
mostrar.style.display = "block";
	
}

function mudarColoracao(page){
var newsletterBar_L01 = document.getElementById('newsletterBar_L01');
var boxBomDia = document.getElementById('boxBomDia');
var formField_EMAIL = document.getElementById('formField_EMAIL');
var formButtomEmail = document.getElementById('formButtomEmail');


if(page == 'MenuItems_HOME'){
	newsletterBar_L01.style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/menuBG02.jpg)';
	newsletterBar_L01.style.backgroundColor = '#78b300';
	
	boxBomDia.style.backgroundColor = '#91cc33';
	
	document.getElementById("email").style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/inputEmail01.jpg)';
	document.getElementById("email").style.border = '1px solid #91CC33';
	document.getElementById("email").style.color = '#000';
	
	document.getElementById("button").style.backgroundColor = '#3a7500';
	document.getElementById("button").style.border = '1px solid #699324';
}

else if(page == 'MenuItems_EVENTO'){
	newsletterBar_L01.style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/menuBG03.jpg)';
	newsletterBar_L01.style.backgroundColor = '#600061';
	
	boxBomDia.style.backgroundColor = '#c945c8';
	
	document.getElementById("email").style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/inputEmail02.jpg)';
	document.getElementById("email").style.border = '1px solid #c945c8';
	document.getElementById("email").style.color = '#000';
	
	document.getElementById("button").style.backgroundColor = '#600061';
	document.getElementById("button").style.border = '1px solid #c945c8';
}

else if(page == 'MenuItems_PARTICIPAR'){
	newsletterBar_L01.style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/menuBG04.jpg)';
	newsletterBar_L01.style.backgroundColor = '#00416b';
	
	boxBomDia.style.backgroundColor = '#0ca4d3';
	
	document.getElementById("email").style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/inputEmail03.jpg)';
	document.getElementById("email").style.border = '1px solid #0ca4d3';
	document.getElementById("email").style.color = '#000';
	
	document.getElementById("button").style.backgroundColor = '#00416b';
	document.getElementById("button").style.border = '1px solid #0ca4d3';
}

else if(page == 'MenuItems_PROGRAMACAO'){
	newsletterBar_L01.style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/menuBG05.jpg)';
	newsletterBar_L01.style.backgroundColor = '#7c5800';
	
	boxBomDia.style.backgroundColor = '#dcbb2b';
	
	document.getElementById("email").style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/inputEmail04.jpg)';
	document.getElementById("email").style.border = '1px solid #dcbb2b';
	document.getElementById("email").style.color = '#000';
	
	document.getElementById("button").style.backgroundColor = '#7c5800';
	document.getElementById("button").style.border = '1px solid #dcbb2b';
}

else if(page == 'MenuItems_VISITACAO'){
	newsletterBar_L01.style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/menuBG06.jpg)';
	newsletterBar_L01.style.backgroundColor = '#6c004c';
	
	boxBomDia.style.backgroundColor = '#cc33a6';
	
	document.getElementById("email").style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/inputEmail05.jpg)';
	document.getElementById("email").style.border = '1px solid #cc33a6';
	document.getElementById("email").style.color = '#000';
	
	document.getElementById("button").style.backgroundColor = '#6c004c';
	document.getElementById("button").style.border = '1px solid #cc33a6';
}

else if(page == 'MenuItems_IMPRENSA'){
	newsletterBar_L01.style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/menuBG07.jpg)';
	newsletterBar_L01.style.backgroundColor = '#7c3000';
	
	boxBomDia.style.backgroundColor = '#d78238';
	
	document.getElementById("email").style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/inputEmail06.jpg)';
	document.getElementById("email").style.border = '1px solid #d78238';
	document.getElementById("email").style.color = '#000';
	
	document.getElementById("button").style.backgroundColor = '#7c3000';
	document.getElementById("button").style.border = '1px solid #d78238';
}

else if(page == 'MenuItems_FALECONOSCO'){
	newsletterBar_L01.style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/menuBG08.jpg)';
	newsletterBar_L01.style.backgroundColor = '#007b59';
	
	boxBomDia.style.backgroundColor = '#32d3a6';
	
	document.getElementById("email").style.backgroundImage = 'url(http://www.salaodolivropp.com.br/images/inputEmail07.jpg)';
	document.getElementById("email").style.border = '1px solid #32d3a6';
	document.getElementById("email").style.color = '#000';
	
	document.getElementById("button").style.backgroundColor = '#007b59';
	document.getElementById("button").style.border = '1px solid #32d3a6';
}
	}


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 +="CNPJ INVALIDO";
		}
		if (erro.length > 0){
			//alert(erro);
			return false;
		}
		return true;
	}


function somenteNumeroSemPontoVirgula(campo){
	var digits="0123456789"
	var campo_temp 
	for (var i=0;i<campo.value.length;i++){
	  campo_temp=campo.value.substring(i,i+1)	
	  if (digits.indexOf(campo_temp)==-1){
		    campo.value = campo.value.substring(0,i);
		    break;
	   }
	}
}

function somente_numero(campo){
	var digits=" -.+0123456789"
	var campo_temp 
	for (var i=0;i<campo.value.length;i++){
	  campo_temp=campo.value.substring(i,i+1)	
	  if (digits.indexOf(campo_temp)==-1){
		    campo.value = campo.value.substring(0,i);
		    break;
	   }
	}
}

function somenteCNPJ(campo){
	var digits=" -.0123456789/"
	var campo_temp 
	for (var i=0;i<campo.value.length;i++){
	  campo_temp=campo.value.substring(i,i+1)	
	  if (digits.indexOf(campo_temp)==-1){
		    campo.value = campo.value.substring(0,i);
		    break;
	   }
	}
}

function Bom_Dia() {

mdata      = new Date()
mhora      = mdata.getHours()
mdia       = mdata.getDate()
mdiasemana = mdata.getDay()
mmes       = mdata.getMonth()
mano       = mdata.getYear()

if (mhora < 12)
    document.write('Bom dia! - ');
else if(mhora >=12 && mhora < 18)
    document.write('Boa Tarde! - ');
else if(mhora >= 18 && mhora < 24)
    document.write('Boa Noite! - ');
if(mdiasemana == 0)
   document.write('Domingo, ');
else if(mdiasemana == 1)
   document.write('Segunda-Feira, ');
else if(mdiasemana == 2)
   document.write('Ter&ccedil;a-Feira, ');
else if(mdiasemana == 3)
   document.write('Quarta-Feira, ');
else if(mdiasemana == 4)
   document.write('Quinta-Feira, ');
else if(mdiasemana == 5)
   document.write('Sexta-Feira, ');
else if(mdiasemana == 6)
   document.write('Sabado, ');

document.write(mdia+' de ');
if(mmes == 0)
   document.write('Janeiro de ');
else if(mmes == 1)
   document.write('Fevereiro de ');
else if(mmes == 2)
   document.write('Mar&ccedil;o de ');
else if(mmes == 3)
   document.write('Abril de ');
else if(mmes == 4)
   document.write('Maio de ');
else if(mmes == 5)
   document.write('Junho de ');
else if(mmes == 6)
   document.write('Julho de ');
else if(mmes == 7)
   document.write('Agosto de ');
else if(mmes == 8)
   document.write('Setembro de ');
else if(mmes == 9)
   document.write('Outubro de ');
else if(mmes == 10)
   document.write('Novembro de ');
else if(mmes == 11)
   document.write('Dezembro de ');

document.write(mano+'');
document.write('');
}

function ano() {

mdata      = new Date()
mano       = mdata.getYear()

document.write(mano+'');
document.write('');
}

function selecionaItemCombo(sel_name, abbr_name) {
	if(abbr_name!='') {
		if(sel_name.length > 0) {
			var maxIndex = sel_name.length;
			for(var i=0; i<maxIndex; i++) {
				if(abbr_name== sel_name.options[i].value) {
					sel_name.selectedIndex = i;
					break;
				}
			}
		}
	}
	return true;    
}


// valida EMAIL
// retornoEmail = validaEmail('email@email.com.br')
function validaEmail(email) {
	if(email.indexOf("@") < 2) {
		return false;
	}
	if(email.indexOf("@",email.indexOf("@") + 1) != -1) {
		return false;
	}
	if(email.indexOf(".") < 1) {
		return false;
	}
	if(email.indexOf(" ") != -1) {
		return false;
	}
	if(email.indexOf("zipmeil.com") > 0) {
		return false;
	}
	if(email.indexOf("hotmeil.com") > 0) {
		return false;
	}
	if(email.indexOf(".@") > 0) {
		return false;
	}
	if(email.indexOf("@.") > 0) {
		return false;
	}
	if(email.indexOf(".com.br.") > 0) {
		return false;
	}
	if(email.indexOf("/") > 0) {
		return false;
	}
	if(email.indexOf("[") > 0) {
		return false;
	}
	if(email.indexOf("]") > 0) {
		return false;
	}
	if(email.indexOf("(") > 0) {
		return false;
	}
	if(email.indexOf(")") > 0) {
		return false;
	}
	if(email.indexOf("..") > 0) {
		return false;
	}

return true
}


function validacao() {
	var enviar = true
	
	var cpf = document.formulario.cpf.value;
	cpfPreparado = preparaCPFValidacao(cpf);
	
	if(validaCPF(cpfPreparado) == false && enviar == true) {
		alert('erro cpf');
		enviar = false;
	}
	
	if(ValidaCNPJ(document.formulario.cnpj) == false && enviar == true) {
		alert('erro cnpj');
		enviar = false;
	}
	
	if (enviar == true) {
		alert("Formulario Enviado");
	}
}

function preparaCPFValidacao(cpf) {
	cpf = cpf.replace('.','');
	cpf = cpf.replace('.','');
	cpf = cpf.replace('-','');
	cpfValidado = cpf;
	return cpfValidado;
}

// valida CPF
// retornoCPF = validaCPF('33200983345')
function validaCPF(s){
 	var i;  
	var c = s.substr(0,9);  
	var dv = s.substr(9,2);  
	var d1 = 0;
  
	for (i = 0; i < 9; i++){   
		d1 += c.charAt(i)*(10-i); 
	} 
  
	if (d1 == 0){  
		var valido = false;
		return false;  
	} 
  
	d1 = 11 - (d1 % 11); 
  
	if (d1 > 9) d1 = 0; 
  
	if (dv.charAt(0) != d1){  
		var valido = false;
		return false;  
	} 
   
	d1 *= 2; 
  
	for (i = 0; i < 9; i++){  
		d1 += c.charAt(i)*(11-i); 
	} 
  
	d1 = 11 - (d1 % 11); 
  
	if (d1 > 9) d1 = 0; 
  
	if (dv.charAt(1) != d1){ 
		var valido = false;
  		return false;   
	} 

return true; 
} 



//--------------------------------------------------------------------
// Valida um campo text que deve conter um CGC DESFORMATADO
// Entradas: e - referência ao campo a ser validado
//           d - mensagem a ser mostrada (alert) em caso de erro
//--------------------------------------------------------------------
function ValidaCNPJ(e) {
	if (e.type == 'text') 	{
		if (!isCNPJ(e.value)) 	{
			if (!e.disabled) e.focus();
			return false;
		}
	}
	return true;
}


//--------------------------------------------------------------------
// isCNPJ
//-------------------------------------------------------------------- 
function isCNPJ(x) {
	strNum = "";  
	if (x == "") return (false);
	l = x.length;
	for (i = 0; i < l; i++) 
	{
	  caracter = x.substring(i,i+1)
	  if ((caracter >= '0') && (caracter <= '9'))
	  {
	     strNum = strNum + caracter;
	  }
	}
	
	strMul = "6543298765432";
	iValido = 1;
	if(strNum.length != 14) return(false);
	iSoma = 0;
	strNum_base = strNum.substring(0,12); 
	iLenNum_base = strNum_base.length - 1;
	iLenMul = strMul.length - 1;
	
	for(i = 0;i < 12; i++)
	{
	   iSoma = iSoma +
						 parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
						 parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)
	}
	
	iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);

	if(iSoma == 11 || iSoma == 10) iSoma = 0;
	
	strNum_base = strNum_base + iSoma; 
	iSoma = 0;
	iLenNum_base = strNum_base.length - 1
	
	for(i=0; i < 13; i++)
	{
		iSoma = iSoma +
						parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
						parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)
	}

	iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);

	if(iSoma == 11 || iSoma == 10)
	{
		iSoma = 0;
	}
	strNum_base = strNum_base + iSoma; 
	if(strNum != strNum_base)
	{
	  return(false);
	}

	return(true);
}



// uso: onkeypress="return mascaraCNPJ(this,event);" maxlength="18"
function mascaraCNPJ(vdateValue,e) {
	var key='';
	var whichCode = (window.Event) ? e.which : e.keyCode;	
	var strCheck = '0123456789';
	
	if (whichCode == 13) return true; // ENTER
	if (whichCode == 8) return true; // Backspace
	if (whichCode == 0) return true; // setas e teclas de (insert-del-home-end-pageUpDown)
	
	//e.preventDefault();
	//var tecla = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	
	key = String.fromCharCode(whichCode); // Pega o valor da tecla digitado
	
	if (strCheck.indexOf(key) == -1) {
		// tecla inválida
		return false;
	}
	

	if (vdateValue.value.length == 2) vdateValue.value=vdateValue.value + '.';
	if (vdateValue.value.length == 6) vdateValue.value=vdateValue.value + '.';
	if (vdateValue.value.length == 10) vdateValue.value=vdateValue.value + '/';
	if (vdateValue.value.length == 15) vdateValue.value=vdateValue.value + '-';
	
	
	return true;
}


// Envia um form para ser processado em uma página
// uso: ExecutarASP(formCadastro,'idExecASP','proprietariosBD.asp');
function ExecutarASP(oForm,target,URL) {
	oForm.target = target;
	oForm.action = URL;
	oForm.submit();
}