function executaScripts(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);
                        novo = document.createElement("script");
						$("body").append("<div id='scriptsResponse'></div>")
						$("#scriptsResponse").html("<script>" + eval(codigo) + "</script>");
						$("#scriptsResponse").remove();						
						
                }
        }
}

function alterarImagem(id,imagem) {
	$('#fotoAmpliada').html('<a name="'+imagem+'" class="jqzoom" href="imagens/produtos/'+id+'/'+imagem+'-1500.jpg"><img src="imagens/produtos/'+id+'/'+imagem+'-415.jpg" alt="" /></a>');
	
	
	jQuery(function() {
		var options4 = {
			zoomWidth: 440,
			zoomHeight: 277,
			title : false
			}
		jQuery(".jqzoom").jqzoom(options4);
	
	});	


	
	}

function chaveOn(varCampo,varChave) {
	if ($("#"+varCampo+"").val() == varChave) {
		$("#"+varCampo+"").val("");
	}
}
function chaveOff(varCampo,varChave) {
	if ($("#"+varCampo+"").val() == "") {
		$("#"+varCampo+"").val(varChave);
	}
}

function alterarSelect(varId1,varId2,varValue1,varValue2) {
	window.parent.$("#"+varId1+"").val(varValue1); 
	window.parent.$("#"+varId2+"").html(varValue2); 	
}


function atualizaSB() {
	window.parent.Shadowbox.init({ skipSetup: true });
	window.parent.Shadowbox.setup();

}

function contato() {
	
    $.ajax({
    type: "POST",
    url: "includes/contato_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formContato").serialize(),
    success:function(response){
		executaScripts(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}


function representantes() {
	$("#resultados").html("<div>Carregando...</div>")
    $.ajax({
    type: "POST",
    url: "includes/representantes_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formRepresentantes").serialize(),
    success:function(response){
		$("#resultados").html(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
}

function selectCidades() {
    $.ajax({
    type: "POST",
    url: "includes/selectLojasCidades.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formLojas").serialize(),
    success:function(response){
		$("#selectCidade").html(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
}

function listaLojas() {
	$("#resultados").html("<div>Carregando...</div>")
    $.ajax({
    type: "POST",
    url: "includes/lojas_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formLojas").serialize(),
    success:function(response){
		$("#resultados").show();
		$("#resultados").html(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
}

var strLink1
strLink1 = '';
function listaLojasDetalhes(id) {
	if (strLink1=='') {
	} else {
		$("#loja"+strLink1+"").removeClass("linkAtivo");
		$("#loja"+strLink1+"").addClass("link");
	}
	strLink1 = id; 
	$("#loja"+id+"").addClass("linkAtivo"); 

	
	
	$("#resultadosDetalhes").html("<div>Carregando...</div>")
    $.ajax({
    type: "POST",
    url: "includes/lojasDetalhes_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: "id=" + id,
    success:function(response){
		$("#resultadosDetalhes").show();
		$("#resultadosDetalhes").html(response);
			Shadowbox.init({ skipSetup: true });
	Shadowbox.setup();

    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
}


function newsletter() {
    $.ajax({
    type: "POST",
    url: "includes/newsletter_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formNewsletter").serialize(),
    success:function(response){
		executaScripts(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}

function indicar() {
	
    $.ajax({
    type: "POST",
    url: "indicar_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formIndicar").serialize(),
    success:function(response){
		executaScripts(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}

function busca() {
	
    $.ajax({
    type: "POST",
    url: "includes/busca_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formBusca").serialize(),
    success:function(response){
		executaScripts(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}

function pedido() {
    $.ajax({
    type: "POST",
    url: "includes/pedido_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formPedido").serialize(),
    success:function(response){
		executaScripts(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}



function loginRepresentante() {
    $.ajax({
    type: "POST",
    url: "includes/login_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formLogin").serialize(),
    success:function(response){
		executaScripts(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}

function adicionarLinhaPedido() {
    $.ajax({
    type: "POST",
    url: "includes/pedido_linha_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: "",
    success:function(response){
		$("#pedidoLinhas").append(response);
		  (function($){
      $(function(){
        $('input:text').setMask();
      }
    );
  })(jQuery);

    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}

function removerLinhaPedido(varLinha) {
	$("#pedidoLinha-"+varLinha+"").remove();
	somarTotal();
	return false;
}
function somarGrade(id) {
	
	qtdeTemp = (parseInt($("#grade33-"+id+"").val())+parseInt($("#grade34-"+id+"").val())+parseInt($("#grade35-"+id+"").val())+parseInt($("#grade36-"+id+"").val())+parseInt($("#grade37-"+id+"").val())+parseInt($("#grade38-"+id+"").val())+parseInt($("#grade39-"+id+"").val())+parseInt($("#grade40-"+id+"").val()))
	$("#qtdeTotal-"+id+"").val(qtdeTemp);
	return false;
}



function procurarEndereco(cep) {
	if (( cep.length > 7 ) && (cep!="_____-___")) {
		$.ajax({
		type: "POST",
		url: "includes/endereco_exe.asp",
		dataType: "html",
		timeout: 60000,
		data: "cep=" + cep,
		success:function(response){				
			executaScripts(response);
		},
		error: function( objAJAXRequest, strError ){
			alert("Erro: " + objAJAXRequest.status);
		}
		});
	  return false;
	  
	}	
}



function somarSubtotal(id) {
    $.ajax({
    type: "POST",
    url: "includes/subtotal_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: "id="+id+"&quantidade="+$("#qtdeTotal-"+id+"").val()+"&preco="+encodeURI($("#preco-"+id+"").val()),
    success:function(response){
		executaScripts(response);
		somarTotal();
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}

function somarTotal(id) {
    $.ajax({
    type: "POST",
    url: "includes/total_exe.asp",
    dataType: "html",
    timeout: 60000,
    data: $("#formPedido").serialize(),
    success:function(response){
		executaScripts(response);
    },
    error: function( objAJAXRequest, strError ){
		alert("Erro: " + objAJAXRequest.status);
    }
    });
  return false;
}
