var opt_no_frames = false;
var opt_integrated_mode = false;
function locale_oC(f1, f2)
{
	if ("default" == f2.login_locale.value)
		return;
	f2.login_name.value = f1.login_name.value;
	f2.submit();
}

function login_oC(f1, f2)
{
	if ((f1.login_name.value == "") || (f2.passwd.value == "")) {
		alert("Entre com seu login e senha.");
		f1.login_name.focus();
		f1.login_name.select();
		return false;
	}
	f2.login_name.value = f1.login_name.value;
	f2.submit();
	return false;
}

function setFocus()
{
	if (o = document.forms[0].login_name) {
		o.focus();
		o.select();
	}
}

function get_password_oC(f1, f2)
{
	f1.login_name.value = f2.login_name.value;
	f1.submit();
}
function chequea_login(formulario){
	if(formulario._user.value == "" || formulario._pass.value == ""){
		alert("Entre com seu login e senha.");
		return false;
	}
	return true;
}
function chequea_login_central(formulario){
	if(formulario.email.value == "" || formulario.senha.value == ""){
		alert("Entre com seu login e senha.");
		return false;
	}
	return true;
}

if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]===obj){
				return i;
			}
		}
		return -1;
	}
}

document.getElementsByClassName = function(className, parentElement) {
	if (typeof parentElement == 'string'){
    	parentElement = document.getElementById(parentElement);
  	}
	else if (typeof parentElement != 'object' || typeof parentElement.tagName != 'string'){
    	parentElement = document.body;
  	}
  	var children = parentElement.getElementsByTagName('*');
  	var re = new RegExp('\\b' + className + '\\b');
  	var el, elements = [];
  	var i = 0;
  	while ( (el = children[i++]) ){
    	if ( el.className && re.test(el.className)){
      		elements.push(el);
    	}
  	}
  	return elements;
} 

function mostra(aba, div){
	var array_abas = new Array("abas-webmail", "abas-painel", "abas-central");
	var array_divs = new Array("webmail", "painel", "central");
	var aba = document.getElementById(aba);
	var div = document.getElementById(div);
	for(var i = 0; i< aba.childNodes.length; i++){
		if(aba.childNodes[i].tagName == "A"){
			aba.childNodes[i].style.color = "#FFF";
		}
	}
	if(aba.id == "abas-webmail"){
		aba.style.background = "#7ED1F3 url('../f/img/ly/acesso_tpe.gif') no-repeat left top";
	}
	else if(aba.id == "abas-painel"){
		aba.style.background = "#7ED1F3 url('../f/img/ly/acesso_tpd.gif') no-repeat right top";
	}
	else{
		aba.style.backgroundColor = "#7ED1F3";
	}
	aba.style.border = "1px solid #FFF";
	if(aba.id == "abas-painel"){
		aba.style.borderRight = "none";
	}
	else if(aba.id == "abas-webmail"){
		aba.style.borderLeft = "none";
	}
	aba.style.borderBottom = "none";
	div.className = "";
	for(var i = 0; i < array_abas.length; i++){
		if(array_abas[i] !== aba.id){
			document.getElementById(array_abas[i]).style.backgroundColor = "transparent";
			document.getElementById(array_abas[i]).style.backgroundImage = "none";
			document.getElementById(array_abas[i]).style.border = "none";
			for(var j = 0; j< document.getElementById(array_abas[i]).childNodes.length; j++){
				if(document.getElementById(array_abas[i]).childNodes[j].tagName == "A"){
					document.getElementById(array_abas[i]).childNodes[j].style.color = "#1BBCF0";
				}
			}
		}
	}
	for(var i = 0; i < array_divs.length; i++){
		if(array_divs[i] !== div.id){
			document.getElementById(array_divs[i]).className = "oculto";
		}
	}
}


function preenche_select(campo_origem, campo_destino, array_determinante){
	campo_destino = document.getElementById(campo_destino);
	campo_destino.length = 0;
	var seleccionado = campo_origem.options[campo_origem.selectedIndex].value;
	for(var i = 0; i < array_determinante[seleccionado].length; i++){
		campo_destino.options[i] = new Option( array_determinante[seleccionado][i].nome, array_determinante[seleccionado][i].codigo);
	}
}

function exibe_plano(){
	var atual = "t"+document.getElementById('hospedagem').value;
	if(atual){
		document.getElementById(atual).style.visibility='visible';
		document.getElementById('hospedagem').setAttribute("onchange", "document.getElementById('"+atual+"').style.visibility='hidden'; calcula_valor(this, precos);");
	}
}

function mostra_detalhes(tabela, botao){
	var tabela = document.getElementById(tabela);
	var filas = tabela.rows;
	var clase;
		var a = 0
	if(botao.innerHTML == "+ detalhes"){
		for(var i = 0; i < filas.length; i++){
			clase = filas[i].className;
			clase = clase.replace(" oculto", " visible");
			clase = clase.replace(" zebra", "");
			filas[i].className = clase;
			if(a++%2 !== 0){
				filas[i].className = clase+" zebra";
			}
		}
		botao.innerHTML = "- detalhes";
	}
	else{
		for(var i = 0; i < filas.length; i++){
			clase = filas[i].className;
			clase = clase.replace(" visible", " oculto");
			clase = clase.replace(" zebra", "");
			filas[i].className = clase;
			if(clase.indexOf(" oculto") == -1 && a++%2 !== 0){
				filas[i].className = clase+" zebra";
			}
		}
		botao.innerHTML = "+ detalhes";
	}
}

var ajaxObj;
function createXMLHttp() {
	if (typeof XMLHttpRequest != 'undefined')
		return new XMLHttpRequest();
	else if (window.ActiveXObject) {
		var avers = ["Microsoft.XMLHttp", "MSXML2.XMLHttp", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.7.0"];
		for (var i = avers.length -1; i >= 0; i--) {
			try {
				var httpObj = new ActiveXObject(avers[i]);
				return httpObj;
			} catch(e) {}
		}
	}
	throw new Error('XMLHttp (AJAX) not supported');
}

function confere_disp_capa(url, comparacao){
	ajaxObj = createXMLHttp();
	ajaxObj.open("GET", url, true);
	ajaxObj.onreadystatechange =  function(){ 
		if(ajaxObj.readyState == 4){
			var cType = ajaxObj.getResponseHeader("Content-Type")
			if(cType == "text/plain"){
				conteudo = ajaxObj.responseText;
				var condicional = conteudo+comparacao;
				if(eval(condicional)){
					if(comparacao == " > 0"){
						var parag = document.getElementById("indisp");
						if(parag){
							parag.setAttribute("id", "disp");
							parag.innerHTML = "(disponível)";	
							clearInterval(intervalo_disp);	
							intervalo_disp = setInterval("confere_disp_capa('"+server_st+"ajax/confere-disp-capa.php', ' == 0')", 5000);									
						}						
					}
					else if(comparacao == " == 0"){
						var parag = document.getElementById("disp");
						if(parag){
							parag.setAttribute("id", "indisp");
							parag.innerHTML = "(indisponível)";	
							clearInterval(intervalo_disp);	
							intervalo_disp = setInterval("confere_disp_capa('"+server_st+"ajax/confere-disp-capa.php', ' > 0')", 5000);																		
						}													
					}
				}
			}
		}
	}
	ajaxObj.send(null);
}