
         function ValidaBuscaMenu (online,dominio,vendor) {

            var pchave_field = document.formbusca_menu.pchave;
            var pchave = pchave_field.value;

            var alvo   = get_radio_value(document.formbusca_menu.alvo);
            
            var regdash = new RegExp(/[\-"]/);
                       
            if ( pchave.length < 3 ) {
   
                  window.alert("Por favor, utilize um termo com no mínimo 3 caracteres.");
         
                  
         
            } else { // ok, lenght passes

               if ( online == 0 || regdash.test(pchave) || vendor != "" ) { // offline, or with dashes pchave's, or negative booleans. Or bvendor search.

                  return true; // the old way, form submit
               
               }
            
               else  { // new way, seo url composed by javascript. 

                  var pchave = SEO_string(pchave);
                  pchave = replaceAll(pchave, '/', '%20');
 
                  var qdir = "q";
                     if      ( alvo == "autor" ) { qdir = "qau"; }
                     else if ( alvo == "titulo" ) { qdir = "qtit"; }
                     else if ( alvo == "editora" ) { qdir = "qed"; }
                     else if ( alvo == "descr" ) { qdir = "qdes"; }
                     else if ( alvo == "todos" ) { qdir = "qt"; }
                     
                  var url = dominio + "/" + qdir + "/" + pchave;
                  
                  window.location = url;
               
               }
               
               
              
            }
   
            return false; // always; javascript submit now
  
         }

	 function replaceAll(txt, replace, with_this) {
             return txt.replace(new RegExp(replace, 'g'),with_this);
         }
         
         
         function SEO_string(strAccents){ 
		    strAccents = strAccents.split(''); 
		    strAccentsOut = new Array(); 
		    strAccentsLen = strAccents.length; 
		    var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñ ?&'; //space, ? and & too!
		    var accentsOut = ['A','A','A','A','A','A','a','a','a','a','a','a','O','O','O','O','O','O','O','o','o','o','o','o','o','E','E','E','E','e','e','e','e','e','C','c','D','I','I','I','I','i','i','i','i','U','U','U','U','u','u','u','u','N','n','-','','']; 
		    for (var y = 0; y < strAccentsLen; y++) { 
		        if (accents.indexOf(strAccents[y]) != -1) { 
		            strAccentsOut[y] = accentsOut[accents.indexOf(strAccents[y])]; 
		        } 
		        else 
		            strAccentsOut[y] = strAccents[y]; 
		    } 
		    strAccentsOut = strAccentsOut.join(''); 
		    return strAccentsOut; 
		} 
		
		function get_radio_value(field) {
		    var valor;
			for (var i=0; i < field.length; i++) {
			   if (field[i].checked) {
			      valor = field[i].value;
			   }
			}
			return valor;
	    }


         
         var http = getHTTPObject();
         
         
         function GoLoginAjax ( thisform, dominio ) {
         
            var username = thisform.username.value;
            var senha = thisform.senha.value;
            var destino = thisform.destino.value;

            if ( username == "" ) { 
            
               window.alert('Por favor digite seu email.');  
               thisform.username.focus();

            }
            
            else if ( senha == "" ) { 
            
               window.alert('Por favor digite sua senha.');  
               thisform.senha.focus();
               
            }
            
           
            else { 
            
               var params = 'username=' + username + '&senha=' + senha + '&destino=' + destino;
               var script = dominio + "/cgi-bin/login.cgi";

               http.open("POST", script, true);
               http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
               http.onreadystatechange = CookieLoginAjax;
               http.send(params);
            
            
            }
  
            return false; // Nada de mudar de página! 
  
         }
         
         function CookieLoginAjax() {
         
            if (http.readyState == 4) {
                  
               var resposta = http.responseText;
               var partes = new Array();
                   partes = resposta.split("***"); 
               
               var mensagem = partes[0]; 
               var script   = partes[1]; 
               
               alert(mensagem);
               
               // alert('*' + script + '*');
               
               eval(script);
               
               
            }
               
         }
        
                     
         function getHTTPObject() {
         
           var xmlhttp;
           
           // if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
           
             try {
               xmlhttp = new XMLHttpRequest(); 
             } catch (e) {
               try {
               xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
             } catch (e) {
             try {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
             } catch (e) {
                alert('XMLHttpRequest not supported'); 
             }
             }
             }
             
           // }
           return xmlhttp;
         }
         
         
                  
         function GoNewsletter (dominio) {
         
            var email = document.form_newsletter.email.value;
            
            if ( email != "digite seu email" && email != "" ) {
            
               var location = dominio + '/cgi-bin/frame-zero.cgi?action=newsletter&input=' + email;
               http.open("GET", location, true);
               http.onreadystatechange = handleHttpResponseNewsletter;
               http.send(null);
               
            }
            
            else { 
            
               window.alert('Digite o email que você deseja cadastrar \\npara receber a nesletter da Estante Virtual.'); 
               document.formemail.email.focus();
               
            }
            
            return false; // do not refresh! Stay right there!
         
         } // fim da função GoNewsletter
         
         function handleHttpResponseNewsletter() {
               
            if (http.readyState == 4) {
                  
               var mensagem = http.responseText;
                         
               window.alert(mensagem);
               
               document.form_newsletter.reset();
               
               self.focus();
                     
            }
            
         }
         
         
         
         function GoInvitation ( dominio) {
         
            var anfitriao = document.form_invitation.anfitriao.value;
            var email_destinatario = document.form_invitation.email_destinatario.value;
            var recado = document.form_invitation.recado.value;
            
            var framezero = parent.frames[0]; // para averiguar a presença da framezero
            
            if ( anfitriao != "digite o seu nome" && anfitriao != "" &&
                 email_destinatario != "digite o email do seu amigo" && email_destinatario != "" &&
                 recado != "escreva uma frase para ele" && recado != "" ) {
             
               var location = dominio + '/cgi-bin/frame-zero.cgi?action=invitation&input=' + anfitriao + '&input2=' + email_destinatario + '&input3=' + recado;
               
               http.open("GET", location, true);
               http.onreadystatechange = handleHttpResponseInvitation;
               http.send(null);
                 
            }
            
            else {
            
               window.alert('Todos os 3 campos são necessários para gerar o seu convite. \\nPor favor, verifique se todos foram preenchidos.'); 
            
            }
         
            return false; // do not refresh! Stay right there!
         
         } // fim da função GoInvitation
         
         function handleHttpResponseInvitation() {
               
            if (http.readyState == 4) {
                  
               var mensagem = http.responseText;
                         
               window.alert(mensagem);
               
               document.form_invitation.reset();
               
               self.focus();
                     
            }
            
         }
      
         
         // functions menu nando
                  
 		 function ClearFormSearch() {
		   document.formbusca_menu.pchave.value= "";
		 }
		
		 function ClearFormUser() {
		   document.formlogin_menu.username.value= "";
		 }
		
		 function toggleBg(objElement)
		 {
		   if (objElement.className=='caixadesenha')
		     objElement.className='caixadesenhaon';
		 //  else
		 //    objElement.className='caixadesenha';
		 }
		
		 function toggleColor(objElement)
		 {
		   if (objElement.className=='caixadebusca')
		     objElement.className='caixadebuscaon';
		   else
		     objElement.className='caixadebusca';
		 }

		 
		 // update do nlivros no cart
         
			var ajax = null;
			
			function AtualizaCesta ( dominio ) {
			
			    var stamp = new Date(); stamp = stamp.getTime();
			
			    var location = dominio + '/cgi-bin/frame-zero.cgi?action=atualiza_cesta&dontcache=' + stamp;
		    			    
			    if (window.ActiveXObject) ajax = new ActiveXObject('Microsoft.XMLHTTP');
			    else if (window.XMLHttpRequest) ajax = new XMLHttpRequest();
			    
			    if(ajax != null){
			      ajax.open('GET',location,true);
			      ajax.onreadystatechange = handleAtualizaCesta;
			      ajax.send(null);
			    }
			}
			
			function handleAtualizaCesta(){
			
			  var dominio_imagens = "http://imagens.estantevirtual.com.br";
			
			  if(ajax.readyState == 4 && ajax.status == 200){
			    var nlivros = ajax.responseText;
			    // window.alert(nlivros);
			    			  			  
			  var s = "s";
			     var nlivros_n = eval ( nlivros );
			     if ( nlivros_n == 1 ) { s = ""; }
			     	     
			  var div = document.getElementById('cesta');

			  			  
			  div.innerHTML = "<span class=cestan>" + nlivros + "</span> livro" + s + "<br>na sua cesta";
			  
			  var carticon = document.getElementById('carticon');
			  if ( nlivros_n == 0 ) { carticon.innerHTML = "<img src=\"" + dominio_imagens + "/imagens/2008/carticon.gif\" width=21 height=19 border=0>"; }
			  else { carticon.innerHTML = "<img src=\"" + dominio_imagens + "/imagens/2008/carticon_red.gif\" width=21 height=19 border=0>"; }
			  
			  }
			  
			}
			
			function GoEstante ( dominio ) {
			
			   var mycookie = getCookie('session'); 

			   if (mycookie != null && mycookie !="") {
			   
			      window.location = dominio + '/mod_perl/estante.cgi';
			      
			   } 
			   
			   else {
			   
			      alert('Você precisa fazer antes o seu login para acessar a sua estante virtual.');
			      
			   } 
			   
			}
			
			function TargetAcervo (vendedor,dominio) {
			
			   if ( vendedor == "0" ) { // busca em toda a EV
			   
			      document.formbusca_menu.action = dominio + "/mod_perl/busca.cgi";
			   
			   }
			   
			   else { // é um vendedor mesmo!
			   
			      document.formbusca_menu.action = dominio + "/mod_perl/busca.cgi";
			   
			   }
			
			
			}
			
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}
         
         

