var URLCep = "http://10.1.1.1/editora-anita-garibaldi/www/cep.aspx";
//var URLCep = "http://www.anitagaribaldi.com.br/versteckt/cep.aspx";


function CacheImagens() {
	cacheArr = new Array(
					"../imagens/topo/menu/menu-contato-h.gif",
					"../imagens/topo/menu/menu-convenios-h.gif",
					"../imagens/topo/menu/menu-horarios-h.gif",
					"../imagens/topo/menu/menu-localizacao-h.gif",
					"../imagens/topo/menu/menu-noticias-h.gif"
					);
	imageCache = new Array();
	
	for (a = 0; a < cacheArr.length; a++) {
		imageCache[a] = new Image();
		imageCache[a].src = cacheArr[a];
	}
}

CacheImagens();


function Janela(e, w, h, p) {
	try {
		param = "";
		if (p != null)
			param = ", " + p;

		centrox = (screen.width / 2) - (w / 2);
		centroy = (screen.height / 2) - (h / 2);

		if (navigator.appName.indexOf("Opera") != -1) {
			test = (screen.height - (screen.height * 0.25));
			centroy = (test / 2) - (h / 2);
		}
		if (navigator.appName.indexOf("Explorer") != -1) {
			w += 20;
		}

		window.open(e.href, '', "left=" + centrox + ", top=" + centroy + ", width=" + w + ", height=" + h + "" + param);

		if (window.event)
			event.returnValue = false;
	}
	catch(e) {
		if (window.event)
			event.returnValue = true;
		
	}
	return false;
}

function ValidarFormulario(Form) {
	Campos = Form.getElementsByTagName("input");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].type == "text" && Campos[a].getAttribute("obrigatorio") != null && Campos[a].value.length == 0) {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	Campos = Form.getElementsByTagName("select");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].getAttribute("obrigatorio") != null && Campos[a].options[Campos[a].selectedIndex].value.length == "") {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	Campos = Form.getElementsByTagName("textarea");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].getAttribute("obrigatorio") != null && Campos[a].value.length == 0) {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	return true;
}

function Campo(obj, objnext) {
	if (obj.value.length == obj.getAttribute("maxlength")) {
		objnext.focus();
	}
}



/* Oculta texto do campo */

function campoFocusValueClass(obj) {

	obj.onfocus = function() {
		if (this.campoFocusValor == null){
			this.campoFocusValor = this.value;
			this.value = "";
		}
		else {
			if (this.value == this.campoFocusValor)
				this.value = "";
		}
	}
	
	obj.onblur = function() {
		if (this.value == ""){
			this.value = this.campoFocusValor;
		}	
	}

}

function formatar_mascara(src, mascara) {
	var campo = src.value.length;
	var saida = mascara.substring(0,1);
	var texto = mascara.substring(campo);
	if(texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}


function CarrinhoList() {
	if ($("#dvCarrinhoList2").is(":hidden")) {
		$("#dvCarrinhoList2").slideDown(250);
	}
	else {
		$("#dvCarrinhoList2").slideUp(250);
	}
}

function produtosHomeClear() {
//	alert($("#dvProdutosHome"));
	//$("#dvProdutosHome").html("Carregando...");
}


function loginEsqueciSenha() {

	var campoEmail = $("#ctl00_ContentPlaceHolder1_campoEmail");

	if (campoEmail.val().length == 0) {
		campoEmail.focus();
		alert("Preencha o campo E-mail para receber a nova senha.");
		return false;
	}

	return true;

}

function findEnderecoCadastro(cep) {
/*

	$.post(URLCep, { cep: cep },
		function(data){
			$("Item", data).each(
					function(){
				alert($("Endereco", this).text());
						$("#ctl00_ContentPlaceHolder1_campoRua").attr("value", $("Endereco", this).text());
						$("#ctl00_ContentPlaceHolder1_campoBairro").attr("value", $("Bairro", this).text());
						$("#ctl00_ContentPlaceHolder1_campoCidade").attr("value", $("Cidade", this).text());
						$("#ctl00_ContentPlaceHolder1_campoNumero").focus();

						$("#ctl00_ContentPlaceHolder1_campoEstado").val($("Estado", this).text());
					}
				);

		}
	);

*/
	$.ajax(
		{
			type: "POST", 
			url: URLCep, 
			data: "cep=" + cep, 
			dataType: "xml", 
			success: function(xml) {



				$("Item", xml).each(
					function(){
						$("#ctl00_ContentPlaceHolder1_campoRua").attr("value", $("Endereco", this).text());
						$("#ctl00_ContentPlaceHolder1_campoBairro").attr("value", $("Bairro", this).text());
						$("#ctl00_ContentPlaceHolder1_campoCidade").attr("value", $("Cidade", this).text());
						$("#ctl00_ContentPlaceHolder1_campoNumero").focus();

						$("#ctl00_ContentPlaceHolder1_campoEstado").val($("Estado", this).text());
					}
				);

			}
		}
	);
/*
*/
}


function PagamentoOpcoesClear() {
//	$("#ctl00_ContentPlaceHolder1_tbFormasPagamento a").removeClass();
}
function PagamentoOpcaoSelect(obj) {

//	obj.className = "sel";
	//$("#ctl00_ContentPlaceHolder1_tbFormasPagamento a").removeClass();
}



function campoFocusValueClass(obj) {
    obj.onfocus = function() {

        if (this.campoFocusValor == null) {
            this.campoFocusValor = this.value;
            this.value = "";
        }
        else {
            if (this.value == this.campoFocusValor)
                this.value = "";
        }
    }

    obj.onblur = function() {
        if (this.value == "") {
            this.value = this.campoFocusValor;
        }
    }
}