function showSubProdutos(){
	document.getElementById("subProdutos").style.display = "";
	document.getElementById("linkProduto").className = "textoHover";
}

function hideSubProdutos(){
	document.getElementById("linkProduto").className = "textoNormal";
	document.getElementById("subProdutos").style.display = "none";
}

var showAjax = true;
$().ajaxSend(function(r,s){
	if (  showAjax ){
		$("#imgLoader").show();
		$("#divLoader").show();
	}
});

$().ajaxStop(function(r,s){
	if (  showAjax ){
		$("#imgLoader").hide();
		$("#divLoader").hide();
	}
});

$(document).ready(function(){

	$('#menu ul li:first').css('border-left','none');

});

function validaBusca(){
	var msg = "";	
    if(document.getElementById("busca").value == "" || document.getElementById("busca").value == "Palavra-chave")
		msg = "Campo Busca nÃ£o foi preenchido";
    if(msg != ""){
		msg = "<div id=\"topoValida\">Os seguintes campos encontam-se vazios e devem ser preenchidos:<br /><br /></div>" + msg;
        jQuery.facebox(msg);
        return false;
    }

}

function openBombasCentrifugas(){
	//openPageFacebox("html/bombas_centrifugas.php","");
	openPageFacebox("galeria.htm","");
}

function openAplicacoes(){
	
}

function openPageFacebox(page,params){
	jQuery.facebox(function() {
	  jQuery.get(page+"?"+params, function(data) {
	    jQuery.facebox( data )
	  })
	}) 
}

function openPage(page,pageType){
	jQuery.get(page, function(data) {
		document.getElementById("conteudo").innerHTML = data;
		 extraiScript(data);
	})
	if ( pageType == "empresa" ){
		document.getElementById("linkEmpresa").onmouseover = function(){}
		document.getElementById("linkEmpresa").onmouseout  = function(){}
		
		document.getElementById("linkProduto").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkProduto").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkContato").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkContato").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkInicio").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkInicio").onmouseout  = function(){ this.className='textoNormal'}
	
		document.getElementById("linkEmpresa").className = "textoHover";
		document.getElementById("linkProduto").className = "textoNormal";
		document.getElementById("linkContato").className = "textoNormal";
		document.getElementById("linkInicio").className = "textoNormal";
	}else if ( pageType == "produto" ){
		document.getElementById("linkEmpresa").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkEmpresa").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkProduto").onmouseover = function(){}
		document.getElementById("linkProduto").onmouseout  = function(){}
		
		document.getElementById("linkContato").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkContato").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkInicio").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkInicio").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkEmpresa").className = "textoNormal";
		document.getElementById("linkProduto").className = "textoHover";
		document.getElementById("linkContato").className = "textoNormal";
		document.getElementById("linkInicio").className = "textoNormal";
	}else if ( pageType == "contato" ){
		document.getElementById("linkEmpresa").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkEmpresa").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkProduto").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkProduto").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkContato").onmouseover = function(){}
		document.getElementById("linkContato").onmouseout  = function(){}
		
		document.getElementById("linkInicio").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkInicio").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkEmpresa").className = "textoNormal";
		document.getElementById("linkProduto").className = "textoNormal";
		document.getElementById("linkContato").className = "textoHover";
		document.getElementById("linkInicio").className = "textoNormal";
	}else if ( pageType == "home" ){
		document.getElementById("linkEmpresa").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkEmpresa").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkProduto").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkProduto").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkContato").onmouseover = function(){ this.className='textoHover' }
		document.getElementById("linkContato").onmouseout  = function(){ this.className='textoNormal'}
		
		document.getElementById("linkInicio").onmouseover = function(){ }
		document.getElementById("linkInicio").onmouseout  = function(){}
		
		document.getElementById("linkEmpresa").className = "textoNormal";
		document.getElementById("linkProduto").className = "textoNormal";
		document.getElementById("linkContato").className = "textoNormal";
		document.getElementById("linkInicio").className = "textoHover";
	}
}



function extraiScript(texto){
    //Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
    //http://forum.imasters.com.br/index.php?showtopic=165277&
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    var codigo = "";
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo += texto.substring(ini,fim);


        }
    }
    // executa o script
    //eval(codigo);
    /**********************
     * Alterado por Micox - micoxjcg@yahoo.com.br
     * Alterei pois com o eval não executava funções.
     ***********************/
    novo = document.createElement("script")
    novo.text = codigo;
    document.body.appendChild(novo);
}

function openBombas(){
	openPage("html/produtos.php","");
}
function openImg(imgLink){
	
	//$('#loadingHide').show();
	$('#loaderImg').empty();
	$('#loaderImg').addClass("loadingImg");
	  var img = new Image();
	  
	  $(img)
	    // once the image has loaded, execute this code
	    .load(function () {
	      // set the image hidden by default    
	      $(this).hide();
	      // with the holding div #loader, apply:
	      $('#loaderImg')
	        // remove the loading class (so no background spinner), 
	        .removeClass('loadingImg')
	        // then insert our image
	        .append(this);
	    
	      // fade our image in to create a nice effect
	      //$('#loadingHide').fadeOut();
	      $(this).fadeIn();
	    })
	    
	    // if there was an error loading the image, react accordingly
	    .error(function () {
	      
	    })
	    .attr('src', 'img/produtos/'+imgLink+'.jpg');	    
}
function loadImg(imgLink,div,className){
	$('#'+div).empty();
	$('#'+div).addClass(className);
	  var img = new Image();
	  
	  $(img)
	    // once the image has loaded, execute this code
	    .load(function () {
	      // set the image hidden by default    
	      $(this).hide();
	    
	      // with the holding div #loader, apply:
	      $('#'+div)
	        // remove the loading class (so no background spinner), 
	        .removeClass(className)
	        // then insert our image
	        .append(this);
	    
	      // fade our image in to create a nice effect
	      //$('#loadingHide').fadeOut();
	      $(this).fadeIn();
	    })
	    
	    // if there was an error loading the image, react accordingly
	    .error(function () {
	      alert('erro!');
	    })
	    .attr('src', imgLink);
}
function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
                    return true;
        }
    }else{
        return false;
    }
}
function validaSend(){
	if ( document.getElementById("nomeEmail") == null ||
		 document.getElementById("emailEmail") == null || 
		 document.getElementById("assuntoEmail") == null ||
		 document.getElementById("messageEmail") == null ){
		 	return false;
		 }
	var nomeEmail    = document.getElementById("nomeEmail").value;
	var emailEmail   = document.getElementById("emailEmail").value;
	var assuntoEmail = document.getElementById("assuntoEmail").value;
	var messageEmail = document.getElementById("messageEmail").value;
	var list = "";
	if ( nomeEmail.length == 0 ){
		list +="Nome<br>";
	}
	if ( emailEmail.length == 0 ){
		list +="Email<br>";
	}
	if ( assuntoEmail.length == 0 ){
		list +="Assunto<br>";
	}
	if ( messageEmail.length == 0 ){
		list +="Mensagem<br>";
	}
	if ( list.length != 0 ){
		jQuery.facebox("<div style='width:300px;'>Os seguintes campos estão em branco:<br>"+list+"</div>");
		return false;
	}
	if (!checkMail(emailEmail)){
		jQuery.facebox("<div style='width:300px;'>Email Invalido!<br>'</div>");
		return false;
	}
	return true;
}
function sendMail(){
	if ( validaSend() ){
		var nomeEmail    = document.getElementById("nomeEmail").value;
		var emailEmail   = document.getElementById("emailEmail").value;
		var assuntoEmail = document.getElementById("assuntoEmail").value;
		var messageEmail = document.getElementById("messageEmail").value;
		params  = "nomeEmail="+nomeEmail;
		params += "&emailEmail="+emailEmail;
		params += "&assuntoEmail="+assuntoEmail;
		params += "&messageEmail="+messageEmail;
		jQuery.get("html/send.php?"+params,function(data) {
			 extraiScript(data);
		});
	}
}

