var httpRequestObj;


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;
}


/* 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 Enderecos_Show(cidade, link) {
	Enderecos_Hide();

	link.className = "sel";

	document.getElementById(cidade).style.display = "block";
}
function Enderecos_Hide() {
	document.getElementById("lkBlumenau").className = "";
	document.getElementById("lkCuritiba").className = "";
	document.getElementById("lkSaoPaulo").className = "";

	document.getElementById("Blumenau").style.display = "none";
	document.getElementById("Curitiba").style.display = "none";
	document.getElementById("SaoPaulo").style.display = "none";
}

function Produtos_Listagem_Titulo(link) {
	document.getElementById("tituloListagemProdutos").innerHTML = link.title;
}
function Produtos_Listagem_Titulo_Hide() {
	document.getElementById("tituloListagemProdutos").innerHTML = "&nbsp;";
}







function httpRequestClass() {

	this.req = null;
	this.XMLHttpFactories = [
		function () {return new XMLHttpRequest()},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	];

	this.sendRequest = function(url, callback, postData) {
		this.req = this.createXMLHTTPObject();
		if (!this.req)
			return;
		var method = (postData) ? "POST" : "GET";
		this.req.open(method,url,true);
		this.req.setRequestHeader('User-Agent','XMLHTTP/1.0');
		if (postData)
			this.req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		this.req.onreadystatechange = function () {
			if (httpRequestObj.req.readyState != 4)
				return;
			if (httpRequestObj.req.status != 200 && httpRequestObj.status != 304) {
				return;
			}
			callback(httpRequestObj.req);
		}
		if (this.req.readyState == 4)
			return;
		this.req.send(postData);
	}
	this.createXMLHTTPObject = function() {
		var xmlhttp = false;
		for (var i=0;i< this.XMLHttpFactories.length;i++) {
			try {
				xmlhttp = this.XMLHttpFactories[i]();
			}
			catch (e) {
				continue;
			}
		}
		return xmlhttp;
	}
}