/*************
Funcoes do Ajax
**************/
// Testa se o browser suporta o XMLHttpRequest.
var xmlhttp;
try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}
//xmlhttp = false;

//testando({vars:{teste:'meuTeste',id:'um ID'},functions:{teste:'Chama Function'}});

/**
* @return void
* @param param: valores:
*               execBefore: uma string que recebera um eval() antes de fazer o pedido pro servidor
*               execAfter: uma string que recebera um eval() depois de fazer o pedido pro servidor
*               method: O metodo que os parametros seerão mandados pro servidor, GET ou POST; DEFAULT = GET.
*               url: a url que sera chamada
*               idTarget: id do elemento HTML que recebera a string que o servidor retornar
* @desc Faz um pedido ao servidor e coloca o resultado (string) em um elemento HTML
* @call ajaxRun({idTarget:"ID_ELEMENTO",url:"URL_CHAMADA",method:"POST",execBefore:"alert('Start')",execAfter:"alert('End')"})
**/

/**
 * lockRequest: TRUE impede que a funcão ajaxRun faca novas requisicoes ao server
**/
var lockRequest = false;
function ajaxRun(param){
    // Testa se lockRequest esta liberado para um novo pedido
    if(lockRequest == false) {
        // Trava lockRequest para que novos pedidos não sejam executados
        lockRequest = true;
        // se execBefore for passado executa a string (comando ou funcao) antes de comecar o pedido pra server
        if(param.execBefore) {
            eval(param.execBefore);
        }
        // Se o metodo não for passado assumir GET
        if(!param.method) {
            param.method = "GET";
        }
        // Transforma a string do metodo para uppercase
        param.method = param.method.toUpperCase();

        // Testa se o browser suporta XMLHttpRequest
        if(xmlhttp) {
            // se suportar abre a conexao
            // Abre conexao
            //xmlhttp.abort();
            xmlhttp.open(param.method,param.url,true);
            xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
            //Funcao para tratamento do retorno
            xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4){
                    //Mostra o HTML recebido
                    retorno = unescape(xmlhttp.responseText.replace(/\+/g," "))

                    // coloca a string retornada pelo servidor (retorno) no elemento HTML com o id == param.idTarget
                    document.getElementById(param.idTarget).innerHTML=retorno;
                    // se execAfter for passado executa a string (comando ou funcao) depois que o retorno foi colocado no elemento

                    // Libera lockRequest para novos pedidos
                    lockRequest = false;
                    if(param.execAfter) {
                        eval(param.execAfter);
                    }
                }
            }
            //Executa
            if(param.method == "POST" && param.strPost) {
                sendPost = param.strPost;
            } else {
                sendPost = null;
            }
            xmlhttp.send(sendPost)
        } else {
            // se nao suportar envia para a url passada
            window.location = param.url.replace("&ajax=1","");
        }
    } else {
        //contentLoading("Por favor, aguarde");
        ;
    }
}

function contentLoading(msg) {
    content = gebi("dvContent");
    if(!msg) msg = "";
    content.innerHTML = '<div id="dvLoading">Carregando... '+msg+'</div>';
}
function comboLoading(display) {
    content = gebi("dvLoading");
    content.style.display = display;
}

function getDetachSmall(name) {
    //alert("Teste");
    //ajaxRun("detachSmall","web/html/detachController.php?detachSmallName="+name+"&ajax=1");
    ajaxRun({idTarget:"detachSmall",url:"web/html/detachController.php?detachSmallName="+name+"&ajax=1"});
}

function styleSwitcher(styleName) {
    styleName = styleName.replace("tab_","");
    var styles = document.getElementsByTagName('link');
    styles[1].href = "web/html/theme/default/styles/style.home."+styleName+".css";
}

function selectMainTab(id) {
    ul = gebi("tabs");
    a = ul.getElementsByTagName("a");
    for(var x=0;x<a.length;x++) {
        a[x].className = "";
        if(a[x].id == id) {
            a[x].className = "selected";
        }
        a[x].blur();
    }
}
function ajaxMainMenu(a) {
    //qs = Querystring(a.href);
    //alert(styles[1]);
    //ajaxRun("dvContent",a.href+"&ajax=1","contentLoading()",false,"styleSwitcher('"+a.id+"')");
    ajaxRun({idTarget:"dvContent",url:a.href+"&ajax=1",execBefore:"contentLoading();selectMainTab('"+a.id+"');styleSwitcher('"+a.id+"')",execAfter:"getSubMenu('"+a.id.replace("tab_","")+"');"});
    return false;
}
function ajaxHomeLink(a) {
    qs = Querystring(a.href);
    //alert(qs['style']);
    //alert(styles[1]);
    //ajaxRun("dvContent",a.href+"&ajax=1","contentLoading()",false,"styleSwitcher('"+a.id+"')");
    ajaxRun({idTarget:"dvContent",url:a.href+"&ajax=1",execBefore:"contentLoading();selectMainTab('tab_"+qs['style']+"');styleSwitcher('"+qs['style']+"')",execAfter:"getSubMenu('"+qs['style']+"');"});
    return false;
}
function ajaxLink(a) {
    qs = Querystring(a.href);
    //alert(qs['style']);
    //alert(styles[1]);
    //ajaxRun("dvContent",a.href+"&ajax=1","contentLoading()",false,"styleSwitcher('"+a.id+"')");
    var selectSubMenu = "";
    if(qs["selectedSubMenu"] != "") {
        selectSubMenu = "selectSubMenu('"+qs["selectedSubMenu"]+"')";
    } else {
        selectSubMenu = "selectSubMenu()";
    }
    ajaxRun({idTarget:"dvContent",url:a.href+"&ajax=1",execBefore:"contentLoading()",execAfter:selectSubMenu});
    return false;
}
function selectSubMenu(id) {
    //alert(id);
    if(id && id != "undefined") {
        subMenu = gebi(id);
        subMenu.parentNode.className = "liSelected";
    } else {
        clearSubMenu("mainSubMenu");
    }
}

function subMenuClick(ele) {
    url = ele.href;
    clearSubMenu("mainSubMenu");
    //alert(ele.parentNode.className);
    ele.parentNode.className = "liSelected";
    ele.blur();
    ajaxRun({idTarget:"dvContent",url:url+"&ajax=1",execBefore:"contentLoading()"});
    return false;
}
function clearSubMenu(id) {
    dv = gebi(id);
    li = document.getElementsByTagName("li");
    for(var x=0;x<li.length;x++) {
        li[x].className = "";
    }
}
function getSubMenu(styleName) {
    //ajaxRun("mainSubMenu","controller.php?action=140&subMenuName="+styleName,"false",false,"getDetachSmall('"+styleName+"');");
    ajaxRun({idTarget:"mainSubMenu",url:"controller.php?action=140&subMenuName="+styleName,execAfter:"getDetachSmall('"+styleName+"')"});
}

/*************
FIM funcoes do Ajax
**************/
function browser () {
	var b = navigator.appName;
	var v = this.version = navigator.appVersion;
	var ua = navigator.userAgent.toLowerCase();
	this.v = parseInt(v);
	this.safari = ua.indexOf("safari")>-1;	// always check for safari & opera
	this.opera = ua.indexOf("opera")>-1;	// before ns or ie
	this.ns = !this.opera && !this.safari && (b=="Netscape");
	this.ie = !this.opera && (b=="Microsoft Internet Explorer");
	this.gecko = ua.indexOf('gecko')>-1; // check for gecko engine
	if (this.ns) {
		this.ns4 = (this.v==4);
		this.ns6 = (this.v>=5);
		this.b = "Netscape";
	}else if (this.ie) {
		this.ie4 = this.ie5 = this.ie55 = this.ie6 = false;
		if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;}
		else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;}
		else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;}
		else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;}
		this.b = "MSIE";
	}else if (this.opera) {
		this.v=parseInt(ua.substr(ua.indexOf("opera")+6,1)); // set opera version
		this.opera6=(this.v>=6);
		this.opera7=(this.v>=7);
		this.b = "Opera";
	}else if (this.safari) {
		this.ns6 = (this.v>=5);	// ns6 compatible correct?
		this.b = "Safari";
	}
	this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false;
	this.def = (this.ie||this.dom);
	this.win32 = ua.indexOf("win")>-1;
	this.mac = ua.indexOf("mac")>-1;
	this.other = (!this.win32 && !this.mac);
	this.supported = (this.def||this.ns4||this.ns6||this.opera)? true:false;
};
/**
* @return obj
* @desc pega a posição do scroll conforme o browser
**/
function getScroll() {
    var scroll = new Array();
    if(document.all) {
        scrollY = "0";
    }
    if(document.documentElement.scrollTop) {
       scroll.y = document.documentElement.scrollTop;
    } else if(document.body.scrollTop) {
        scroll.y = document.body.scrollTop;
    } else if(scrollY) {
        scroll.y = scrollY;
    }
    return scroll;
}



/**
* @return obj
* @param str id: ID do elemento
* @desc Retorna o lemento pelo seu ID. Alias para getElementById() ("G"et"E"lement"B"y"I"d)
**/
function gebi(id) {
    return document.getElementById(id);
}

/**
* @return false (desabilitar o click do mouse)
* @param str origem: Onde o usuario estava quando chamou o chat
* @desc Abre a janela de chat
**/
function openChat(origem,tipo) {
    openChatVoid(origem,tipo);
    return false;
}
function openChatVoid(origem,tipo) {
    //alert(origem);
    if(tipo) {
        tipo = "&tipo="+tipo;
    } else {
    	tipo = "";
	}
    var width = 593;
    var height = 414;
    var left = 50;
    var top = 99;
    url = "http://terrae.ad.adnetwork.com.br/atmo/click/$d=219$ck=1$ct=http://callback.terra.com.br/callbackte/?origem="+origem;
    window.open(url,'janela_chat', 'width='+width+', height='+height+', top='+top+', left='+left+', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, fullscreen=no');
}
function openChatVoid_capa(origem,tipo) {
    //alert(origem);
    if(tipo) {
        tipo = "&tipo="+tipo;
    } else {
    	tipo = "";
	}
    var width = 593;
    var height = 414;
    var left = 50;
    var top = 99;
    url = "http://terrae.ad.adnetwork.com.br/atmo/click/$d=219$ck=1$ct=http://terra2.directtalk.com.br/clientes/custom/Terra%20Empresas/chat/suporte.asp?origem=suporte_online_capa&tipo=s/custom/Terra%20Empresas/chat/suporte.asp";
    window.open(url,'janela_chat', 'width='+width+', height='+height+', top='+top+', left='+left+', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, fullscreen=no');
}
function openMcafeeDemo() {
    var width = 760;
    var height = 410;
    var left = 50;
    var top = 99;
    url = "http://www.terraempresas.com.br/mcafeeDemo/mcafeeDemo.htm";
    window.open(url,'janela_chat', 'width='+width+', height='+height+', top='+top+', left='+left+', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, fullscreen=no');
}

/**
* @retun Array
* @param str qs: QueryString de uma URL
* @desc Tranforma uma querystring de uma URL em um array associativo variavel = valor
**/
function Querystring(qs) {
    this.params = new Object();
    //qs = "http://localhost/svn/www.intelimen.com.br/controller.php?menu=empresa&selectedMenu=empmissao&page=atendimento_solucao";
    if(qs.indexOf("?") > 0) {
        tmp = qs.split("?");
        qs = tmp[1];
        tmp = "";
    }
    args = qs.split("&");
    var name,value
    for(var x = 0 ; x < args.length ; x++) {
        tmp = args[x].split("=");
        name = tmp[0];
        value = tmp[1];
        this.params[name] = value;
    }
    return this.params;
}

/**
* @return false (Para desabilitar o clique do mouse)
* @param str status: show/hide
* @desc Mostra ou esconde as perguntas na tela. Se status == show Mostra. Se status == hide Esconde. Caso o status não seja passado o estado das "perguntas" será invertido.
**/
function showHideQuestions(status) {
    // pega a lista de perguntas
    questions = gebi("ulQuestions");

    // Testa se o Status foi passado
    if(status) {
        // Mostra ou Esconde a lista
        switch(status) {
            case "show":
                questions.style.display = "block";
                questions.style.visibility = "visible";
                break;
            case "hide":
                questions.style.display = "none";
                questions.style.visibility = "hidden";
                break;
        }
    // Caso status não seja passado testar estado atual da lista. Se visivel esconde, se escondido mostra
    } else if(questions.style.display == "none") {
        questions.style.display = "block";
        questions.style.visibility = "visible";
    } else {
        questions.style.display = "none";
        questions.style.visibility = "hidden";
    }
    return false;
}
function showHideBtnVoltar(status) {
    // pega a lista de perguntas
    questions = gebi("dvVoltarHide");

    // Testa se o Status foi passado
    if(status) {
        // Mostra ou Esconde a lista
        switch(status) {
            case "show":
                questions.style.display = "block";
                questions.style.visibility = "visible";
                break;
            case "hide":
                questions.style.display = "none";
                questions.style.visibility = "hidden";
                break;
        }
    // Caso status não seja passado testar estado atual da lista. Se visivel esconde, se escondido mostra
    } else if(questions.style.display == "none") {
        questions.style.display = "block";
        questions.style.visibility = "visible";
    } else {
        questions.style.display = "none";
        questions.style.visibility = "hidden";
    }
    return false;
}
/**
* @return false (Para desabilitar o clique do mouse)
* @param ele: obj. O Elemento "a"
* @desc Mostra a resposta da pergunta selecionada e esconde a lista de perguntas
**/
function fDuvRes(ele) {
    param = Querystring(ele.href);
    target = gebi("dvReply");
    reply = gebi(param["getReply"]);
    target.innerHTML = reply.innerHTML;
    // Faz o link perder o foco para não ficar com uma borda pontilhada no link depois de clicar
    ele.style.color = "#808080";
    ele.parentNode.style.backgroundImage = "url(web/html/theme/default/images/siteFacil/bullet_pb.gif)";
    ele.blur();
    showHideQuestions("hide");
    showHideBtnVoltar("show");
    return false;
}

function duvidaVoltar() {
    showHideQuestions("show");
    showHideBtnVoltar("hide");
    target = gebi("dvReply");
    target.innerHTML = "";
    return false;
}

var callFlashFunction = function(name,stateId) {
    var myMapa = gebi("myMapa");
    browse = new browser();
    if(browse.win32) {
    //if(myMapa.SetVariable) {
        myMapa.SetVariable("_root.stateIdSelected",stateId);
        myMapa.SetVariable("_root.functionName", name);
        myMapa.SetVariable("_root.flag", true);
    //}
    }

}

function selectCombo(id,value) {
    combo = gebi(id);
    for(var x = 0 ; x < combo.options.length ; x++ ) {
        if(combo.options[x].value == value) {
            combo.selectedIndex = combo.options[x].index;
            break;
        }
    }
}

function sendState(stateId) {
	if(stateId == "...") stateId = "0";
    callFlashFunction("selectState",stateId);
	callFlashFunction("selectState",stateId);
	exec ='comboLoading("block");selectCombo("cbStates","'+stateId+'");combo = gebi("cbCities");combo.disabled = true;';
	if(stateId != "...") {
	    ajaxRun({idTarget:"dvCitiesCombo",url:"controller.php?action=136&st_code="+stateId,execBefore:exec,execAfter:"comboLoading('none');"});
	}
}

function sendCity(stateId,cityId) {
    //window.location = "controller.php?action=111&st_code="+stateId+"&cy_code="+cityId;
    //combo = gebi("cbTechs");
    //combo.disabled = true;
    //ajaxRun("dvTechsCombo","controller.php?action=137&cy_code="+cityId,false,true);
    //window.location = "controller.php?action=112&cy_code="+cityId;
    //ajaxRun("dvContent","controller.php?action=112&cy_code="+cityId+"&ajax=1","contentLoading()",false,false);
    if(cityId != 0) {
    	//alert("controller.php?action=112&cy_code="+cityId+"&ajax=1");
    	window.location = "controller.php?action=112&cy_code="+cityId;
        //ajaxRun({idTarget:"dvContent",url:"controller.php?action=112&cy_code="+cityId+"&ajax=1",execBefore:"contentLoading()"});
    }
}

function sendTech(cityId,techId,typeId) {
	if( !typeId ){
        window.location = "controller.php?action=112&cy_code="+cityId+"&th_code="+techId+"#plansType";
	}else{
    	window.location = "controller.php?action=112&cy_code="+cityId+"&th_code="+techId+"&tbl_code="+typeId+"#plansType";
    }
}


function showFaq_old(status) {
    var dvFaq = gebi("dvFaq");
    var scroll = getScroll();
    if(status == "show") {
        dvFaq.style.top = scroll.y + "px";
        dvFaq.style.display = "block";
        dvFaq.style.visibility = "visible";
    } else {
        dvFaq.style.display = "none";
        dvFaq.style.visibility = "hidden";
    }
    return false;
}

function showFaq(status) {
    var dvContentFaq = gebi("dvFaq");
    if(!(dvFaq = gebi("popunderFaq"))) {
        var dvFaq = document.createElement("div");
        dvFaq.id = "popunderFaq";
    }
    dvFaq.innerHTML = dvContentFaq.innerHTML;
    var scroll = getScroll();
    if(status == "show") {
        dvFaq.style.top = scroll.y + 50 + "px";
        document.body.appendChild(dvFaq);
    } else {
        document.body.removeChild(dvFaq);
    }

    return false;
}



function preload(arr) {
    var imgs = new Array();
    var img = new Array();
    var i = 0;
    for(ele in arr) {
        img[i] = new Image;
        img[i].src = arr[ele];
        i++;
        imgs.push(img);
    }
}

function clearClass(a) {
    for(var x=0;x<a.length;x++) {
        a[x].className = "";
    }
}

function animaPanel(a,index,action) {
    clearClass(a);
    if(a[index].className) {
        a[index].className = "selected";
        if(index >= a.length-1) {
            index = 0;
        } else {
            index++;
        }
        if(action == "stop") {
            clearTimeout(timer);
        } else {
            timer = setTimeout("animaPanel(a,"+index+")",5000);
        }
    }

}
function clearHomeLinks(lnks) {
    a = lnks.getElementsByTagName(lnks);
    for(var x=0;x>a.length ;x++) {
        a[x].className = "";
    }
}
function changeDestaqueBg(a,link) {
    var destaque = gebi("dvImgDestaque");
    var lnks = gebi("dvMenuLinks");
    var aa = lnks.getElementsByTagName("a");
    clearClass(aa);
    a.className = "hover";

    //Desabilitando o mouseOver para manter o destaque da capa sempre visivel
    //destaque.style.background = "url("+arrLinks[link]+") 100% 0% no-repeat";
}

function startPlansPanel(id) {
    panel = gebi(id);
    a = panel.getElementsByTagName("a");
    for(var x=0;x<a.length;x++) {
        a[x].obj = a;
        a[x].index = x;
        a[x].onmouseover = function (){
            //alert(this.index);
            animaPanel(this.obj,this.index,'stop');
        }
        a[x].onmouseout = function (){
            //alert(this.index);
            animaPanel(this.obj,this.index);
        }
    }
    animaPanel(a,0);
}
function swapSwfs(ele) {
	var destaque = gebi("dvImgDestaque");
    var lnks = gebi("dvMenuLinks");
    var aa = lnks.getElementsByTagName("a");
    clearClass(aa);
	var swfHospedagem = document.getElementById("novosPlanosHospedagens");
	var swfDominio = document.getElementById("promoDominios");
	swfHospedagem.style.display = "";
	swfDominio.style.display = "none";
	ele.onmouseout = function() {
        var swfHospedagem = document.getElementById("novosPlanosHospedagens");
		var swfDominio = document.getElementById("promoDominios");
		swfHospedagem.style.display = "none";
		swfDominio.style.display = "";
	}
	
}
var timer
var vitCapa;
var countVitCapa;
//var vitRandIndex = 0, vitRandInterval = 1000;
function init() {
	preload(arrLinks);
    if(typeof(vitRand) != "undefined") {
   		timer = setTimeout("startRandomVitrine(0)",0);
	}
	var lnkVitCapa =  document.getElementById("imgLnkDestaqueCapa");
	if(lnkVitCapa) {
		vitCapa = new Array();
		// As imagens tambem devem ser trocadas no /web/html/pages/home/home.php
        vitCapa[0] = "destaque_home_speedy_negocios.jpg";
		vitCapa[1] = "destaque_home_cortinas.jpg";
		countVitCapa = 0;
		setInterval("alternateVitCapa()",10000);
    }
}

function alternateVitCapa() {
    var lnkVitCapa =  document.getElementById("imgLnkDestaqueCapa");
    if(lnkVitCapa.src == "web/html/theme/default/images/home/"+vitCapa[countVitCapa]) {
    	countVitCapa++;
    	return;
	}
    lnkVitCapa.src = "web/html/theme/default/images/home/"+vitCapa[countVitCapa];
    countVitCapa++;
    if(countVitCapa > vitCapa.length-1) {
    	countVitCapa = 0;
	}
}

function startRandomVitrine(vitRandIndex) {

    var aVit = document.getElementById("imgVitrineAcessoHome");
    var imgVit = aVit.getElementsByTagName("img");
    var vitInfos = vitRand[vitRandIndex].split(":");
    imgVit[0].src = "web/html/destaques/full/"+vitInfos[0];
    //alert("web/html/destaques/full/"+vitInfos[0]);
    //alert(vitInfos[1]);
    if(typeof(vitInfos[1]) != "undefined") {
        vitRandInterval = vitInfos[1];
	} else {
		vitRandInterval = 10000;
	}
	
	////////alert(vitInfos[0]);
	
	if(vitInfos[0]=="banner_TE_wifi.jpg"){
		
		document.getElementById("imgVitrineAcessoHome").href='http://www.terra.com.br/wifi';
		document.getElementById("imgVitrineAcessoHome").onclick= function(){
			
		}
		document.getElementById("imgVitrineAcessoHome").target='_blank';
		
	}else{
		
		document.getElementById("imgVitrineAcessoHome").href='#';
		document.getElementById("imgVitrineAcessoHome").onclick= function(){
			openChat("aces.central");
		}
		document.getElementById("imgVitrineAcessoHome").target='';
		
	}

    if(typeof(vitRand[vitRandIndex+1]) != "undefined") {
        vitRandIndex++;
	} else {
        vitRandIndex = 0;
	}
    timer = setTimeout("startRandomVitrine("+vitRandIndex+")",vitRandInterval);
}

var arrLinks = new Array();
    arrLinks["hospedagem"] = "web/html/theme/default/images/home/bg_home_hospedagem.jpg";
    arrLinks["siteFacil"] = "web/html/theme/default/images/home/bg_home_site_facil.jpg";
    arrLinks["acesso"] = "web/html/theme/default/images/home/bg_home_acesso.jpg";
window.onload = init;


if(typeof(showResp) != "undefined" && showResp != false) {
	addEvent(window,'load',showResposta);
}

function addEvent(el,event,func) {
	if (el.addEventListener) {
		el.addEventListener(event, func, false);
	} else {
		el.attachEvent("on"+event, func);
	}
}


function dbug(h){
  var r="";
  for(ef in h){
    r+=ef+" -  ";
  }
  alert(r);
}
function printfire() {
    if (document.createEvent) {
    printfire.args = arguments;
    var ev = document.createEvent("Events");
    ev.initEvent("printfire", false, true);
    dispatchEvent(ev);
}
}

/**
* Teste
**/
function getMousePosition(e) {
    if(typeof(e) == "undefined") {e = window.event;}
    var mouse = new Object();
    mouse.x = e.clientX;
    mouse.y = e.clientY;
    return mouse;
}
function editIt(e,ele) {
    mouse = getMousePosition(e);
    //alert(mouse.x +" - " + mouse.y);
    content = ele.innerHTML;
    txt = document.createElement("textarea");
    txt.value = content;
    txt.style.position = "absolute";
    txt.style.top = mouse.y+"px";
    txt.style.left = mouse.x+"px";
    txt.style.fontColor = ele.style.fontColor;;
    //ele.innerHTML="";
    document.body.appendChild(txt);
    txt.onblur = function() {
        ele.innerHTML = Del(this.value);
        document.body.removeChild(this);
    }
}

function Del(Word) {
    a = Word.indexOf("<");
    b = Word.indexOf(">");
    len = Word.length;
    c = Word.substring(0, a);
    if(b == -1)
    b = a;
    d = Word.substring((b + 1), len);
    Word = c + d;
    tagCheck = Word.indexOf("<");
    if(tagCheck != -1) {
        Word = Del(Word);
    }
    return Word;
}
function verificaVirus(pag, titulo, propiedades) {
    ventana = window.open("http://seguranca.terra.com.br/mcafee/freescan_eula_page.htm","TerraAntivirus","top=0,left=0,scrollbars=yes,width=756px,height=430px,resizeable=no");
}

function startForm(id) {
    //alert(id);
    form = gebi(id);
    inputs = form.getElementsByTagName("input");
    for(var x=0;inputs.length > x; x++ ) {
        inputs[x].oldColor = inputs[x].style.borderColor;
        inputs[x].onfocus = function (){this.style.borderColor="#6199D4"};
        inputs[x].onblur = function (){this.style.borderColor=this.oldColor};
    }
    inputs = form.getElementsByTagName("select");
    for(var x=0;inputs.length > x; x++ ) {
        inputs[x].oldColor = inputs[x].style.borderColor;
        inputs[x].onfocus = function (){this.style.borderColor="#6199D4"};
        inputs[x].onblur = function (){this.style.borderColor=this.oldColor};
    }
    inputs = form.getElementsByTagName("textarea");
    for(var x=0;inputs.length > x; x++ ) {
        inputs[x].oldColor = inputs[x].style.borderColor;
        inputs[x].onfocus = function (){this.style.borderColor="#6199D4"};
        inputs[x].onblur = function (){this.style.borderColor=this.oldColor};
    }
}

function getParceirosList(state) {
    if(state != "0") {
        url = "controller.php?action=146&listState="+state;
        window.location = url;
    }
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=500,left = 162,top = 134');");
}

function openClose(id) {
    var ele = gebi(id);
    if(ele.style.display != "block") {
        ele.style.display = "block";
    } else {
        ele.style.display = "none";
    }
    return false;
}

/**
    Funcoes de consulta de dominios
**/

function getKey(e) {
   if(typeof(e) == "undefined") e = window.event;
   var keyCode = "";
   switch(navigator.appName) {
	   case "Netscape":
		   keyCode = e.which;
		   break;
	   case "Microsoft Internet Explorer":
		   keyCode = e.keyCode;
		   break;
	   default:
		   keyCode = e.which;
		   break;
   }
   var key = "";

   if(keyCode == 0 || keyCode == 8 || keyCode == 13) {
	   //key = "specialKey";
	   if( keyCode == 0 ){
	     key = "specialKey";
	   }
	   if( keyCode == 8 ){
	     key = "backspace";
	   }
	   if( keyCode == 13 ){
	     key = "enter";
	   }
   } else {
	   key = String.fromCharCode(keyCode);
   }
   return key;
}

function maxlength(){
	var textArea = document.getElementById( 'domainname' );
	var errorDiv = document.getElementById( 'error' );
	var errorTLDs = 0;
	var textAreaMaxLength = 100;
	//var textAreaMaxLength = 30;
	var nomesMaxLength;
	var nomesDivisor = 30;
	var nomesRestantes;
	var nomeMaxLength = 63;
	//var nomeMaxLength = 5;
	var caracteresRestantes = textAreaMaxLength;
	var posCaracterAtual = textArea.value.length - 1;
	var caracterAtual = textArea.value.charAt( posCaracterAtual );
	var caracterAnterior = textArea.value.charAt( posCaracterAtual - 1 );
	var realChars = new Array();
	var i = 0;
	var errorCarecInv = 0;
	var rest;
	var cara;
	var nomeString;

	inputs = document.getElementsByTagName('input');
	var checkTest = 0;
	for( var k = 0; k < inputs.length; k++ ){
		input = inputs[k];
		if( input.type == 'checkbox' ){
			if( input.checked == true ){
				checkTest++;
			}
		}
	}

	combo = document.getElementById( 'tdlcombo' );
	var selectTest = 0;
	for( k = 0; k < combo.options.length; k++ ){
		option = combo.options[k];
		if( option.selected == true ){
			selectTest++;
		}
	}

	var TLDTotal = checkTest + selectTest;
	if( TLDTotal != 0 ){
		nomesMaxLength = nomesDivisor/TLDTotal;
		nomesMaxLength = nomesMaxLength.toFixed(0);
	}else{
		nomesMaxLength = nomesDivisor;
		errorTLDs = "<span style='color:#FF0000'>Selecione uma ou mais extensões para pesquisar.</span>";
	}

	nomes = textArea.value.split(/,|;|\s|\n/);
	nomesRestantes = nomesMaxLength - nomes.length;
	if( nomes[nomes.length - 1] == '' ){
		nomesRestantes = nomesRestantes + 1;
	}

	for( var k = 0; k < nomes.length; k++ ){
		if( nomes[k].length > nomeMaxLength ){
			textArea.value = textArea.value.substr( 0, posCaracterAtual );
			errorTLDs = "<span style='color:#FF0000'>Um nome de domínio pode ter no máximo "+nomeMaxLength+" caracteres.</span>";
		}
	}

	seek = new RegExp('[^A-Za-zàáâãéêíóôõúüç0-9\-\n_ ,;]');
	if( caracterAtual.match(seek) != null ){
		textArea.value = textArea.value.substr( 0, posCaracterAtual );
		errorCarecInv = "<br><span style='color:#FF0000'>O caracter "+caracterAtual+" não pode ser usado.</span>";
	}

	for( var k = 0; k < textArea.value.length; k++ ){
		if( textArea.value.charAt( k ) != '\n' && textArea.value.charAt( k ) != ' ' && textArea.value.charAt( k ) != ';' && textArea.value.charAt( k ) != ',' ){
			realChars[i] = textArea.value.charAt( k );
			i++;
		}
	}
	var realLength = realChars.length;
	caracteresRestantes = textAreaMaxLength - realLength;

	if( (caracterAtual == '\n' || caracterAtual == ' ' || caracterAtual == ',' || caracterAtual == ';') && (caracterAnterior == '\n' || caracterAnterior == ' ' || caracterAnterior == ',' || caracterAnterior == ';') ){
		textArea.value = textArea.value.substr( 0, posCaracterAtual );
	}
	if( (caracterAtual == '\n' || caracterAtual == ' ' || caracterAtual == ',' || caracterAtual == ';') && caracteresRestantes == 0 ){
		textArea.value = textArea.value.substr( 0, posCaracterAtual );
	}
	if( (caracterAtual == '\n' || caracterAtual == ' ' || caracterAtual == ',' || caracterAtual == ';') && nomesRestantes == 0 ){
		textArea.value = textArea.value.substr( 0, posCaracterAtual );
	}

	if( nomesRestantes < 0 ){
		textArea.value = textArea.value.substr( 0, posCaracterAtual );
		errorDiv.innerHTML = "<span style='color:#FF0000'>Limite de nomes, selecione menos extensões ou diminua a quantidade de nomes.</span>";
	}
	if( nomesRestantes == 0 ){
		errorDiv.innerHTML = "<span style='color:#FF0000'>Limite de nomes, selecione menos extensões ou diminua a quantidade de nomes.</span>";
	}
	if( caracteresRestantes < 0 ){
		textArea.value = textArea.value.substr( 0, posCaracterAtual );
		errorDiv.innerHTML = "<span style='color:#FF0000'>Limite de caracteres!</span>";
	}
	if( caracteresRestantes == 0 ){
		errorDiv.innerHTML = "<span style='color:#FF0000'>Limite de caracteres!</span>";
	}
	if( caracteresRestantes > 0 && nomesRestantes > 0 ){
		if( caracteresRestantes == 1 ){
			rest = 'Limite de ';
			cara = ' caracter';
		}else{
			rest = 'Limite de ';
			cara = ' caracteres';
		}
		if( nomesRestantes == 1 ){
			nomeString = ' nome.';
		}else{
			nomeString = ' nomes.';
		}
		if( errorTLDs == 0 ){
			if( errorCarecInv == 0 ){
				//errorDiv.innerHTML = rest+"<strong>"+caracteresRestantes+"</strong>"+cara+' e '+"<strong>"+nomesRestantes+"</strong>"+nomeString+'<br>Utilize virgula, ponto e virgula, espaço ou ENTER para separar cada nome.';
				errorDiv.innerHTML = rest+"<strong>"+caracteresRestantes+"</strong>"+cara+' e '+"<strong>"+nomesRestantes+"</strong>"+nomeString;
			}else{
				errorDiv.innerHTML = rest+"<strong>"+caracteresRestantes+"</strong>"+cara+' e '+"<strong>"+nomesRestantes+"</strong>"+nomeString+errorCarecInv;
			}
		}else{
			errorDiv.innerHTML = rest+"<strong>"+caracteresRestantes+"</strong>"+cara+' e '+"<strong>"+nomesRestantes+"</strong>"+nomeString+'<br>'+errorTLDs;
		}
	}

	return false;
}

function doSearch(){
	inputs = document.getElementsByTagName('input');
	checkTest = 0;
	for( var k = 0; k < inputs.length; k++ ){
		input = inputs[k];
		if( input.type == 'checkbox' ){
			if( input.checked == true ){
				checkTest = 1;
			}
		}
	}

	combo = document.getElementById( 'tdlcombo' );
	selectTest = 0;
	for( k = 0; k < combo.options.length; k++ ){
		option = combo.options[k];
		if( option.selected == true ){
			selectTest = 1;
		}
	}

	var error = '';
	if( checkTest == 0 && selectTest == 0 ){
		error = "<span style='color:#FF0000'>Selecione uma ou mais extensões para pesquisar.</span>";
	}

	textArea = document.getElementById( 'domainname' );
	if( textArea.value == '' ){
		if( error != '' ){
			error += "<br>";
		}
		error += "<span style='color:#FF0000'>Digite um ou mais nomes de dominios para pesquisar.</span>";
	}

	if( error == '' ){
		//form = document.getElementById( 'formConsultaDominio' );
		//form.submit();
        return true;
	}else{
		errorDiv = document.getElementById('error');
		errorDiv.innerHTML = error;
        return false;
	}
}

function validaBusca(){
	var obTextAreaDominio = document.getElementById('domainname');
	var error = '';
	if( obTextAreaDominio.value == '' || obTextAreaDominio.value == 'nome1;nome2;nome3;...' ){
		errorDiv = document.getElementById('error');
		error    = "<span style='color:#FF0000'>Digite um domínio válido.</span>";
		errorDiv.innerHTML = error;
		obTextAreaDominio.focus();
		return false;
	}else{
	    return doSearch();
	}
	return false;
}

function selectRow(row) {
    row.st = row.className;
    row.className = row.st+"_hover";
    row.onmouseout = function() {
        row.className = row.st;
    }
}
/**
    /Funcoes de consulta de dominios
**/

function popupSuporte(lnk) {
    var tt = document.getElementById("popupSuporte");
    if(tt) {
        lnk.parentNode.removeChild(tt);
    }
    pp = document.createElement("div");
    pp.style.position = "absolute"
    pp.style.width = "0px";
    pp.style.height = "0px";
    pp.style.left = "165px";
    pp.style.top = "2px";
    browse = new browser();
    if(browse.ie) {
        pp.style.top = "2px";
    }
    if(browse.ns) {
        pp.style.top = "8px";
    }
    if(browse.opera) {
        pp.style.top = "9px";
        pp.style.left = "156px";
    }
    pp.id = "popupSuporte";
    pp.style.zIndex = "9999";
    pp.style.background = "url(/web/html/theme/default/images/home/menu_suporte_hover.gif) 50% no-repeat";
    pp.style.cursor = "pointer";
    pp.onclick = function() {
        openChatVoid_capa("suporte_online_capa","s");
    };
    lnk.parentNode.appendChild(pp);
    //animaIn(pp.id);
    var timmer;
    //pp.onmouseout = function() {
    //    animaOut("popupSuporte");
    //}
    anima.setEle("popupSuporte");
    anima.show();
}
var anima = {
    ele:"",
    timmer:"",
    setEle:function(id) {
        anima.ele = document.getElementById(id);
    },
    show:function() {
        anima.ele.style.left = anima.ele.offsetLeft - 20 + "px";
        anima.ele.style.top = anima.ele.offsetTop - 8 + "px";
        anima.ele.style.width = anima.ele.offsetWidth + 40 + "px";
        anima.ele.style.height = anima.ele.offsetHeight + 16 + "px";
        anima.ele.onmouseout = anima.hide;
        if(anima.ele.offsetWidth <= 170) {
            clearTimeout(anima.timmer);
            anima.timmer = setTimeout("anima.show('"+anima.ele.id+"')",1);
        } else {
            clearTimeout(anima.timmer);
        }
    },
    hide:function() {
        anima.ele.style.left = anima.ele.offsetLeft + 20 + "px";
        anima.ele.style.top = anima.ele.offsetTop + 8 + "px";
        anima.ele.style.width = anima.ele.offsetWidth - 40 + "px";
        anima.ele.style.height = anima.ele.offsetHeight - 16 + "px";
        //alert(anima.ele.offsetWidth);
        if(anima.ele.offsetWidth > 0) {
            clearTimeout(anima.timmer);
            anima.timmer = setTimeout("anima.hide('"+anima.ele.id+"')",1);
        } else {
            clearTimeout(anima.timmer);
        }
    }
}
function animaIn(id) {
    ele = document.getElementById(id);
    ele.style.left = ele.offsetLeft - 5 + "px";
    ele.style.top = ele.offsetTop - 2 + "px";
    ele.style.width = ele.offsetWidth + 10 + "px";
    ele.style.height = ele.offsetHeight + 4 + "px";
    var timmer;
    clearTimeout(timmer);
    if(ele.offsetWidth <= 160) {
        clearTimeout(timmer);
        timmer = setTimeout("animaIn('"+id+"')",1);
    } else {
        clearTimeout(timmer);
    }
}
function animaOut(id) {
    ele = document.getElementById(id);
    ele.style.left = ele.offsetLeft + 5 + "px";
    ele.style.top = ele.offsetTop + 2 + "px";
    ele.style.width = ele.offsetWidth - 10 + "px";
    ele.style.height = ele.offsetHeight - 4 + "px";
    var timmer;
    clearTimeout(timmer);
    if(ele.offsetWidth > 0) {
        timmer = setTimeout("animaOut('"+id+"')",1);
    } else {
        ele.parentNode.removeChild(ele);
        clearTimeout(timmer);
    }
}
function closePopupAlert(ele) {
    var popup = document.getElementById("popupAlert");
    document.body.removeChild(popup);
    var mask = document.getElementById("mask");
    document.body.removeChild(mask);
    document.getElementById("final").style.visibility = "visible";
}
function fechar_publicidade(){document.getElementById("mcafee_banner").style.display ='none';}

function showTip() {
	document.getElementById("ctrlTip").style.display = "block";
}
function hideTip() {
	document.getElementById("ctrlTip").style.display = "none";
}