/***
* Descri??o.: formata um campo do formul?rio de
* acordo com a m?scara informada...
* Par?metros: - objForm (o Objeto Form)
* - strField (string contendo o nome
* do textbox)
* - sMask (mascara que define o
* formato que o dado ser? apresentado,
* usando o algarismo "9" para
* definir n?meros e o s?mbolo "!" para
* qualquer caracter...
* - evtKeyPress (evento)
* Uso.......: <input type="textbox"
* name="xxx".....
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
* Observa??o: As m?scaras podem ser representadas como os exemplos abaixo:
* CEP -> 99.999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* Data -> 99/99/9999
* Tel Resid -> (99) 999-9999
* Tel Cel -> (99) 9999-9999
* Processo -> 99.999999999/999-99
* C/C -> 999999-!
* E por a? vai...
***/

function txtBoxFormat(strField, sMask, evtKeyPress) {
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

     if(window.event) { // Internet Explorer
       nTecla = evtKeyPress.keyCode; }
     else if(evtKeyPress.which) { // Nestcape / firefox
       nTecla = evtKeyPress.which;
     }
    //se for backspace n?o faz nada
    if (nTecla != 8){
     sValue = document.getElementById(strField).value;
    // alert(sValue);

     // Limpa todos os caracteres de formata??o que
     // já estiverem no campo.
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( " ", "" );
     sValue = sValue.toString().replace( " ", "" );
	 
     fldLen = sValue.length;
     mskLen = sMask.length;

     i = 0;
     nCount = 0;
     sCod = "";
     mskLen = fldLen;

     while (i <= mskLen) {
       bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
       bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

       if (bolMask) {
         sCod += sMask.charAt(i);
         mskLen++; }
       else {
         sCod += sValue.charAt(nCount);
         nCount++;
       }

       i++;
     }

     document.getElementById(strField).value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas n?meros...
         return ((nTecla > 47) && (nTecla < 58)); } // n?meros de 0 a 9
       else { // qualquer caracter...
         return true;
       } }
     else {
       return true;
     }
    }//fim do if que verifica se ? backspace
}
//Fim da Fun??o M?scaras Gerais


// MASCARA DE NUMERO

function MascaraLetras(objeto)
{
campo = eval (objeto);
	caracteres = '01234567890';
	if (caracteres.search(String.fromCharCode(window.event.keyCode))!=-1){ 
		return false;
	}
}
function MascaraNumero(objeto)
{
campo = eval (objeto);
	caracteres = '0123456789';
	if (caracteres.search(String.fromCharCode(window.event.keyCode)) == -1){ 
		return false;
	}
}
function verificaEquivalencias(){

	

	if (document.contato.senha.value != document.contato.senha2.value)  // Aqui faz a compara??o se a senha 1 confere com a senha2 
	{ 
		alert ("As senhas n?o Conferem"); //Dispara o alerta caso a condi??o n?o seja favor?vel 
		contato.senha.focus(); // Aqui manda o foco voltar para a senha1
		return false; 
	} 
	
return true; 

}


function abreBox(){
	param = 'processado';
	param2 = 'img_alpha';
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	document.getElementById(param).style.height = (windowHeight+200)+'px';
	document.getElementById(param).style.width = 100+'%';
	document.getElementById(param).style.visibility = "visible"; 
	document.getElementById(param).style.overflow = "hidden";


	document.getElementById(param2).style.height = (windowHeight+200)+'px';
	document.getElementById(param2).style.width = 100+'%';
	document.getElementById(param2).style.visibility = "visible"; 
	document.getElementById(param2).style.overflow = "hidden";

		
}


var ativado2
function abreDIVOBS(param) {
   if (ativado2 != null){
   ativado2.style.visibility = "hidden";
	}
   document.getElementById(param).style.visibility = "visible"; 
   
   ativado2 = document.getElementById(param);  
   return ativado2;
}
function fechaDIVOBS(param) {
   document.getElementById(param).style.visibility = "hidden";
   ativado2 = null;
   return ativado2;
}
var ativado
function abreDIV(param) {
   if (ativado != null){
   ativado.style.visibility = "hidden";
   ativado.style.overflow = "auto";
	ativado.style.height = 0;
	}
   document.getElementById(param).style.visibility = "visible"; 
   document.getElementById(param).style.overflow = "auto";
   document.getElementById(param).style.height = "auto";
   document.getElementById(param).style.position = "relative";
   ativado = document.getElementById(param);  
}
function fechaDIV(param) {
   document.getElementById(param).style.visibility = "hidden";
   document.getElementById(param).style.overflow = "hidden";
   document.getElementById(param).style.position = "absolute";
   document.getElementById(param).style.height = 0;
   ativado = null;
}



jaabriudiv = false;
$j(function(){
	if(!jaabriudiv){		
	$j('.lista').slideUp();
	}
	
});


function abre_fechaDIV(param){	
	$j('.lista').slideUp();
	$j('#'+param).slideDown("slow");
	jaabriudiv = true;
}

function abre_fechaDIVUnica(param){	
	$j('#'+param).slideDown("slow");
	jaabriudiv = true;
}


function abre_fechaDIV2(param){
   if (ativado != null)
 			 {
   			ativado.style.visibility = "hidden";
			ativado.style.position = "absolute"
		     ativado.style.overflow = "hidden";
			 ativado.style.height = 0;
			
	   if (ativado == document.getElementById(param)){
			ativado = null ;
	   }else{

	   		document.getElementById(param).style.visibility = "visible";
			
		
			
			document.getElementById(param).style.overflow = "hidden";
			document.getElementById(param).style.height = "auto";
			document.getElementById(param).style.position = "relative";
			
	   		ativado = document.getElementById(param);  
	   }
   }else{

   		document.getElementById(param).style.visibility = "visible"; 
		document.getElementById(param).style.overflow = "hidden";
		document.getElementById(param).style.height = "auto";
		document.getElementById(param).style.position = "relative";
		
		ativado = document.getElementById(param);  
   }
}
function ffff() {
  var oField;
  if (document.forms.length > 0) {
    for (var i=0; i < document.forms[0].elements.length; ++i) {
      oField = document.forms[0].elements[i];
      if ((oField.type != "hidden") && (oField.type != "select-one")) {
if (oField.disabled!=true) {
          oField.focus();
  break;
}
      }
    }
  }
}

<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
			var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
			for (i=0; i<(args.length-2); i+=3) { 
					test=args[i+2]; 
					val=document.getElementById(args[i]);
					if (val) { 
							nm=val.name; 
							if ((val=val.value)!="") {
								if (test.indexOf('isEmail')!=-1) { 
									p=val.indexOf('@');
									if (p<1 || p==(val.length-1)) { 
											errors+='- '+nm+' precisa conter um endereço de e-mail válido.\n';
									}
								}else{
									if (test!='R') { 
												num = parseFloat(val);
												if (isNaN(val)){ 
															errors+='- '+nm+' Precisa conter um número.\n';
												}
												if (test.indexOf('inRange') != -1) { 
															p=test.indexOf(':');
															min=test.substring(8,p); max=test.substring(p+1);
															if (num<min || max<num){
																	errors+='- '+nm+' Precisa conter um numero entre '+min+' e '+max+'.\n';
															}
												}
												if (test.indexOf('isSelected') != -1) { 
													if ((val == 0) || (val == '')){ 
															errors += '- '+nm+' preciza ter alguma opção válida.\n';
													}		
												}
												if ((test.indexOf('isCheked') != -1) || (test.indexOf('isRadio') != -1)) { 
													vart = false;
													if (val.length != null) {
														for (j=0; val.length; j++){	
															if (val[j].checked){ 
																	vart = true;
															}	
														}
													}else {
														if (val.checked){ 
																vart = true;
														}	
													}
													if (vart) errors += '- '+nm+' preciza ter alguma opção marcada.\n';
												}
									}
								}
							}else {
								if (test.charAt(0) == 'R') errors += '- '+nm+' não pode estar em branco.\n';
							}
					}
			}
			if (errors) alert('Os seguintes erro(s) ocorreram:\n'+errors);
			document.MM_returnValue = (errors == '');
	}
}
//-->

function criaXMLHttp() {
	if (typeof XMLHttpRequest != "undefined")
		return new XMLHttpRequest();
	else if (window.ActiveXObject){
		var versoes = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0", "Msxml2.XMLHttp.3.0","Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
	}
	for (var i = 0; i < versoes.length; i++){
		try{
			return new ActiveXObject(versoes[i]);
		}catch (e) {}
	}
throw new Error("Seu browser nao suporta AJAX");
}

function testaDDD(campo){
	if(campo.value != '83'){
	
		campo.value = '';
		this.focus();
		alert('Só trabalhamos com entrega na Paraíba');
	}
}
function abreAjax(id, metodo, url, retorno1) {
	
	

	var divInfo = document.getElementById(id);
	var retorno = document.getElementById(retorno1);
	var minha = abreDIVOBS(retorno1);
	var url = url;
	retorno.innerHTML = '';
	retorno.innerHTML = '<div class="area"><h3>Aviso</h3><p><img src="images/loding.gif" width="10" height="10">Aguarde ...</p></div><hr/>';
	var XMLHttp = criaXMLHttp();
	
	
	if((metodo == "GET") || (metodo == "get")) {
		XMLHttp.open("GET", url, true);
	} else { 
		
		XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		XMLHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		XMLHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		XMLHttp.setRequestHeader("Pragma", "no-cache");
		XMLHttp.open("POST", url, true);
	} 
	
	XMLHttp.onreadystatechange = function () {
	
	if (XMLHttp.readyState == 4)
		if (XMLHttp.status == 200){
			retorno.innerHTML = '';
			retorno.innerHTML = '<div class="area"><h3>Aviso</h3><p>Aguarde, Atualizando dados ...</p></div><hr/>';
			fechaDIVOBS(retorno1);
			divInfo.innerHTML = unescape(escape(XMLHttp.responseText));
		
		} else {
			fechaDIVOBS(retorno1);
			divInfo.innerHTML = "Um erro ocorreu" + XMLHttp.statusText;
		}
	};

XMLHttp.send(null);
}



function create_opcao(cidade) { //Cria um novo elemento OPTION.
    var new_opcao = document.createElement("option"); //Cria um OPTION.
    var texto = document.createTextNode(cidade.childNodes[0].data); //Cria um texto.
    new_opcao.setAttribute("value",cidade.getAttribute("id")); //Adiciona o atributo de valor a nova opção.
    new_opcao.appendChild(texto); //Adiciona o texto a OPTION.
    return new_opcao; // Retorna a nova OPTION.
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function cepAjax(id, metodo, url, meuform) {
	
	
	meuform = eval('document.'+ meuform);
	var divInfo = document.getElementById(id);
	var url = url;
	
	divInfo.style.visibility = "visible";
	divInfo.style.position = "relative";
	divInfo.innerHTML = "Buscando endereço relacionado ao cep digitado ..."; 
	meuform.endereco.value = 'Buscando Dados ...'
	meuform.complemento.value = 'Buscando Dados ...'
	meuform.cidade.value = 'Buscando Dados ...'
	
	
	var XMLHttp = criaXMLHttp();
	
	
	if((metodo == "GET") || (metodo == "get")) {
		XMLHttp.open("GET", url, true);
	} else { 
		XMLHttp.open("POST", url, true);
		XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		XMLHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		XMLHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		XMLHttp.setRequestHeader("Pragma", "no-cache");
	} 
	
	XMLHttp.onreadystatechange = function () {
	if (XMLHttp.readyState == 4)
		if (XMLHttp.status == 200){
			var result = unescape(escape(XMLHttp.responseText)); //Armazena a resposta XML.
			
			divInfo.innerHTML = '';
			
			var pesquisa = result.split('|'); //Captura todas as respostas nas Tags <retorno>
			var endereco = '';
			var complemento = '';
			var bairro = '';
			var cidade = '';
			var V_bairro = '';
			var V_cidade = '';
				
			meuform.endereco.value = '';
			meuform.complemento.value = '';
			meuform.cidade.value = '';

			if (pesquisa[0] != ''){
								endereco = trim(pesquisa[0],' '); //Endereco
							if (pesquisa[1] != '')
									complemento = trim(pesquisa[1],' '); //Complemento
							if (pesquisa[2] != '')
									V_bairro = trim(pesquisa[2],' '); //Bairro
							if (pesquisa[3] != '')					
									bairro = trim(pesquisa[3],' '); //Bairro
							if (pesquisa[4] != '')
									V_cidade = trim(pesquisa[4],' ');//cidade
							if (pesquisa[5] != '')
									cidade = trim(pesquisa[5],' '); //cidade
							
							
							
							
							meuform.endereco.value = endereco
							meuform.complemento.value = complemento
							meuform.cidade.value = cidade
							
							minhasopcoes = meuform.bairro.options;
							meuform.bairro.selectedIndex = 0;
						
							
							
							for (var i = 0; i<minhasopcoes.length;i++){
								if (meuform.bairro.options[i].value == V_bairro){
									meuform.bairro.selectedIndex = i;
								}
							}
					
							meuform.bairro.focus();
							
							
			}else{
					meuform.cep.focus();
					divInfo.style.visibility = "visible";
					divInfo.style.position = "relative";
					divInfo.innerHTML = "CEP não encontrado."; 
			}
			
			
		} else {
			divInfo.innerHTML = "Um erro ocorreu" + XMLHttp.statusText;
		}
	};

XMLHttp.send(null);
}




function webServiceCep(id, metodo, url, meuform, retorno) {
	

	meuform = eval('document.'+ meuform);
	var divInfo = document.getElementById(id);
	var divInfo2 = document.getElementById(retorno);
	divInfo.style.visibility = "visible";
	divInfo.style.position = "relative";
	divInfo.innerHTML = "Processando..."; 
	
	meuform.endereco.value = 'Buscando Dados ...';
	meuform.complemento.value = 'Buscando Dados ...';
	meuform.cidade.value = 'Buscando Dados ...';
	meuform.bairro.value = 'Buscando Dados ...';
	meuform.num.value = 'Buscando Dados ...';
	
	url = url; //Localização do documento de pesquisa.
    
	//divInfo.innerHTML = '<p><img src="images/loading.gif" \> Carregando ...</p>';
	
	var XMLHttp = criaXMLHttp();
	
	
	if((metodo == "GET") || (metodo == "get")) {
		XMLHttp.open("GET", url, true);
	} else { 
		XMLHttp.open("POST", url, true);
 		XMLHttp.setRequestHeader('encoding','ISO-8859-1'); //Define o conjunto de caracteres usado no documento.
    	XMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded' ); //Prepara o servidor para receber dados POST.
		XMLHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		XMLHttp.setRequestHeader('Content-length', strData.length ); //Comunica ou servidor o tamanho dos dados a serem enviados.
		XMLHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		XMLHttp.setRequestHeader("Pragma", "no-cache");
	} 
	
	XMLHttp.onreadystatechange = function () {
	if (XMLHttp.readyState == 4)
		if (XMLHttp.status == 200){
			var resposta = unescape((XMLHttp.responseText)); //Armazena a resposta XML.
			
			divInfo.innerHTML = '';
			divInfo.style.visibility = "hidden";
			divInfo.style.position = "absolute";
			
			var endereco = '';
			var bairro = '';
			var cidade = '';
			var estado = '';
			var num = '';
				

			meuform.endereco.value = '';
			meuform.complemento.value = '';
			meuform.cidade.value = '';
			meuform.num.value = '';
			//meuform.estado.selectedIndex = 0;
			meuform.bairro.selectedIndex = 0;
		
		    	
			var pesquisa = resposta.split('|'); //Captura todas as respostas nas Tags <retorno>
				
			resultado =  trim(pesquisa[0],' ');
			tipo = trim(pesquisa[1],' ');
			endereco = trim(pesquisa[2],' ');
			bairro = trim(pesquisa[3],' ');
			cidade = trim(pesquisa[4],' ');
			estado = trim(pesquisa[5],' ');
			
						
			

			
			
			
			
			if (pesquisa.length > 0){
				if (endereco == ''){			
					meuform.cep.focus();
					divInfo.style.visibility = "visible";
					divInfo.style.position = "relative";
					divInfo.innerHTML = "CEP não encontrado.";
					
					meuform.endereco.value = '';
					//meuform.bairro.value = '';
					meuform.cidade.value = '';
					meuform.estado.selectedIndex = 0;
					
				}else{
						
				
						minhasopcoes = meuform.bairro.options;
						meuform.bairro.selectedIndex = 0;
						
							
 
						for (var i = 0; i<minhasopcoes.length;i++){
							
							
							if ((meuform.bairro.options[i].text).toLowerCase == (bairro).toLowerCase){
								meuform.bairro.selectedIndex = i;
							}
						}
				
					
						meuform.cidade.value = cidade;
						meuform.endereco.value = tipo+' '+endereco;
						meuform.bairro.value  = bairro;	
						meuform.num.focus(); //Passa o focu para o campo de pesquisa.
								
				}		
			}
			
		} else {
			divInfo.innerHTML = "Um erro ocorreu" + XMLHttp.statusText;
		}
	};

	XMLHttp.send(null);
}



		function avisa(){
        window.alert('AVISO: Para efetuar pedido utilize a área de PEDIDO ONLINE. Observação: Alguns produtos do cardápio não estão disponíveis para entregas. ');
		return false;
		}