// Lib jcvdesign
function Ajax(valor, urlr, qid, msg)
{
url=urlr+valor;
jcvF(url, qid, msg);
}
function jcvF(url, QID, msg)
{
	this.QID = QID;
	this.msg = msg;
	ajax(url);
}
function extraiScript(texto){
        var ini = 0;
        while (ini!=-1){
                ini = texto.indexOf('<script', ini);
                if (ini >=0){
                        ini = texto.indexOf('>', ini) + 1;
                        var fim = texto.indexOf('</script>', ini);
                        codigo = texto.substring(ini,fim);
                        //eval(codigo);
						novo = document.createElement("script")
                        novo.text = codigo;
                        document.body.appendChild(novo);

                }
        }
}
function ajax(url){
	  req = null;
      if (window.XMLHttpRequest) {
      req = new XMLHttpRequest();
      req.onreadystatechange = processReqChange;
      req.open("GET",url,true);
      req.send(null);
 	  }
	  else if (window.ActiveXObject) {
      req = new ActiveXObject("Microsoft.XMLHTTP");
     	 if (req) {
      	req.onreadystatechange = processReqChange;
		req.setRequestHeader("'Content-Type', 'application/x-www-form-urlencoded'");
  		req.open("GET",url,true);
		req.send();
      	}

      }
}
function processReqChange(){
	document.getElementById(QID).innerHTML = "<div id='loadingAjax'>"+msg+"</div>";
      if (req.readyState == 4) {
		  if (req.status ==200) {
			 document.getElementById(QID).innerHTML = req.responseText;
			 extraiScript(req.responseText);

     		 }
		  else {
		      document.getElementById(QID).innerHTML = "<div id='errorAjax'>ERRO: Falha ao executar a requisi&ccedil;&atilde;o.</div>";
      		}

      }

} 
function searchClick(){
	if(document.getElementById("search").value == 'Procurando por...'){
		document.getElementById("search").value = '';
	}
}
function searchBlur(){
	if(document.getElementById("search").value == ''){
		document.getElementById("search").value = 'Procurando por...';
	}
}

function validasearch(){
	$search = _$('search').value;
	if($search == ""){
		return false;
		// fail form
	}
	else if($search == "Procurando por..."){
		return false;
		// fail form
	}
	else{
		return true;
	}
}

function verifForm(){

$alert = _$("alerts-form");
$nome = _$("cont_nome");
$email = _$("cont_email");
$estado = _$("cont_estado");
$cidade =  _$("cont_cidade");
$assunto = _$("cont_assunto");
$mensagem = _$("cont_msg");
$type = "";

if($nome.value == ''){
$msg= "Favor informar seu nome";
$nome.focus();
}
else if($email.value == ''){
$msg= "Favor informar seu e-mail";
$email.focus();
}
else if($cidade.value == ''){
$msg= "Favor informar sua cidade";
$cidade.focus();
}
else if($estado.value == ''){
$msg= "Favor informar seu estado";
$estado.focus();
}

else if($assunto.value == ''){
$msg= "Favor informar um assunto";
$assunto.focus();
}
else if($mensagem.value == ''){
$msg= "Favor digitar uma mensagem";
$mensagem.focus();
}
else{
$msg= "Enviando sua Mensagem... Aguarde!";
$type = "ok";
}
	if($type == "ok"){
	$alert.innerHTML= "<div class='oksend'>"+$msg+"</div>";
	document.FormContatos.submit();
	return true;
	}
	else{
	$alert.innerHTML= "<div class='errors'>"+$msg+"</div>";
	return false;
	}
}



function aprove($url, $msg){
	if(confirm($msg)){
		window.location = $url;
	}
	else{
		return false;
		}
}

// tabbs

$(document).ready(function(){
    
  $("a.tab").click(function () {  
        
     $(".active").removeClass("active");  
        
    $(this).addClass("active");  
	
	      
    $(".tconts").hide();  
     
    var content_show = $(this).attr("title");  
    $("#"+content_show).show();  
      
 });  
 
 });  

// tabbs end






$(document).ready(function(){
						   $(".image-view a").hover(function(){
						   $(".bg", this).fadeTo("slow", 0.4);
						   $(".zoom", this).fadeTo("slow", 1);
						   },function(){
						   $("div", this).fadeTo("slow", 0);
						   });
						   });


$(document).ready(function(){
						   $(".list-class .item").hover(function(){
						   $(".infos", this).slideDown();
						   },function(){
						   $(".infos", this).slideUp(); 
						   });
						   });
$(document).ready(function(){
				  $("#imageload").fadeTo("slow", 1);
						   });

$(document).ready(function(){
						   $("#catlist").click(function(){
						   $(this).slideUp();}); 
						   
						   $(".categories").hover(function(){
						   $("#catlist", this).slideDown();
						   },function(){
						   $("#catlist", this).slideUp(); 
						   });
						   });



function Numbers(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}



function addcampo(){
	$count = $("#arquivos > div").size();
	if($count <= 9){
		  var ni = document.getElementById('arquivos');
		  var numi = document.getElementById('theValue');
		  var num = (document.getElementById('theValue').value -1)+ 2;
		  numi.value = num;
		  var newdiv = document.createElement('div');
		  var divIdName = 'file_'+num+'';
		  newdiv.setAttribute('id',divIdName);
		  newdiv.innerHTML = '<label><input name="file[]" type="file" id="file_0'+num+'" /> </label> <a href=\"javascript:void(0);\" onclick=\"removecampo(\''+divIdName+'\');\" class=\'remove\'></a>';
		  ni.appendChild(newdiv);
	}
	else{
		alert("Limite de 10 Imagens por anúncio!");
	}
  
}


function removecampo(divNum){
  var d = document.getElementById('arquivos');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}


function selectUF($uf){
		Ajax($uf ,'lista-representantes.php?uf=', 'lista-representantes', '');		
}

Cufon.replace('.cufon', { hover: true} );
Cufon.replace('.cufon strong', { hover: true, fontFamily: "Klavika Rg"} );
Cufon.replace('.cufon b', { hover: true, fontFamily: "Klavika Rg"} );
Cufon.replace('.topmenu .menubt a', { hover: true} );
Cufon.replace('.topmenu .produtos .label', { hover: true} );
Cufon.replace('.menu-cats', { hover: true} );
Cufon.replace('.menu-foot', { hover: true} );

Cufon.replace('.buttons a', { hover: true} );


Cufon.replace('h1', { hover: true} );
Cufon.replace('h2', { hover: true} );
Cufon.replace('h3', { hover: true} );
Cufon.replace('h4', { hover: true} );
Cufon.replace('h5', { hover: true} );


Cufon.replace('#filiais li a', { hover: true} );


Cufon.replace('#carousel-tabs a', { hover: true} );



Cufon.replace('.labels-sub', { fontFamily: "Klavika Rg" });

Cufon.replace('.label-show', { hover: true, fontFamily: "Klavika Rg"} );


$(document).ready(function(){
						$('.materiais a img[title]').tooltip({ effect: 'slide', position: "top left"});							 							 
								 
								 });
$(document).ready(function(){
						   $("#view-img a").hover(function(){
						   	   $("div", this).fadeTo("slow", 0.8);
						   },function(){
						  		 $("div", this).fadeTo("slow", 0);
						  	 });
						   });


$(document).ready(function(){
						   $("#filial .thumbs a").click(function(){
																 
														Ajax($(this).attr("href") , "../viewimgfil.php?file=", "view-img", "");
														return false;
																
								});
						   
						   });




jQuery(function($) {
						   $(".prod-view a").hover(function(){
						   $(".zoom", this).fadeTo("slow", 0.7);
						   },function(){
						   $(".zoom", this).fadeTo("slow", 0);
						   });
						   });




