//#############################################################
//####               envia newsletter ajax                 ####
//#############################################################
function valida_newsletter_formulario()
{

// see http://www.thesitewizard.com/archive/validation.shtml
// for an explanation of this script and how to use it on your
// own website

// ** START **

	

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	var var_erro = 'E-mail Inválido.';
	
	if (str.indexOf(at)==-1){
	alert(var_erro)
	return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	alert(var_erro)
	return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	alert(var_erro)
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
	alert(var_erro)
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	alert(var_erro)
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
	alert(var_erro)
		return false
	}
	
	if (str.indexOf(" ")!=-1){
	alert(var_erro)
		return false
	}

 	return true					
}


var emailID=document.forms[0].no_email;

if ((document.forms[0].no_contato.value==null)||(document.forms[0].no_contato.value=="")){
	alert("Por favor digite seu nome.")
	document.forms[0].no_contato.focus()
	return false
}			

if ((emailID.value==null)||(emailID.value=="")){
	alert("Por favor digite seu email.")
	emailID.focus()
	return false
}
if (echeck(emailID.value)==false){
	emailID.value=""
	emailID.focus()
	return false
}

newsletter_enviar();

    function newsletter_enviar() {

        var var_url = '';
        var_url = 'include_newsletter_src.asp?acao=newsletter';
        var_url = var_url + '&no_contato=' + document.forms[0].no_contato.value;
        var_url = var_url + '&no_email=' + document.forms[0].no_email.value;

        var ajax = new Ajax.Updater(
	        'col_right',        // DIV id (XXX: doesnt work?)
	        var_url,        // URL
	        {                // options
	        method:'post',
	        onComplete: contato_showResponse
	        });     
    	
    }

    function contato_showResponse(req){
        $('col_right').innerHTML = req.responseText;
    }		  

	
return false;
}

//#############################################################
//####               envia newsletter ajax                 ####
//#############################################################
function valida_newsletter_formularioH()
{

// see http://www.thesitewizard.com/archive/validation.shtml
// for an explanation of this script and how to use it on your
// own website

// ** START **

	

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	var var_erro = 'E-mail Inválido.';
	
	if (str.indexOf(at)==-1){
	alert(var_erro)
	return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	alert(var_erro)
	return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	alert(var_erro)
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
	alert(var_erro)
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	alert(var_erro)
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
	alert(var_erro)
		return false
	}
	
	if (str.indexOf(" ")!=-1){
	alert(var_erro)
		return false
	}

 	return true					
}


var emailID=document.forms[0].no_email;

if ((document.forms[0].no_contato.value==null)||(document.forms[0].no_contato.value=="")){
	alert("Por favor digite seu nome.")
	document.forms[0].no_contato.focus()
	return false
}			

if ((emailID.value==null)||(emailID.value=="")){
	alert("Por favor digite seu email.")
	emailID.focus()
	return false
}
if (echeck(emailID.value)==false){
	emailID.value=""
	emailID.focus()
	return false
}

newsletter_enviar();

function newsletter_enviar() {

var var_url = '';

var_url = 'include_newsletter_src.asp?acao=newsletter';
var_url = var_url + '&no_contato=' + document.forms[0].no_contato.value;
var_url = var_url + '&no_email=' + document.forms[0].no_email.value;

var ajax = new Ajax.Updater(
	'box_novidade_home',        // DIV id (XXX: doesnt work?)
	var_url,        // URL
	{                // options
	method:'post',
		onComplete: newsletter_showResponse
		});		
}

function newsletter_showResponse(req)
{

$('col_right').innerHTML = req.responseText;

}		  

	
return true ;
}

//#############################################################
//####              valida form de contato                 ####
//#############################################################
function valida_formulario_contato()
{

// see http://www.thesitewizard.com/archive/validation.shtml
// for an explanation of this script and how to use it on your
// own website

    // ** START **

    	

    function echeck(str) {

	    var at="@"
	    var dot="."
	    var lat=str.indexOf(at)
	    var lstr=str.length
	    var ldot=str.indexOf(dot)
    	
	    var var_erro = 'E-mail Inválido.';
    	
	    if (str.indexOf(at)==-1){
	    alert(var_erro)
	    return false
	    }

	    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	    alert(var_erro)
	    return false
	    }

	    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert(var_erro)
		    return false
	    }

	    if (str.indexOf(at,(lat+1))!=-1){
	    alert(var_erro)
		    return false
	    }

	    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert(var_erro)
		    return false
	    }

	    if (str.indexOf(dot,(lat+2))==-1){
	    alert(var_erro)
		    return false
	    }
    	
	    if (str.indexOf(" ")!=-1){
	    alert(var_erro)
		    return false
	    }

 	    return true					
    }

    var emailID=document.FormContato.no_email;

    if ((document.FormContato.cd_departamento.value=="")){
	    alert("Por favor selecione o departamento.");
	    document.FormContato.cd_departamento.focus();
	    return false;
    }

    if ((document.FormContato.no_contato.value==null)||(document.FormContato.no_contato.value=="")){
	    alert("Por favor digite seu nome.");
	    document.FormContato.no_contato.focus();
	    return false;
    }			

    if ((emailID.value==null)||(emailID.value=="")){
	    alert("Por favor digite seu email.");
	    emailID.focus();
	    return false;
    }
    if (echeck(emailID.value)==false){
	    emailID.value="";
	    emailID.focus();
	    return false;
    }

    if ((document.FormContato.ds_mensagem.value==null)||(document.FormContato.ds_mensagem.value=="")||(document.FormContato.ds_mensagem.value=="Mensagem")){
	    alert("Por favor digite sua mensagem.");
	    document.FormContato.ds_mensagem.focus();
	    document.FormContato.ds_mensagem.value='';
	    return false;
    }

    var var_url = '';
    var_url = 'include_contato_src.asp?acao=contato';
    var_url = var_url + '&cd_departamento=' + document.FormContato.cd_departamento.value;
    var_url = var_url + '&no_contato=' + document.FormContato.no_contato.value;
    var_url = var_url + '&no_email=' + document.FormContato.no_email.value;
    var_url = var_url + '&ds_telefone=' + document.FormContato.ds_telefone.value;
    var_url = var_url + '&ds_mensagem=' + document.FormContato.ds_mensagem.value;

    var ajax = new Ajax.Updater(
	    'col_right',  // DIV id (XXX: doesnt work?)
	    var_url,                // URL
	    {                       // options
	    method:'post',
	    onComplete: contato_showResponse
	    });    

    function contato_showResponse(req){
	    $('col_right').innerHTML = req.responseText;
    }

    return false;
}


//#############################################################
//####          valida form de enviar para amigo           ####
//#############################################################
function valida_formulario_amigo(){

// see http://www.thesitewizard.com/archive/validation.shtml
// for an explanation of this script and how to use it on your
// own website

    // ** START **
    function echeck(str) {

	    var at="@"
	    var dot="."
	    var lat=str.indexOf(at)
	    var lstr=str.length
	    var ldot=str.indexOf(dot)
    	
	    var var_erro = 'E-mail Inválido.';
    	
	    if (str.indexOf(at)==-1){
	        alert(var_erro);
	        return false;
	    }

	    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	        alert(var_erro);
	        return false;
	    }

	    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	        alert(var_erro);
		    return false;
	    }

	    if (str.indexOf(at,(lat+1))!=-1){
	        alert(var_erro);
		    return false;
	    }

	    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	        alert(var_erro);
		    return false;
	    }

	    if (str.indexOf(dot,(lat+2))==-1){
	        alert(var_erro);
		    return false;
	    }
    	
	    if (str.indexOf(" ")!=-1){
	        alert(var_erro);
		    return false;
	    }

 	    return true;
    }
    
    if ((document.FormAmigo.no_contato.value==null)||(document.FormAmigo.no_contato.value=="")){
	    alert("Por favor digite seu nome.");
	    document.FormAmigo.no_contato.focus();
	    return false;
    }
    if ((document.FormAmigo.ds_email.value==null)||(document.FormAmigo.ds_email.value=="")){
	    alert("Por favor digite seu email.");
	    document.FormAmigo.ds_email.focus();
	    return false;
    }
    if (echeck(document.FormAmigo.ds_email.value)==false){
	    document.FormAmigo.ds_email.value="";
	    document.FormAmigo.ds_email.focus();
	    return false;
    }
    if ((document.FormAmigo.ds_email_amigo1.value==null)||(document.FormAmigo.ds_email_amigo1.value=="")){
	    alert("Por favor digite ao menos o e-mail de um amigo.");
	    document.FormAmigo.ds_email_amigo1.focus();
	    return false;
    }
    if (echeck(document.FormAmigo.ds_email_amigo1.value)==false){
	    document.FormAmigo.ds_email_amigo1.value="";
	    document.FormAmigo.ds_email_amigo1.focus();
	    return false;
    }

    var_url =			'include_amigo_src.asp?acao=contato';
    var_url = var_url + '&no_contato=' + document.FormAmigo.no_contato.value;
    var_url = var_url + '&ds_email=' + document.FormAmigo.ds_email.value;
    var_url = var_url + '&ds_url=' + document.FormAmigo.ds_url.value;
    var_url = var_url + '&ds_tipo=' + document.FormAmigo.ds_tipo.value;
    var_url = var_url + '&ds_email_amigo1=' + document.FormAmigo.ds_email_amigo1.value;
    var_url = var_url + '&ds_email_amigo2=' + document.FormAmigo.ds_email_amigo2.value;
    var_url = var_url + '&ds_email_amigo3=' + document.FormAmigo.ds_email_amigo3.value;
    var_url = var_url + '&ds_email_amigo4=' + document.FormAmigo.ds_email_amigo4.value;

    var ajax = new Ajax.Updater(
	    'indicacao',  // DIV id (XXX: doesnt work?)
	    var_url,                // URL
	    {                       // options
	    method:'post',
	    onComplete: indicacao_showResponse
	    });
	    
    function indicacao_showResponse(req){
	    $('indicacao').innerHTML = req.responseText;
    }


    return false;
}

//#############################################################
//####             abri popup centralizado                 ####
//#############################################################
function openCenteredWindow(url, name, width, height, scrollbars) {

   var left			= Math.floor( (screen.width - width) / 2);
   var top			= Math.floor( (screen.height - height) / 2);
   var winParms	= "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width + ",scrollbars=" + scrollbars;   
   var win = window.open(url, name, winParms);
}

function valida_areaMostrar(codigo_produto,codigo_familia,codigo_area,codigo_idioma){
    var_url =			'vst_area.asp?acao=mostra_produto';
    if (codigo_produto != ""){
        var_url = var_url + '&cd_produto=' + codigo_produto;
    }
    if (codigo_idioma != ""){
        var_url = var_url + '&cd_idioma=' + codigo_idioma;
    }
    if (codigo_familia != ""){
        var_url = var_url + '&cd_familia=' + codigo_familia;
    }
    if (codigo_area != ""){
        var_url = var_url + '&cd_area=' + codigo_area;
    }   
    
    var ajax = new Ajax.Updater(
	    'mostra_produto',  // DIV id (XXX: doesnt work?)
	    var_url,                // URL
	    {                       // options
	        method:'post',
		    onComplete: newsletter_showResponse
		});
    
    function newsletter_showResponse(req){
	    $('mostra_produto').innerHTML = req.responseText;
    }
    return true ;
}

function valida_produtoMostrar(codigo_produto,codigo_familia,codigo_idioma){
    var_url =			'vst_produto.asp?acao=mostra_produto';
    if (codigo_produto != ""){
        var_url = var_url + '&cd_produto=' + codigo_produto;
    }
    if (codigo_idioma != ""){
        var_url = var_url + '&cd_idioma=' + codigo_idioma;
    }
    if (codigo_familia != ""){
        var_url = var_url + '&cd_familia=' + codigo_familia;
    }
    
    var ajax = new Ajax.Updater(
	    'mostra_produto',  // DIV id (XXX: doesnt work?)
	    var_url,                // URL
	    {                       // options
	        method:'post',
		    onComplete: newsletter_showResponse
		});
    
    function newsletter_showResponse(req){
	    $('mostra_produto').innerHTML = req.responseText;
    }
    return true ;
}
