﻿function copiadata(x, termino)
{
var y=document.getElementById(x).value;
document.getElementById(termino.toString()).value= y.substr(0,10) + document.getElementById(termino.toString()).value.substr(10,20);
}

//var objAbaAtiva;
function cl(Nomeobj, className) {
    Objx(Nomeobj).className = className;
}
function clFilhos(Nomeobj, className) {
    Nomeobj = Objx(Nomeobj);
    for (var i = 0; i < Nomeobj.childNodes.length; i++) {
        Nomeobj.childNodes[i].className = className;
    } 
}
function err() {
    //var x =0/2;
    //throw new Exception;
}

function Objx(Nomeobj) {
    var obj;
    if (typeof Nomeobj == "string") {
        obj = document.getElementById(Nomeobj);
    } else {
        obj = Nomeobj;
    }
    if (obj == null) { obj = window.parent.document.getElementById(Nomeobj) }
    return obj;
}
function Show(Nomeobj) {
    if (Objx(Nomeobj) != null) {
        Sw(Nomeobj);
        Objx(Nomeobj).style.visibility = 'visible';
    }
}
function Hide(Nomeobj) {
    if (Objx(Nomeobj) != null) {
        Hi(Nomeobj);
        Objx(Nomeobj).style.visibility = 'hidden';
    }
}
function trazpai(xobj) {
    return xobj.parentNode;
}
function ShowModal(path, altura, largura) {
    var retorno = ""
    feautures = "dialogHeight: " + altura + "px; dialogWidth: " + largura + "px; edge: Raised; center: Yes; help: No; resizable: Yes; status: Yes;"
    retorno = window.showModalDialog(path, window, feautures);
    if (retorno == "submit") {
        //    alert("-submit");
        theForm.submit();
    } else if (retorno == "reload") {
        //	    alert("-reload");
        window.location.reload();
        return false;

    } else {
        //    alert("-"+retorno);
        //Para atualizar pagina opener e fechar a pagina filho, colocar na página aberta:window.returnValue='reload';window.close() 
        return false;
    }
}
function ShowModal2(path, altura, largura) {
    var retorno = ""
    feautures = "dialogHeight: " + altura + "px; dialogWidth: " + largura + "px; edge: Raised; center: Yes; help: No; resizable: Yes; status: Yes;"
    window.showModalDialog(path, window, feautures);
}
function ShowWindow(path, altura, largura) {
    var winl = (screen.width - largura) / 2;
    var wint = (screen.height - altura) / 2;
    feautures = "left=" + winl + "px, top=" + wint + "px, Height=" + altura + "px, Width=" + largura + "px, edge=Raised, center=Yes, help=No, resizable=Yes, status=Yes, scrollbars=1";
    window.open(path, 'WINDOW', feautures);
}


function SelecionarTodos(ObjetoPai) {
    var st = Objx(ObjetoPai).getElementsByTagName("INPUT");
    //alert(st);
    //alert(st[1].id.substring(0,2));
    for (var i = 0; i < st.length; i++) {
        if (st[i].type == "checkbox") {
            st[i].checked = 1;
            //alert(st[i].id + "\n"+st[i].innerHTML);
            //S(st[i].id,'Editar','Editar','tbConteudo');
        }
    }
}
function SwHiXY(Nomeobj, poshdl) {
    /*
    var obpai =Objx(Nomeobj);
    var px=0;
    var py = 0;
    for(var i=0;i<6;i++){
    obpai=trazpai(obpai);
    if(obpai.style.position == "absolute")
    {
    if(obpai.style.top.indexOf('%')>0){
    py+= obpai.style.height.substring(0,obpai.style.height.indexOf('px')) * obpai.style.top.substring(0,obpai.style.top.indexOf('%'))/100
    py+= obpai.style.height.substring(0,obpai.style.height.indexOf('px')) * obpai.style.top.substring(0,obpai.style.top.indexOf('%'))/100
    }
    px = ;
    py = obpai.style.top;
    alert(obpai.id+": "+px+" - "+py);
    }
    }
    alert(window.width);
    //alert(Objx(Nomeobj))
    */
    var x = (10 + event.clientX);
    var y = (event.clientY - 5);
    Objx(Nomeobj).style.top = y + "px";
    Objx(Nomeobj).style.left = x + "px";
    Objx(poshdl).value = x + ";" + y;
    SwHi(Nomeobj);
}
function SwHi(Nomeobj) {
    if (Objx(Nomeobj).style.visibility == 'hidden') {
        Sw(Nomeobj);
        Objx(Nomeobj).style.visibility = 'visible';
    } else {
        Hi(Nomeobj);
        Objx(Nomeobj).style.visibility = 'hidden';
    }
}
function SH(link, text1, text2, Nomeobj) {
    if (link != null) {
        if (link.innerHTML == text1) { link.innerHTML = text2; } else { link.innerHTML = text1; }
    }
    if (Objx(Nomeobj).style.display == 'block') {
        Objx(Nomeobj).style.display = 'none';
    } else {
        Objx(Nomeobj).style.display = 'block';
    }
}

function S(Nomeobj) {
    if (Objx(Nomeobj) != null) {
        Objx(Nomeobj).style.display = 'block';
    }
}
function H(Nomeobj) {
    if (Objx(Nomeobj) != null) {
        Objx(Nomeobj).style.display = 'none';
    }
}
function Sw(Nomeobj) {
    Objx(Nomeobj).style.display = 'block';
}
function Hi(Nomeobj) {
    Objx(Nomeobj).style.display = 'none';
}

function ShowDvMd(Nomeobj, w, h) {
    Show('dvProtetor');
    Hide(Nomeobj);

    Objx(Nomeobj).style.top = 0 + "px";
    Objx(Nomeobj).style.left = 0 + "px";
    Objx(Nomeobj).style.width = w + "px";
    Objx(Nomeobj).style.heigth = h + "px";
    
    
    
    var divs = document.getElementsByTagName("div");    
    for (i=0 ;i<divs.length;i++)
    {
        if(divs[i].className == "autocomplete_icon")
        {
            divs[i].style.display = "none";
        }
    }
    window.setTimeout("Show('" + Nomeobj + "');CenterDv('" + Nomeobj + "');", 100);
}
function CenterDv(Nomeobj) {
    var posTop = window.pageYOffset;
    if (posTop == null) {
        posTop = document.documentElement.scrollTop;
    }
    var leftinicial = parseInt(Objx(Nomeobj).style.left.replace("px", ""));

    var winl = ((document.documentElement.offsetWidth - parseInt(Objx(Nomeobj).offsetWidth)) / 2);
    var wint = ((((document.documentElement.clientHeight - parseInt(Objx(Nomeobj).offsetHeight)) / 2) + (posTop)));
    
    var xy = getXY(Objx(Nomeobj));

    if (leftinicial != parseInt(xy[0])) 
    {
        var dvleft = parseInt((parseInt(xy[0])) - leftinicial)
        dvleft = parseInt(winl) - (parseInt(dvleft));
        winl = dvleft;
    }
    Objx(Nomeobj).style.top = wint + "px";
    Objx(Nomeobj).style.left = winl + "px";    
}
function ShowDvM(Nomeobj) {
    ShowDvMd(Nomeobj, 500, 450);
}
function HideDvM(Nomeobj) {
    Hide('dvProtetor');
    var divs = document.getElementsByTagName("div");    
    for (i=0 ;i<divs.length;i++)
    {
        if(divs[i].className == "autocomplete_icon")
        {
            divs[i].style.display = "block";
        }
    }    
    Hide(Nomeobj);
}

function getXY(t) {
    var T = 0, L = 0, e = t;
    do {
        T += e.offsetTop || 0;
        L += e.offsetLeft || 0;
        if (e.style.position == "absolute" && e.offsetParent == document.body) {
            break;
        }
    } while (e = e.offsetParent);
    e = t;
    do {
        if (!window.opera || e.tagName == "BODY") {
            T -= e.scrollTop || 0;
            L -= e.scrollLeft || 0;
        }
    } while (e = e.parentNode);

    return [L, T];
}
function mostra(qtd){
for(var i=0; i<qtd ;i++){
    Objx('twitteroff'+i).style.display = 'block';
    }
}
