jQuery.noConflict();/*quando são utilizadas várias bibliotecas JavaScript em um mesmo projeto corre-se o risco
                    de ter conflito e consequentemente um mal funcionamento dos scripts.Uma forma de resolver esse
                    problema quando a biblioteca jQuery é uma delas pode-se utilizar a função jQuery.noConflict().*/

/////////////////////////////////////////ZOOM DOS PRODUTOS//////////////////////////////////////////////////////////////////////
//ZOOM DOS PRODUTOS NA PÁGINA PRODUTOS
function troca(url_padrao,produto,imagem){
 jQuery("#principal").fadeOut(100);
 troca2(url_padrao,produto,imagem);
}
function troca2(url_padrao,produto,imagem){
 jQuery("#principal").attr("src",url_padrao+"/_images/produtos/"+produto+"/"+imagem);
 jQuery("#principal").fadeIn(100);
}


                                                        // AMPLIAR IMAGEM NA TABELA DE PRODUTOS
function zoom(codigo,categoria,subcategoria){
	jQuery("#back_zoom").css("display","block");
	jQuery("#zoom").css("display","block");
    jQuery("body").css("overflow","hidden");
    jQuery.ajax({
         type: "POST",
         url: "exibe_produto.php",
         data: "id="+codigo+"&cat="+categoria+"&sub="+subcategoria,
         success: function(msg){
         window.document.getElementById("zoom").innerHTML=msg;
         }
       });
}

function fechar_zoom()
{
 	jQuery("div.info_imagem img").attr("src","_images/branco.gif");
 	jQuery("#back_zoom").css("display","none");
	jQuery("#zoom").css("display","none");
    jQuery("body").css("overflow","auto");
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//NA PÁGINA CADASTRE-SE, MUDA OS FORMULARIOS(CLIENTE FINAL/REPRESENTANTE)
function muda(formulario){
  if(formulario=='cliente'){
  jQuery(".cliente").css("display","block");
  jQuery(".fin").html('<option selected="selected" value="cliente">Cliente Final</option> <option value="lojista">Lojista</option> <option value="representante">Representante</option>');
  jQuery(".representante").css("display","none");
  jQuery(".lojista").css("display","none");
 }else if(formulario=='representante'){
    jQuery(".representante").css("display","block");
    jQuery(".rep").html('<option value="cliente">Cliente Final</option> <option value="lojista">Lojista</option> <option selected="selected" value="representante">Representante</option>');
    jQuery(".cliente").css("display","none");
    jQuery(".lojista").css("display","none");
 }else if(formulario=='lojista'){
    jQuery(".lojista").css("display","block");
    jQuery(".loj").html('<option value="cliente">Cliente Final</option> <option selected="selected" value="lojista">Lojista</option> <option value="representante">Representante</option>');
    jQuery(".cliente").css("display","none");
    jQuery(".representante").css("display","none");
 }
}

function radio(valor){
    jQuery("#complemento_valor").attr("value",valor);
}

//////////////////////////////////INSERIR NOVAS LINHAS NA AREA DO REPRESENTANTE (PRODUTO)////////////////////////
var inIndex = 6;
function setIndex(pNumero){
	inIndex = pNumero;
}
function fcnAddLinha(pParent){
  var tblTarget
  var tblRow
  var tblCol1
  var tblCol2
  var tblCol3
  var tblCol4
  var tblCol5

  var qtd_linhas = parseInt(jQuery('#qtd_produtos').val()) + 1;
  jQuery('#qtd_produtos').attr('value',qtd_linhas);

  inIndex++;
  setIndex(inIndex);
  tblTarget = document.getElementById(pParent);
  tblRow = tblTarget.insertRow(-1); // o -1 é para inserir apos a ultima linha
  tblRow.className = "text"; // AQUI VOCE SETA A CLASS CSS DA 'LINHA'
  tblCol1 = tblRow.insertCell(0);
	tblCol1.className = "text";
  tblCol1.innerHTML = "<input disabled=\"disabled\" type=\"text\" name=\"item_" + inIndex + "\" class=\"text1 item_" + inIndex + "\" id=\"item\" value=\"" + inIndex + "\" />";
	tblCol2 = tblRow.insertCell(1);
	tblCol2.className = "text";
  tblCol2.innerHTML = "<input type=\"text\" name=\"quant_" + inIndex + "\" class=\"text1 quant_" + inIndex + "\" id=\"quant\" onblur=\"javascript:preco_tot();\" />";
    tblCol3 = tblRow.insertCell(2);
    tblCol3.className = "text";
  tblCol3.innerHTML = "<input type=\"text\" name=\"descricao_" + inIndex + "\" class=\"text1 descricao_" + inIndex + "\" id=\"desc\" />";
    tblCol4 = tblRow.insertCell(3);
    tblCol4.className = "text";
  tblCol4.innerHTML = "<input type=\"text\" name=\"preco_un_" + inIndex + "\" class=\"text1 preco_un_" + inIndex + "\" id=\"preco_un\" onblur=\"javascript:preco_tot();\" />";
    tblCol5 = tblRow.insertCell(4);
    tblCol5.className = "text";
  tblCol5.innerHTML = "<input type=\"text\" name=\"preco_total_" + inIndex + "\" class=\"text1 preco_total_" + inIndex + "\" id=\"preco_total\"  disabled=\"disabled\" />";

  jQuery('#section.area_representante #content form.form_area_representante input.text').each(function(i){
		jQuery(this).removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected'); });
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});
	});

}

function precototal(){
        var cont = 1;
        var qtd_linhas = jQuery('#qtd_produtos').val();

        while(cont<=qtd_linhas){
        var quantidade = jQuery('.quant_'+cont).val();
        var preco_unitario = jQuery('.preco_un_'+cont).val();
        var preco_total_liq;
        preco_unitario = preco_unitario.replace(",",".");//Pega um valor formatado com vírgula e o transforma em float
        preco_total_liq = (quantidade) * (preco_unitario);//Multiplica o preço unitário e a quantidade
        jQuery('.preco_total_'+cont).val(preco_total_liq);//Joga a multiplicação do preço unitário e a quantidade
        cont++;
        }
}

////////////////////////////////////////PARA MOVER A BARRINHA AO LADO DO MENU/////////////////////////////////////////////////
/*function NavUnderline(positionTop,elementStart) {

      //Customizable
	var positionTop = positionTop; //Get (in px) the top background position
	var positionLeft = elementStart; //Get the id of element for start position
	var defaultPositionLeft = 0; //Default position (in px) for start left background (if positionLeft is blank)
	var parentalElement = '#header .nav'; //Element with the background image and container of elements for navigation
	var elements = 'li'; //Elements for navigation (without parental)
	var underlineHeight = 19; //Width of underline image (in px)


	//Ok, thats all...
	var quantity = jQuery(parentalElement).children().size();;
	var i; var o;
	var position = 0;
    quantity = (quantity/2) - 1;

	//Started position
	if(positionLeft != '/' && positionLeft != '') {
		for(i=0;i<quantity;i++) {
			if(jQuery(parentalElement+' '+elements+':eq('+i+')').attr('class') == positionLeft) {
				for(o=0;o<i;o++) {
					if(jQuery(parentalElement+' '+elements+':eq('+o+')').attr('class') != "pipe" && jQuery(parentalElement+' '+elements+':eq('+o+')').attr('class') != "inicial" ){
                    position += jQuery(parentalElement+' '+elements+':eq('+o+')').outerHeight();
					position += 12;
                    }

				}
				position += (jQuery(parentalElement+' '+elements+':eq('+i+')').outerHeight() + 12)/2;
				position -= underlineHeight/2;
                //alert(position);
				positionLeft = position;
				jQuery(parentalElement).css({backgroundPosition:positionTop+" "+positionLeft+"px "});
				position = 0;
			}
		}
	} else {
		positionLeft = defaultPositionLeft;
		jQuery(parentalElement).css({backgroundPosition:positionTop+" "+positionLeft+"px "});
	}

	//Set position of elements
	jQuery(parentalElement + ' ' + elements).each(function(i) {
		jQuery(this).mouseover(function() {
			for(o=0;o<i;o++) {
				if(jQuery(parentalElement+' '+elements+':eq('+o+')').attr('class') != "pipe"){
				position += jQuery(parentalElement+' '+elements+':eq('+o+')').outerHeight();
				position += 12;
                }
			}
			position += jQuery(this).outerHeight()/2;
			position -= underlineHeight/2;
			jQuery(parentalElement).stop().animate({backgroundPosition:positionTop+" "+position+"px "});
		});
	});

	//Return to default position
	jQuery(parentalElement + ' ' + elements).mouseout(function() {
		position = 0;
		jQuery(parentalElement).stop().animate({backgroundPosition:positionTop+" "+positionLeft+"px "});
	});
}*/


////////////////////////////////////////PARA MOVER A BARRINHA AO LADO DO MENU/////////////////////////////////////////////////
function NavUnderline(positionTop,elementStart) {

      //Customizable
	var positionTop = positionTop; //Get (in px) the top background position (na verdade essa é a posição da esquerda)
	var positionLeft = elementStart; //Get the id of element for start position
	var defaultPositionLeft = -7; //Default position (in px) for start left background (if positionLeft is blank)
	var parentalElement = '#menu'; //Element with the background image and container of elements for navigation
	var elements = 'li'; //Elements for navigation (without parental)
	var underlineHeight = 19; //Width of underline image (in px)
	var image = '.sideline'; //

	//Ok, thats all...
	var quantity = jQuery(parentalElement+" ul").children().size();
	var i; var o;
	var position = 0;
    quantity = (quantity) - 1;

	//Started position
	if(positionLeft != '/' && positionLeft != '' && positionLeft != 'inicial') {
		for(i=0;i<quantity;i++) {
			if(jQuery(parentalElement+' '+elements+':eq('+i+')').attr('class') == positionLeft) {
				for(o=0;o<i;o++) {
					if(jQuery(parentalElement+' '+elements+':eq('+o+')').attr('class') != "pipe" && jQuery(parentalElement+' '+elements+':eq('+o+')').attr('class') != "inicial" ){
                    position += jQuery(parentalElement+' '+elements+':eq('+o+')').outerHeight();
                    }

				}
				position += (jQuery(parentalElement+' '+elements+':eq('+i+')').outerHeight())/2;
				position -= underlineHeight/2;
                position -= 4;
				positionLeft = position;
				jQuery(parentalElement+" "+image).css({marginTop:positionLeft+"px "});
				position = 0;
			}

		}
	} else {
		positionLeft = defaultPositionLeft;
		jQuery(parentalElement+" "+image).css({marginTop:positionLeft+"px "});
	}

	//Set position of elements
	jQuery(parentalElement + ' ' + elements).each(function(i) {
		jQuery(this).mouseover(function() {
			for(o=0;o<i;o++) {
				if(jQuery(parentalElement+' '+elements+':eq('+o+')').attr('class') != "pipe" && jQuery(parentalElement+' '+elements+':eq('+o+')').attr('class') != "inicial" ){
				position += jQuery(parentalElement+' '+elements+':eq('+o+')').outerHeight();
				//position += 12;
                }
			}
			position += (jQuery(this).outerHeight())/2;
			position -= underlineHeight/2;
            position -= 4;
			jQuery(parentalElement+" "+image).stop().animate({marginTop:position+"px "});
		});
	});

	//Return to default position
	jQuery(parentalElement + ' ' + elements).mouseout(function() {
		position = 0;
		jQuery(parentalElement+" "+image).stop().animate({marginTop:positionLeft+"px "});
	});
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////SIDELINE for NAV links
////////////////////////////////////////////////////////////////
function SideLine(parentalElement,defaultPosition,option) {
	//Customizable
	var parentalElement = parentalElement; //Element of container of elements for navigation and image
	var elements = 'ul.nav li'; //Elements for navigation (without parental)
	var image = '.sideline'; //Image element
	var defaultPosition = defaultPosition; //Default position of image

	//Ok, thats all...
	var quantity = $(parentalElement + ' ' + elements).length;
	var i; var o; var clicked; var newPosition;
	var position = defaultPosition;
	var underlineHeight = $(parentalElement + ' ' + image).outerHeight();

	//Started position
	$(parentalElement + ' ' + image).animate({marginTop:defaultPosition + "px"});

	//Close the box
	if(option == "close") {
		$(parentalElement + ' .infobox').fadeOut('fast');
		$(parentalElement + ' ' + elements).each(function(i) {
			$(this).removeClass('checked');
		});
	}

	//On mouse over and click
	$(parentalElement + ' ' + elements).each(function(i) {
		//On mouse over
		$(this).mouseover(function() {
			if(clicked != true) { //If dont clicked on a link
				for(o=0;o<i;o++) {
					position += $(parentalElement+' '+elements+':eq('+o+')').outerHeight();
				}
				position += underlineHeight/2;
				position += defaultPosition/2;

				$(parentalElement + ' ' + image).stop().animate({marginTop:position + "px"});
			} else { //If clicked on a link
				for(o=0;o<i;o++) {
					position += $(parentalElement+' '+elements+':eq('+o+')').outerHeight();
				}
				position += underlineHeight/2;
				position += defaultPosition;
				$(parentalElement + ' ' + image).stop().animate({marginTop:position + "px"});
			}
		});
		//On click on a link
		$(this).click(function() {
			$(parentalElement + ' ' + elements).each(function(i) {
				$(this).removeClass('checked');
			});
			$(parentalElement + ' ' + image).stop().animate({marginTop:position + "px"});
			$(this).addClass('checked');
			clicked = true;
			newPosition = position;
		});
	});

	//Return to default position
	$(parentalElement + ' ' + elements).mouseout(function() {
		if(clicked != true) {
			position = defaultPosition;
			$(parentalElement + ' ' + image).stop().animate({marginTop:defaultPosition + "px"});
		} else {
			position = 0;
			$(parentalElement + ' ' + image).stop().animate({marginTop:newPosition + "px"});
		}

	});
}

/////////////PARA FECHAR AS MSGS DE ERRO/ACERTO/////////////

function fechar(box){
    jQuery('.message_box .error').css('display','none');
    if(box==2){////////CADASTRE-SE/////
      jQuery('.message_box .sucess').css('display','none');
      jQuery('.tipo form table').css('display','block');
      jQuery('.cliente').css('display','block');

      jQuery('.cliente table input.text').each(function(i){
        jQuery(this).attr("value","");
	});

    }
    else{
		if(box==4){/////FALE CONOSCO//////
        jQuery('.message_box .sucess').css('display','none');
        jQuery('.form_fale_conosco').css('display','block');

        jQuery('.form_fale_conosco table input.text').each(function(i){
            jQuery(this).attr("value","");
	    });

        jQuery('.form_fale_conosco table textarea').each(function(i){
            jQuery(this).attr("value","");
	    });
		}
        else{/////AREA DO REPRESENTANTE//////
        jQuery('.message_box .sucess').css('display','none');
        jQuery('.message_box_esqueci .sucess_esqueci').css('display','none');
        jQuery('.message_box_login .error_login').css('display','none');
        jQuery('.message_box_esqueci .error_esqueci').css('display','none');
        jQuery('.form_area_representante').css('display','block');

        jQuery('.form_area_representante table input.text').each(function(i){
            jQuery(this).attr("value","");
	    });

        jQuery('.form_area_representante table textarea').each(function(i){
            jQuery(this).attr("value","");
	    });

        }
    }
}

/////////////PARA MOSTRAR O FORM DA NEWSLETTER/////////////

function mostra(){
    jQuery('#header .altbox #msgerro .erro').css('display','none');
    jQuery('#header .newsletter form').css('display','block');

        jQuery('#header .newsletter form input.text').each(function(i){
        jQuery(this).attr("value","");
	});

}
////////////PARA CALCULAR O PREÇO TOTAL DA TABELA DE PRODUTOS(AREA REPRESENTANTE)//////////////////////
function preco_tot(){
  var total	= total_parc = 0;
  jQuery('#section.area_representante form.form_area_representante input#preco_total').each(function(i) { //For each element

    var item = i+1;
    if(jQuery('#section.area_representante form.form_area_representante input.quant_'+item).val() != '' && jQuery('#section.area_representante form.form_area_representante input.preco_un_'+item).val() != '' && jQuery('#section.area_representante form.form_area_representante input.preco_un_'+item).val() != 'R$' ){
      var qtd = parseInt(jQuery('#section.area_representante form.form_area_representante input.quant_'+item).val());
      var pu = jQuery('#section.area_representante form.form_area_representante input.preco_un_'+item).val();
      var pt = jQuery('#section.area_representante form.form_area_representante input.preco_total_'+item).val();
      pu = pu.replace(",",".");
      total_parc = pu * qtd;
      total_parc = total_parc.toFixed(2);
      pt = "R$"+total_parc;


     jQuery('#section.area_representante form.form_area_representante input.preco_total_'+item).attr('value',pt);
    }
    else{
      jQuery('#section.area_representante form.form_area_representante input.preco_total_'+item).attr('value','');
    }


    if(jQuery(this).val() != ''){
     var resultado;
     resultado = jQuery(this).val();
     resultado = resultado.replace("R$","");
	 total += parseFloat(resultado);

    }
  });

   if(jQuery('#section.area_representante form.form_area_representante input#desconto').val() != ''){
     var desconto = jQuery('#section.area_representante form.form_area_representante input#desconto').val();
     if(desconto.search('%') != -1){
      desconto = desconto.replace("%",""); desconto = desconto.replace(",",".");  desconto = desconto/100;  total = total - (total * desconto); total = total.toFixed(2);
     }
     else{
      total -= desconto;
      total = total.toFixed(2);
     }

   }

  total = "R$"+total;
  jQuery('#section.area_representante form.form_area_representante input#valor_total').attr('value',total);

}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
jQuery(document).ready(function(){
	////////////////////////////////////////////////////////////////Página 'representantes.php' - Área de representantes
	////////////////////////////////////////////////////////////////Get content of "servicos" page and put in container
	////////////////////////////////////////////////////////////////
    /*jQuery('#section.area_representante form.form_area_representante input#quant').each(function(i) { //For each element
		jQuery(this).blur(function() {
		   var item = i+1;
           var valor = jQuery('#section.area_representante form.form_area_representante input.preco_un_'+item).val();
           var valor = valor.replace(",",".");
           var qtd = parseInt(this.value);
           var valor_total = 0;

           if(valor != '' && qtd != ''){
            var total = valor * qtd;
            jQuery('#section.area_representante form.form_area_representante input.preco_total_'+item).attr('value',total);
            //valor_total = parseFloat(jQuery('#section.area_representante form.form_area_representante input#valor_total').val()) + parseFloat(total);
            //jQuery('#section.area_representante form.form_area_representante input#valor_total').attr('value',valor_total);
           }




		});

	});
    jQuery('#section.area_representante form.form_area_representante input#preco_un').each(function(i) { //For each element
		jQuery(this).blur(function() {
		   var item = i+1;
           var valor = this.value;
           var valor = valor.replace(",",".");
           var qtd = jQuery('#section.area_representante form.form_area_representante input.quant_'+item).val();
           var valor_total = 0;

           if(valor != '' && qtd != ''){
            var total = valor * qtd;
            jQuery('#section.area_representante form.form_area_representante input.preco_total_'+item).attr('value',total);
            //valor_total = parseFloat(jQuery('#section.area_representante form.form_area_representante input#valor_total').val()) + parseFloat(total);
            //jQuery('#section.area_representante form.form_area_representante input#valor_total').attr('value',valor_total);
           }
		});
	});*/


    //jQuery('#p1 .infobox, #p2 .infobox, #p3 .infobox').hide();

	jQuery('#p1 ul li a.list').each(function(i) { //For each element
		jQuery(this).click(function() {
			var jQueryhtml = jQuery('#p1 ul li .info').eq(i).html();
			jQuery('#p1 .infobox').fadeOut('fast', function() {jQuery('#p1 .infobox').fadeIn('normal'); jQuery('#p1 .infobox').html('<a href="javascript:SideLine(\'#p1\',25,\'close\')" title="Fechar esta informação" class="fechar">Fechar</a>' + jQueryhtml);});
		});
	});
	jQuery('#p2 ul li a.list').each(function(i) { //For each element
		jQuery(this).click(function() {
			var jQueryhtml = jQuery('#p2 ul li .info').eq(i).html();
			jQuery('#p2 .infobox').fadeOut('fast', function() {jQuery('#p2 .infobox').fadeIn('normal'); jQuery('#p2 .infobox').html('<a href="javascript:SideLine(\'#p2\',25,\'close\')" title="Fechar esta informação" class="fechar">Fechar</a>' + jQueryhtml);});
		});
	});
	jQuery('#p3 ul li a.list').each(function(i) { //For each element
		jQuery(this).click(function() {
			var jQueryhtml = jQuery('#p3 ul li .info').eq(i).html();
			jQuery('#p3 .infobox').fadeOut('fast', function() {jQuery('#p3 .infobox').fadeIn('normal'); jQuery('#p3 .infobox').html('<a href="javascript:SideLine(\'#p3\',25,\'close\')" title="Fechar esta informação" class="fechar">Fechar</a>' + jQueryhtml);});
		});
	});
    jQuery(".representantes h5").each(function(i){
      jQuery(this).click(function(){
      jQuery(".representantes ul.info").eq(i).slideToggle();
      if(jQuery(this).is(".selected"))
      {
        jQuery(this).removeClass("selected");
      }
      else
      {
        jQuery(this).addClass("selected");
      }
    });
    });


//////////////////////////////////VALIDAÇÃO NEWSLETTER/////////////////////////////////////////////

//QUANDO O FOCO ESTIVER NO CAMPO TEXT
    jQuery('#header .newsletter form input.text').each(function(i){
		jQuery(this).removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected')});
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});
	});

    //AO CLICAR NO BOTÃO OK
    jQuery('#header .newsletter form').submit(function() {

		//VERIFICA SE OS DADOS NOS CAMPOS SÃO VÁLIDOS
		var hasError = false;
		var msg = '';
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var txtReg = /^[a-z A-ZãÃáÁàÀêÊéÉèÈíÍìÌôÔõÕóÓòÒúÚùÙûÛçÇ\.]+$/;
		var nmbReg = /^\d+$/;
		var phoneReg = /^(\(\d{2}\)|\d{2})?\s?\d{4}-?\d{4}$/;
		var cnpjReg = /^(\d{2})\.(\d{3})\.(\d{3})\/(\d{4})-(\d{2})$/;


       //CHECA TODOS OS CAMPOS TEXT NO FORMULÁRIO
		jQuery('#header .newsletter form input.text').each(function(i){
			//Reset classes
			jQuery(this).removeClass('selected');
			jQuery(this).removeClass('error');

			//VERIFICA SE ALGUM CAMPO ESTÁ EM BRANCO,SE ESTIVER,O TEXT FICA VERMELHO
			if(!jQuery(this).val()) {
				jQuery(this).addClass('error');
				hasError = true;
			}
		});

        //SE TODOS OS CAMPOS ESTIVEREM CORRETOS,ATRIBUI O VALOR AS VARIÁVEIS
	   	if(hasError == false) {
            //Variables for values
			var news = jQuery('#header .newsletter form input.text');


        	//VALIDAÇÕES
			if(!emailReg.test(jQuery(news).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = "<p>Erro. Endereço de email não válido.<br /><a href='javascript:mostra();'>Clique e tente novamente.</a></p>";
				jQuery(news).addClass('error');
			}
		}

		//SE ESTIVER ALGUM CAMPO ERRADO IRÁ MOSTRAR AS MENSAGENS DE ERRO
	   	if(hasError == true){
 			if(msg == '') {
				jQuery('#header .altbox #msgerro .erro').fadeIn('fast').html('<p>Erro. Endereço de email não válido.<br /><a href="javascript:mostra();">Clique e tente novamente.</a></p>');
                jQuery('#header .newsletter form').css('display','none');
			} else {
				jQuery('#header .altbox #msgerro .erro').fadeIn('fast').html(msg);
                jQuery('#header .newsletter form').css('display','none');
			}
         }
         //ESTANDO TUDO CERTO IRÁ ENVIAR PARA O BANCO DE DADOS E MOSTRAR A MENSAGEM DE CADASTRADO COM SUCESSO
	    else {
			jQuery('#header .altbox #msgerro .acerto').ajaxStart(function(){jQuery(this).fadeIn('fast').html('<p>Aguarde...</p>')});
            jQuery('#header .newsletter form').css('display','none');

			jQuery.ajax({
				type: "POST",
				url: "_newsletter.php",
				data: "news="+jQuery(news).val(),
				success: function(){
					jQuery('#header .altbox #msgerro .acerto').fadeIn('fast').html('<p>Email cadastrado com sucesso!</p>');
                    jQuery('#header .newsletter form').css('display','none');

				}

			});


		}


        return false;

        });

//////////////////////////////////VALIDAÇÃO CADASTRE-SE (CLIENTE)/////////////////////////////////////////////

    //QUANDO O FOCO ESTIVER NO CAMPO TEXT(CLIENTE)
    jQuery('#section.cadastre_se #content .cliente table input.text').each(function(i){
		jQuery(this).removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected')});
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});
	});

    //MÁSCARA PARA TELEFONE(CLIENTE)
    jQuery('#section.cadastre_se #content .cliente table tr td input#telefone').mask("(99) 9999-9999",{placeholder:" "});


    //AO CLICAR NO BOTÃO OK(CLIENTE)
    jQuery('#section.cadastre_se #content .cliente form').submit(function() {

		//VERIFICA SE OS DADOS NOS CAMPOS SÃO VÁLIDOS
		var hasError = false;
		var msg = '';
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var txtReg = /^[a-z A-ZãÃáÁàÀêÊéÉèÈíÍìÌôÔõÕóÓòÒúÚùÙûÛçÇ\.]+$/;
		var nmbReg = /^\d+$/;
		var phoneReg = /^(\(\d{2}\)|\d{2})?\s?\d{4}-?\d{4}$/;
		var cnpjReg = /^(\d{2})\.(\d{3})\.(\d{3})\/(\d{4})-(\d{2})$/;


       //CHECA TODOS OS CAMPOS TEXT NO FORMULÁRIO
		jQuery('#section.cadastre_se #content .cliente table input.text').each(function(i){
			//Reset classes
			jQuery(this).removeClass('selected');
			jQuery(this).removeClass('error');

			//VERIFICA SE ALGUM CAMPO ESTÁ EM BRANCO,SE ESTIVER,O TEXT FICA VERMELHO
			if(!jQuery(this).val()) {
				jQuery(this).addClass('error');
				hasError = true;
			}
		});

        //SE TODOS OS CAMPOS ESTIVEREM CORRETOS,ATRIBUI O VALOR AS VARIÁVEIS
	   	if(hasError == false) {
            //Variables for values
			var nome = jQuery('#section.cadastre_se #content .cliente table tr td input#nome');
            var email = jQuery('#section.cadastre_se #content .cliente table tr td input#email');
			var telefone = jQuery('#section.cadastre_se #content .cliente table tr td input#telefone');
			var endereco = jQuery('#section.cadastre_se #content .cliente table tr td input#endereco');
		   	var cidade = jQuery('#section.cadastre_se #content .cliente table tr td input#cidade');
			var estado= jQuery('#section.cadastre_se #content .cliente table tr td select#estado');
			var pais = jQuery('#section.cadastre_se #content .cliente table tr td input#pais');

        	//VALIDAÇÕES
			if(!emailReg.test(jQuery(email).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = "<p>Este email não é válido!</p>";
				jQuery(email).addClass('error');
			}

            if(!phoneReg.test(jQuery(telefone).val())) { //VALIDAÇÃO DO TELEFONE
				hasError = true;
				msg = "<p>Este telefone não é válido!</p>";
				jQuery(telefone).addClass('error');
			}
		}

		//SE ESTIVER ALGUM CAMPO ERRADO IRÁ MOSTRAR AS MENSAGENS DE ERRO
	   	if(hasError == true){
 			if(msg == '') {
				jQuery('#section.cadastre_se #content .message_box .error').fadeIn('fast').html('<p><strong>Algo está errado!</strong> Confira os campos em vermelho e preencha-os novamente.</p><a id="fecha_error" href="javascript:fechar(1);" ><img src="_images/area_representante/fechar_msg_error.gif"/></a>');
			} else {
				jQuery('#section.cadastre_se #content .message_box .error').fadeIn('fast').html(msg);
			}
         }
         //ESTANDO TUDO CERTO IRÁ ENVIAR PARA O BANCO DE DADOS E MOSTRAR A MENSAGEM DE CADASTRADO COM SUCESSO
	    else {
			jQuery('#section.cadastre_se #content .message_box .sucess').ajaxStart(function(){jQuery(this).fadeIn('fast').html('<p>Aguarde...</p>')});

			jQuery.ajax({
				type: "POST",
				url: "_cadastro.php",
				data: "nome="+jQuery(nome).val()+"&email="+jQuery(email).val()+"&telefone="+jQuery(telefone).val()+"&endereco="+jQuery(endereco).val()+"&cidade="+jQuery(cidade).val()+"&estado="+jQuery(estado).val()+"&pais="+jQuery(pais).val(),
				success: function(msg){
					jQuery('#section.cadastre_se #content .message_box .sucess').fadeIn('fast').html('<p><strong>Sucesso!</strong> Você foi cadastrado corretamente.</p><a id="fecha_sucess" href="javascript:fechar(2);" ><img src="_images/area_representante/fechar_msg_sucess.gif"/></a>');
                    jQuery('#section.cadastre_se #content .tipo table').css('display','none');
                    jQuery('#section.cadastre_se #content .cliente').css('display','none');
                    //jQuery('#section.cadastre_se #content .teste').html(msg);

				}

			});


		}


        return false;

        });

//////////////////////////////////VALIDAÇÃO CADASTRE-SE (REPRESENTANTE)/////////////////////////////////////////////

   //QUANDO O FOCO ESTIVER NO CAMPO TEXT(REPRESENTANTE)
    jQuery('#section.cadastre_se #content .representante table input.text').each(function(i){
		jQuery(this).removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected')});
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});
	});

    //MÁSCARA PARA TELEFONE(REPRESENTANTE)
    jQuery('#section.cadastre_se #content .representante table tr td input#telefone').mask("(99) 9999-9999",{placeholder:" "});

    //AO CLICAR NO BOTÃO OK(REPRESENTANTE)
    jQuery('#section.cadastre_se #content .representante form').submit(function() {

		//VERIFICA SE OS DADOS NOS CAMPOS SÃO VÁLIDOS
		var hasError = false;
		var msg = '';
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var txtReg = /^[a-z A-ZãÃáÁàÀêÊéÉèÈíÍìÌôÔõÕóÓòÒúÚùÙûÛçÇ\.]+$/;
		var nmbReg = /^\d+$/;
		var phoneReg = /^(\(\d{2}\)|\d{2})?\s?\d{4}-?\d{4}$/;
		var cnpjReg = /^(\d{2})\.(\d{3})\.(\d{3})\/(\d{4})-(\d{2})$/;


       //CHECA TODOS OS CAMPOS TEXT NO FORMULÁRIO
		jQuery('#section.cadastre_se #content .representante table input.text').each(function(i){
			//Reset classes
			jQuery(this).removeClass('selected');
			jQuery(this).removeClass('error');

			//VERIFICA SE ALGUM CAMPO ESTÁ EM BRANCO,SE ESTIVER,O TEXT FICA VERMELHO
			if(!jQuery(this).val()) {
				jQuery(this).addClass('error');
				hasError = true;
			}
		});

        //SE TODOS OS CAMPOS ESTIVEREM CORRETOS,ATRIBUI O VALOR AS VARIÁVEIS
	   	if(hasError == false) {
            //Variables for values
			var cnpj = jQuery('#section.cadastre_se #content .representante table tr td input#cnpj');
			var contato = jQuery('#section.cadastre_se #content .representante table tr td input#contato');
			var razao = jQuery('#section.cadastre_se #content .representante table tr td input#razao');
			var insc = jQuery('#section.cadastre_se #content .representante table tr td input#insc');
		    var email = jQuery('#section.cadastre_se #content .representante table tr td input#email');
			var telefone = jQuery('#section.cadastre_se #content .representante table tr td input#telefone');
			var endereco = jQuery('#section.cadastre_se #content .representante table tr td input#endereco');
			var bairro = jQuery('#section.cadastre_se #content .representante table tr td input#bairro');
		   	var cidade = jQuery('#section.cadastre_se #content .representante table tr td input#cidade');
			var estado= jQuery('#section.cadastre_se #content .representante table tr td select#estado');
			var cep= jQuery('#section.cadastre_se #content .representante table tr td input#cep');
			var pais = jQuery('#section.cadastre_se #content .representante table tr td input#pais');

        	//VALIDAÇÕES
			if(!emailReg.test(jQuery(email).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = "<p>Este email não é válido!</p>";
				jQuery(email).addClass('error');
			}


            if(!phoneReg.test(jQuery(telefone).val())) { //VALIDAÇÃO DO TELEFONE
				hasError = true;
				msg = "<p>Este telefone não é válido!</p>";
				jQuery(telefone).addClass('error');
			}
		}

		//SE ESTIVER ALGUM CAMPO ERRADO IRÁ MOSTRAR AS MENSAGENS DE ERRO
	   	if(hasError == true){
 			if(msg == '') {
				jQuery('#section.cadastre_se #content .message_box .error').fadeIn('fast').html('<p><strong>Algo está errado!</strong> Confira os campos em vermelho e preencha-os novamente.</p><a id="fecha_error" href="javascript:fechar(1);" ><img src="_images/area_representante/fechar_msg_error.gif"/></a>');
			} else {
				jQuery('#section.cadastre_se #content .message_box .error').fadeIn('fast').html(msg);
			}
         }
         //ESTANDO TUDO CERTO IRÁ ENVIAR PARA O BANCO DE DADOS E MOSTRAR A MENSAGEM DE CADASTRADO COM SUCESSO
	    else {
			jQuery('#section.cadastre_se #content .message_box .sucess').ajaxStart(function(){jQuery(this).fadeIn('fast').html('<p>Aguarde...</p>')});

			jQuery.ajax({
				type: "POST",
				url: "_cadastro_representante.php",
				data: "cnpj="+jQuery(cnpj).val()+"&contato="+jQuery(contato).val()+"&razao="+jQuery(razao).val()+"&insc="+jQuery(insc).val()+"&email="+jQuery(email).val()+"&telefone="+jQuery(telefone).val()+"&endereco="+jQuery(endereco).val()+"&bairro="+jQuery(bairro).val()+
                "&cidade="+jQuery(cidade).val()+"&estado="+jQuery(estado).val()+"&cep="+jQuery(cep).val()+"&pais="+jQuery(pais).val(),
				success: function(){
					jQuery('#section.cadastre_se #content .message_box .sucess').fadeIn('fast').html('<p><strong>Sucesso!</strong> Você foi cadastrado corretamente.</p><a id="fecha_sucess" href="javascript:fechar(2);" ><img src="_images/area_representante/fechar_msg_sucess.gif"/></a>');
                    jQuery('#section.cadastre_se #content .tipo table').css('display','none');
                    jQuery('#section.cadastre_se #content .representante').css('display','none');

               	}

			});


		}


        return false;

        });

//////////////////////////////////VALIDAÇÃO CADASTRE-SE (LOJISTA)/////////////////////////////////////////////

   //QUANDO O FOCO ESTIVER NO CAMPO TEXT(REPRESENTANTE)
    jQuery('#section.cadastre_se #content .lojista table input.text').each(function(i){
		jQuery(this).removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected')});
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});
	});

    //MÁSCARA PARA TELEFONE(REPRESENTANTE)
    jQuery('#section.cadastre_se #content .lojista table tr td input#telefone').mask("(99) 9999-9999",{placeholder:" "});

    //AO CLICAR NO BOTÃO OK(REPRESENTANTE)
    jQuery('#section.cadastre_se #content .lojista form').submit(function() {

		//VERIFICA SE OS DADOS NOS CAMPOS SÃO VÁLIDOS
		var hasError = false;
		var msg = '';
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var txtReg = /^[a-z A-ZãÃáÁàÀêÊéÉèÈíÍìÌôÔõÕóÓòÒúÚùÙûÛçÇ\.]+$/;
		var nmbReg = /^\d+$/;
		var phoneReg = /^(\(\d{2}\)|\d{2})?\s?\d{4}-?\d{4}$/;
		var cnpjReg = /^(\d{2})\.(\d{3})\.(\d{3})\/(\d{4})-(\d{2})$/;


       //CHECA TODOS OS CAMPOS TEXT NO FORMULÁRIO
		jQuery('#section.cadastre_se #content .lojista table input.text').each(function(i){
			//Reset classes
			jQuery(this).removeClass('selected');
			jQuery(this).removeClass('error');

			//VERIFICA SE ALGUM CAMPO ESTÁ EM BRANCO,SE ESTIVER,O TEXT FICA VERMELHO
			if(!jQuery(this).val()) {
				jQuery(this).addClass('error');
				hasError = true;
			}
		});

        //SE TODOS OS CAMPOS ESTIVEREM CORRETOS,ATRIBUI O VALOR AS VARIÁVEIS
	   	if(hasError == false) {
            //Variables for values
			var cnpj = jQuery('#section.cadastre_se #content .lojista table tr td input#cnpj');
			var contato = jQuery('#section.cadastre_se #content .lojista table tr td input#contato');
			var razao = jQuery('#section.cadastre_se #content .lojista table tr td input#razao');
			var insc = jQuery('#section.cadastre_se #content .lojista table tr td input#insc');
		    var email = jQuery('#section.cadastre_se #content .lojista table tr td input#email');
			var telefone = jQuery('#section.cadastre_se #content .lojista table tr td input#telefone');
			var endereco = jQuery('#section.cadastre_se #content .lojista table tr td input#endereco');
			var bairro = jQuery('#section.cadastre_se #content .lojista table tr td input#bairro');
		   	var cidade = jQuery('#section.cadastre_se #content .lojista table tr td input#cidade');
			var estado= jQuery('#section.cadastre_se #content .lojista table tr td select#estado');
			var cep= jQuery('#section.cadastre_se #content .lojista table tr td input#cep');
			var pais = jQuery('#section.cadastre_se #content .lojista table tr td input#pais');

        	//VALIDAÇÕES
			if(!emailReg.test(jQuery(email).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = "<p>Este email não é válido!</p>";
				jQuery(email).addClass('error');
			}


            if(!phoneReg.test(jQuery(telefone).val())) { //VALIDAÇÃO DO TELEFONE
				hasError = true;
				msg = "<p>Este telefone não é válido!</p>";
				jQuery(telefone).addClass('error');
			}
		}

		//SE ESTIVER ALGUM CAMPO ERRADO IRÁ MOSTRAR AS MENSAGENS DE ERRO
	   	if(hasError == true){
 			if(msg == '') {
				jQuery('#section.cadastre_se #content .message_box .error').fadeIn('fast').html('<p><strong>Algo está errado!</strong> Confira os campos em vermelho e preencha-os novamente.</p><a id="fecha_error" href="javascript:fechar(1);" ><img src="_images/area_representante/fechar_msg_error.gif"/></a>');
			} else {
				jQuery('#section.cadastre_se #content .message_box .error').fadeIn('fast').html(msg);
			}
         }
         //ESTANDO TUDO CERTO IRÁ ENVIAR PARA O BANCO DE DADOS E MOSTRAR A MENSAGEM DE CADASTRADO COM SUCESSO
	    else {
			jQuery('#section.cadastre_se #content .message_box .sucess').ajaxStart(function(){jQuery(this).fadeIn('fast').html('<p>Aguarde...</p>')});

			jQuery.ajax({
				type: "POST",
				url: "_cadastro_lojista.php",
				data: "cnpj="+jQuery(cnpj).val()+"&contato="+jQuery(contato).val()+"&razao="+jQuery(razao).val()+"&insc="+jQuery(insc).val()+"&email="+jQuery(email).val()+"&telefone="+jQuery(telefone).val()+"&endereco="+jQuery(endereco).val()+"&bairro="+jQuery(bairro).val()+
                "&cidade="+jQuery(cidade).val()+"&estado="+jQuery(estado).val()+"&cep="+jQuery(cep).val()+"&pais="+jQuery(pais).val(),
				success: function(){
					jQuery('#section.cadastre_se #content .message_box .sucess').fadeIn('fast').html('<p><strong>Sucesso!</strong> Você foi cadastrado corretamente.</p><a id="fecha_sucess" href="javascript:fechar(2);" ><img src="_images/area_representante/fechar_msg_sucess.gif"/></a>');
                    jQuery('#section.cadastre_se #content .tipo table').css('display','none');
                    jQuery('#section.cadastre_se #content .lojista').css('display','none');

               	}

			});


		}


        return false;

        });

//////////////////////////////////VALIDAÇÃO ESQUECI SENHA/////////////////////////////////////////////

    //QUANDO O FOCO ESTIVER NO CAMPO TEXT
    jQuery('#section.esqueci_minha_senha #content #esqueceu table input.text').each(function(i){
		jQuery(this).removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected')});
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});
	});

    //AO CLICAR NO BOTÃO ENVIAR
    jQuery('#section.esqueci_minha_senha #content #esqueceu').submit(function() {

		//VERIFICA SE OS DADOS NOS CAMPOS SÃO VÁLIDOS
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        var msg = '';

        //CHECA TODOS OS CAMPOS TEXT NO FORMULÁRIO
		jQuery('#section.esqueci_minha_senha #content #esqueceu table input.text').each(function(i){
			//Reset classes
			jQuery(this).removeClass('selected');
			jQuery(this).removeClass('error');

			//VERIFICA SE ALGUM CAMPO ESTÁ EM BRANCO,SE ESTIVER,O TEXT FICA VERMELHO
			if(!jQuery(this).val()) {
				jQuery(this).addClass('error');
				hasError = true;
			}
		});

        //SE TODOS OS CAMPOS ESTIVEREM CORRETOS,ATRIBUI O VALOR AS VARIÁVEIS
	   	if(hasError == false) {
            //Variables for values
            var email = jQuery('#section.esqueci_minha_senha #content #esqueceu table input#email');


        	//VALIDAÇÕES
			if(!emailReg.test(jQuery(email).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = "<p>Este email não é válido!</p>";
				jQuery(email).addClass('error');
			}
		}


		//SE ESTIVER ALGUM CAMPO ERRADO IRÁ MOSTRAR AS MENSAGENS DE ERRO
	   	if(hasError == true){
 			if(msg == ''){
				jQuery('#section.esqueci_minha_senha #content .message_box_esqueci .error_esqueci').fadeIn('fast').html('<p>Email inv&aacute;lido!</p><a id="fecha_error" href="javascript:fechar(1);" ><img src="_images/area_representante/fechar_msg_error.gif"/></a>');
			}else{
				jQuery('#section.esqueci_minha_senha #content .message_box_esqueci .error_esqueci').fadeIn('fast').html(msg);
           }
         }  //ESTANDO TUDO CERTO IRÁ ENVIAR PARA O BANCO DE DADOS E MOSTRAR A MENSAGEM DE CADASTRADO COM SUCESSO
	    else {
			jQuery('#section.esqueci_minha_senha #content .message_box_esqueci .sucess_esqueci').ajaxStart(function(){jQuery(this).fadeIn('fast').html('<p>Aguarde...</p>')});

			jQuery.ajax({
				type: "POST",
				url: "_arearepresentante.php",
				data: "email="+jQuery(email).val(),
				success: function(){
					jQuery('#section.esqueci_minha_senha #content .message_box_esqueci .sucess_esqueci').fadeIn('fast').html('<p><strong>Sucesso!</strong> Você foi cadastrado corretamente.</p><a id="fecha_sucess" href="javascript:fechar(1);" ><img src="_images/area_representante/fechar_msg_sucess.gif"/></a>');
                    jQuery('#section.esqueci_minha_senha #content #esqueceu').css('display','none');

               	}

			});
		}
         return false;
        });

 //////////////////////////////////VALIDAÇÃO AREA DO REPRESENTANTE/////////////////////////////////////////////
   	//QUANDO O FOCO ESTIVER NO CAMPO TEXT
   jQuery('#section.area_representante #content form.form_area_representante input.text').each(function(i){
		jQuery(this).removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected'); });
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});
	});


    //QUANDO O FOCO ESTIVER NO CAMPO TEXTAREA
	jQuery('#section.area_representante #content form.form_area_representante textarea').each(function(i){
		jQuery(".errortextarea").removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected')});
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});

	});

    //MÁSCARA PARA TELEFONE
    jQuery('#section.area_representante #content form.form_area_representante input.text.data').mask(" 99/99/9999",{placeholder:" "});
    jQuery('#section.area_representante #content form.form_area_representante input.text.data_saida').mask(" 99/99/9999",{placeholder:" "});
    jQuery('#section.area_representante #content form.form_area_representante input.text.fone').mask("(99) 9999-9999",{placeholder:" "});
    jQuery('#section.area_representante #content form.form_area_representante input.text.fax').mask("(99) 9999-9999",{placeholder:" "});
    jQuery('#section.area_representante #content form.form_area_representante input.text.cep_cliente').mask(" 99.999-999",{placeholder:" "});
    jQuery('#section.area_representante #content form.form_area_representante input.text.cep_cobranca').mask(" 99.999-999",{placeholder:" "});
    jQuery('#section.area_representante #content form.form_area_representante input.text.cep_entrega').mask(" 99.999-999",{placeholder:" "});


    //AO CLICAR NO BOTÃO OK
    jQuery('#section.area_representante #content form').submit(function() {

        //VERIFICA SE OS DADOS NOS CAMPOS SÃO VÁLIDOS
		var hasError = false;
		var msg = '';
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var txtReg = /^[a-z A-ZãÃáÁàÀêÊéÉèÈíÍìÌôÔõÕóÓòÒúÚùÙûÛçÇ\.]+$/;
		var nmbReg = /^\d+$/;
		var phoneReg = /^(\(\d{2}\)|\d{2})?\s?\d{4}-?\d{4}$/;
		//var cnpjReg = /^(\d{2})\.(\d{3})\.(\d{3})\/(\d{4})-(\d{2})$/;

	   	//CHECA TODOS OS CAMPOS TEXT NO FORMULÁRIO
		jQuery('#section.area_representante #content form.form_area_representante input.text').each(function(i){
			jQuery(this).removeClass('selected');
			jQuery(this).removeClass('error');

			//VERIFICA SE ALGUM CAMPO ESTÁ EM BRANCO,SE ESTIVER,O TEXT FICA VERMELHO
			if(!jQuery(this).val() || jQuery(this).val() == "R$" ) {
				jQuery(this).addClass('error');
				hasError = true;
			}
		});

        if(jQuery('form.logado .verifica_login').val() == "true" ){


        if(hasError == false) {
			//Variables for values
			var data = jQuery('#section.area_representante #content form.form_area_representante input.text.data');
			var n_pedido = jQuery('#section.area_representante #content form.form_area_representante input.text.n_pedido');
			var nome_cod_repres = jQuery('#section.area_representante #content form.form_area_representante input.text.nome_cod_repres');
			var n_pedido_fab = jQuery('#section.area_representante #content form.form_area_representante input.text.n_pedido_fab');
            var fantasia = jQuery('#section.area_representante #content form.form_area_representante input.text.fantasia');
			var contato = jQuery('#section.area_representante #content form.form_area_representante input.text.contato');
			var cargo = jQuery('#section.area_representante #content form.form_area_representante input.text.cargo');
			var razao = jQuery('#section.area_representante #content form.form_area_representante input.text.razao');
            var fone = jQuery('#section.area_representante #content form.form_area_representante input.text.fone');
			var fax = jQuery('#section.area_representante #content form.form_area_representante input.text.fax');
			var cnpj_cpf = jQuery('#section.area_representante #content form.form_area_representante input.text.cnpj_cpf');
			var insc = jQuery('#section.area_representante #content form.form_area_representante input.text1.insc');
            var rua_av_cliente = jQuery('#section.area_representante #content form.form_area_representante input.text.rua_av_cliente');
			var bairro_cliente = jQuery('#section.area_representante #content form.form_area_representante input.text.bairro_cliente');
			var cep_cliente = jQuery('#section.area_representante #content form.form_area_representante input.text.cep_cliente');
			var cidade_cliente = jQuery('#section.area_representante #content form.form_area_representante input.text.cidade_cliente');
            var estado_cliente = jQuery('#section.area_representante #content form.form_area_representante input.text.estado_cliente');
			var email = jQuery('#section.area_representante #content form.form_area_representante input.text.email');
			var home_page = jQuery('#section.area_representante #content form.form_area_representante input.text1.home_page');
			var obs = jQuery('#section.area_representante #content form.form_area_representante textarea#obs');
            var desconto = jQuery('#section.area_representante #content form.form_area_representante input#desconto');
            var valor_total = jQuery('#section.area_representante #content form.form_area_representante input#valor_total');
            var cond_pgto = jQuery('#section.area_representante #content form.form_area_representante input.text.cond_pgto');
			var dados_deposito = jQuery('#section.area_representante #content form.form_area_representante input.text.dados_deposito');
			var data_saida = jQuery('#section.area_representante #content form.form_area_representante input.text.data_saida');
			var peso = jQuery('#section.area_representante #content form.form_area_representante input.text.peso');
            var rua_av_cobranca = jQuery('#section.area_representante #content form.form_area_representante input.text.rua_av_cobranca');
			var bairro_cobranca = jQuery('#section.area_representante #content form.form_area_representante input.text.bairro_cobranca');
			var cep_cobranca = jQuery('#section.area_representante #content form.form_area_representante input.text.cep_cobranca');
			var cidade_cobranca = jQuery('#section.area_representante #content form.form_area_representante input.text.cidade_cobranca');
            var estado_cobranca = jQuery('#section.area_representante #content form.form_area_representante input.text.estado_cobranca');
            var rua_av_entrega = jQuery('#section.area_representante #content form.form_area_representante input.text.rua_av_entrega');
			var bairro_entrega = jQuery('#section.area_representante #content form.form_area_representante input.text.bairro_entrega');
			var cep_entrega = jQuery('#section.area_representante #content form.form_area_representante input.text.cep_entrega');
			var cidade_entrega = jQuery('#section.area_representante #content form.form_area_representante input.text.cidade_entrega');
            var estado_entrega = jQuery('#section.area_representante #content form.form_area_representante input.text.estado_entrega');
            var complemento = jQuery('#section.area_representante #content form.form_area_representante input#complemento_valor');


            //VALIDAÇÕES
			if(!emailReg.test(jQuery(email).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este email não é válido!</p>';
				jQuery(email).addClass('error');
			}
            if(!nmbReg.test(jQuery(n_pedido).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este número de pedido não é válido!</p>';
				jQuery(n_pedido).addClass('error');
			}
            if(!nmbReg.test(jQuery(n_pedido_fab).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este número de pedido da fábrica não é válido!</p>';
				jQuery(n_pedido_fab).addClass('error');
			}
            if(!txtReg.test(jQuery(contato).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este contato não é válido!</p>';
				jQuery(contato).addClass('error');
			}
            if(!txtReg.test(jQuery(cargo).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este cargo não é válido!</p>';
				jQuery(cargo).addClass('error');
			}
            if(!nmbReg.test(jQuery(cnpj_cpf).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este CNPJ/CPF não é válido!</p>';
				jQuery(cnpj_cpf).addClass('error');
			}
            if(!txtReg.test(jQuery(bairro_cliente).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este bairro não é válido!</p>';
				jQuery(bairro_cliente).addClass('error');
			}
            if(!txtReg.test(jQuery(cidade_cliente).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Esta cidade não é válida!</p>';
				jQuery(cidade_cliente).addClass('error');
			}
            if(!txtReg.test(jQuery(estado_cliente).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este estado não é válido!</p>';
				jQuery(estado_cliente).addClass('error');
			}
            if(!txtReg.test(jQuery(bairro_cobranca).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este bairro não é válido!</p>';
				jQuery(bairro_cobranca).addClass('error');
			}
            if(!txtReg.test(jQuery(cidade_cobranca).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Esta cidade não é válida!</p>';
				jQuery(cidade_cobranca).addClass('error');
			}
            if(!txtReg.test(jQuery(estado_cobranca).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este estado não é válido!</p>';
				jQuery(estado_cobranca).addClass('error');
			}
            if(!txtReg.test(jQuery(bairro_entrega).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este bairro não é válido!</p>';
				jQuery(bairro_entrega).addClass('error');
			}
            if(!txtReg.test(jQuery(cidade_entrega).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Esta cidade não é válida!</p>';
				jQuery(cidade_entrega).addClass('error');
			}
            if(!txtReg.test(jQuery(estado_entrega).val())) { //VALIDAÇÃO DO EMAIL
				hasError = true;
				msg = '<p>Este estado não é válido!</p>';
				jQuery(estado_entrega).addClass('error');
			}


		}

        }

	   //SE ESTIVER ALGUM CAMPO ERRADO IRÁ MOSTRAR AS MENSAGENS DE ERRO
		if(hasError == true) {
			if(msg == '') {
				jQuery('#section.area_representante #content .message_box .error').fadeIn('fast').html('<p><strong>Algo está errado!</strong> Confira os campos em vermelho e preencha-os novamente.</p><a id="fecha_error" href="javascript:fechar(1);" ><img src="_images/area_representante/fechar_msg_error.gif"/></a>');
			} else {
				jQuery('#section.area_representante #content .message_box .error').fadeIn('fast').html(msg).css('background-position','0px 0px');
			}
        }
         else {
         	if(jQuery('form.logado .verifica_login').val() == "true"  ){
			jQuery('#section.area_representante #content .message_box .sucess').ajaxStart(function(){jQuery(this).fadeIn('fast').html('<p>Aguarde...</p>')});

              var itens = '';
              var quantidade = '';
              var descricao = '';
              var preco_unitario = '';
              var preco_total = '';
              var cont = 1;
              var qtd_linhas = jQuery('#qtd_produtos').val();
              while(cont<=qtd_linhas){
                itens += "&item_"+cont+"="+jQuery('.item_'+cont).val();
                quantidade += "&quant_"+cont+"="+jQuery('.quant_'+cont).val();
                descricao += "&descricao_"+cont+"="+jQuery('.descricao_'+cont).val();
                preco_unitario += "&preco_un_"+cont+"="+jQuery('.preco_un_'+cont).val();
                preco_total += "&preco_total_"+cont+"="+jQuery('.preco_total_'+cont).val();
                cont++;
              }
              if (jQuery(complemento).val() == 'outro'){
		        complemento = jQuery('#section.area_representante #content form.form_area_representante input.text1.especifico');
              }

            jQuery.ajax({
				type: "POST",
				url: "_arearepresentante.php",
				data: "&data="+jQuery(data).val()+"&n_pedido="+jQuery(n_pedido).val()+"&nome_cod_repres="+jQuery(nome_cod_repres).val()+"&n_pedido_fab="+jQuery(n_pedido_fab).val()+"&fantasia="+jQuery(fantasia).val()+"&contato="+jQuery(contato).val()+"&cargo="+jQuery(cargo).val()+"&razao="+jQuery(razao).val()+"&fone="+jQuery(fone).val()+
				"&fax="+jQuery(fax).val()+"&cnpj_cpf="+jQuery(cnpj_cpf).val()+"&insc="+jQuery(insc).val()+"&rua_av_cliente="+jQuery(rua_av_cliente).val()+"&bairro_cliente="+jQuery(bairro_cliente).val()+"&cep_cliente="+jQuery(cep_cliente).val()+"&cidade_cliente="+jQuery(cidade_cliente).val()+"&estado_cliente="+jQuery(estado_cliente).val()+
                "&email="+jQuery(email).val()+"&home_page="+jQuery(home_page).val()+"&obs="+jQuery(obs).val()+"&desconto="+jQuery(desconto).val()+"&valor_total="+jQuery(valor_total).val()+
                "&cond_pgto="+jQuery(cond_pgto).val()+"&dados_deposito="+jQuery(dados_deposito).val()+"&data_saida="+jQuery(data_saida).val()+"&peso="+jQuery(peso).val()+"&rua_av_cobranca="+jQuery(rua_av_cobranca).val()+"&bairro_cobranca="+jQuery(bairro_cobranca).val()+"&cep_cobranca="+jQuery(cep_cobranca).val()+
                "&cidade_cobranca="+jQuery(cidade_cobranca).val()+"&estado_cobranca="+jQuery(estado_cobranca).val()+"&rua_av_entrega="+jQuery(rua_av_entrega).val()+"&bairro_entrega="+jQuery(bairro_entrega).val()+"&cep_entrega="+jQuery(cep_entrega).val()+"&cidade_entrega="+jQuery(cidade_entrega).val()+"&estado_entrega="+jQuery(estado_entrega).val()+
                "&complemento_valor="+jQuery(complemento).val()+itens+quantidade+descricao+preco_unitario+preco_total,
				success: function(){
					jQuery('#section.area_representante #content .message_box .sucess').fadeIn('fast').html('<p><strong>Sucesso!</strong> Você foi cadastrado corretamente.</p><a id="fecha_sucess" href="javascript:fechar(3);" ><img src="_images/area_representante/fechar_msg_sucess.gif"/></a>');
                    jQuery('#section.area_representante #content form.form_area_representante').css('display','none');
				}
			});
            }
            else{
               jQuery('#section.area_representante #content #login').submit();


            }
		}


        return false;

        });

//////////////////////////////////VALIDAÇÃO FALE CONOSCO/////////////////////////////////////////////
  	//QUANDO O FOCO ESTIVER NO CAMPO TEXT
   jQuery('#section.fale_conosco #content form.form_fale_conosco input.text').each(function(i){
		jQuery(this).removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected')});
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});
	});


    //QUANDO O FOCO ESTIVER NO CAMPO TEXTAREA
	jQuery('#section.fale_conosco #content form.form_fale_conosco textarea').each(function(i){
		jQuery(".errortextarea").removeClass('error');
		jQuery(this).focus(function() {jQuery(this).addClass('selected')});
		jQuery(this).blur(function() {jQuery(this).removeClass('selected').removeClass('error')});

	});



    //AO CLICAR NO BOTÃO OK
   jQuery('#section.fale_conosco #content form.form_fale_conosco').submit(function() {

        //VERIFICA SE OS DADOS NOS CAMPOS SÃO VÁLIDOS
		var hasError = false;
		var msg = '';
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var txtReg = /^[a-z A-ZãÃáÁàÀêÊéÉèÈíÍìÌôÔõÕóÓòÒúÚùÙûÛçÇ\.]+$/;
		var nmbReg = /^\d+$/;
		var phoneReg = /^(\(\d{2}\)|\d{2})?\s?\d{4}-?\d{4}$/;
		var cnpjReg = /^(\d{2})\.(\d{3})\.(\d{3})\/(\d{4})-(\d{2})$/;

	   	//CHECA TODOS OS CAMPOS TEXT NO FORMULÁRIO
		jQuery('#section.fale_conosco #content form.form_fale_conosco input.text').each(function(i){
			jQuery(this).removeClass('selected');
			jQuery(this).removeClass('error');

			//VERIFICA SE ALGUM CAMPO ESTÁ EM BRANCO,SE ESTIVER,O TEXT FICA VERMELHO
			if(!jQuery(this).val() ) {
				jQuery(this).addClass('error');
				hasError = true;
			}

           });

        //CHECA TODOS OS CAMPOS TEXTAREA NO FORMULÁRIO
        jQuery('#section.fale_conosco #content form.form_fale_conosco textarea').each(function(i){
            //Reset classes
			jQuery(this).removeClass('selected');
			jQuery(this).removeClass('error');

			//VERIFICA SE ALGUM CAMPO ESTÁ EM BRANCO,SE ESTIVER,O TEXTAREA FICA VERMELHO
			if(!jQuery(this).val()) {
				jQuery('#section.fale_conosco #content form.form_fale_conosco textarea').addClass('error');
				hasError = true;
			}

           });

         if(hasError == false) {
			//Variables for values
			var nome = jQuery('#section.fale_conosco #content form.form_fale_conosco input#nome');
			var email = jQuery('#section.fale_conosco #content form.form_fale_conosco input#email');
			var cidade = jQuery('#section.fale_conosco #content form.form_fale_conosco input#cidade');
			var estado = jQuery('#section.fale_conosco #content form.form_fale_conosco select#estado');
			var assunto = jQuery('#section.fale_conosco #content form.form_fale_conosco select#assunto');
			var msg = jQuery('#section.fale_conosco #content form.form_fale_conosco textarea#msg');


            //VALIDAÇÕES
			if(!txtReg.test(jQuery(nome).val())) { //Name validation
				hasError = true;
				msg = "<p>Este nome não é válido</p>";
				jQuery(nome).addClass('error');
			}
			if(!emailReg.test(jQuery(email).val())) { //Email validation
				hasError = true;
				msg = "<p>Este email não é válido</p>";
				jQuery(email).addClass('error');
			}
			if(!txtReg.test(jQuery(cidade).val())) { //Cidade validation
				hasError = true;
				msg = "<p>Esta cidade não é válida</p>";
				jQuery(cidade).addClass('error');
			}


		}

       //SE ESTIVER ALGUM CAMPO ERRADO IRÁ MOSTRAR AS MENSAGENS DE ERRO
		if(hasError == true) {
			if(msg == '') {
				jQuery('#section.fale_conosco #content .message_box .error').fadeIn('fast').html('<p>Confira os campos em vermelho!</p><a id="fecha_error" href="javascript:fechar(1);" ><img src="_images/area_representante/fechar_msg_error.gif"/></a>');
			} else {
				jQuery('#section.fale_conosco #content .message_box .error').fadeIn('fast').html(msg);
			}

            }
        //ESTANDO TUDO CERTO IRÁ ENVIAR PARA O BANCO DE DADOS E MOSTRAR A MENSAGEM DE CADASTRADO COM SUCESSO
		 else {
			jQuery('#section.fale_conosco #content .message_box .sucess').ajaxStart(function(){jQuery(this).fadeIn('fast').html('<p>Aguarde...</p>')});

			jQuery.ajax({
				type: "POST",
				url: "_faleconosco.php",
				data: "nome="+jQuery(nome).val()+"&estado="+jQuery(estado).val()+"&email="+jQuery(email).val()+"&assunto="+jQuery(assunto).val()+
				"&cidade="+jQuery(cidade).val()+"&msg="+jQuery(msg).val(),
				success: function(){
					jQuery('#section.fale_conosco #content .message_box .sucess').fadeIn('fast').html('<p>Mensagem enviada com sucesso!</p><a id="fecha_sucess" href="javascript:fechar(4);"><img src="_images/area_representante/fechar_msg_sucess.gif"/></a>');
                    jQuery('#section.fale_conosco #content form.form_fale_conosco').css('display','none');
				}
			});
		}


        return false;

        });

});




