﻿function OpenLinkBanner() {
    location.href = '/CETN/WebSite/Curso/Default.aspx';
}

function CallMenu(src) {
    var Page;
    
    switch(src) {
        case 1: Page = 'Sobre/CETN.aspx'; break;
        case 2: Page = 'Noticia-Artigo/,1,,default.aspx'; break;
        case 3: Page = 'Trabalho/Publicado.aspx'; break;
        case 4: Page = 'Contato/FaleConosco.aspx'; break;
        default: Page = 'Home/Default.aspx';
    }
    location.href = '/CETN/WebSite/' + Page;
}

function CallHigh(link) {
    parent.location.href = '/CETN/WebSite/' + link;
}

/*****************************************************
*** Header
*****************************************************/
function Logon() {
    location.href = '/CETN/WebSite/Online/Login.aspx?keyString=' + encryptUrl(document.getElementById('txtLoginMail').value, document.getElementById('txtLoginPassword').value);
}

function KeyPressEnter() {
    keyPressed = event.keyCode;
    if (keyPressed == 13) {
        Logon();
        return false;
    }
}

function OpenFLV(UserHostAddress) {
    var LayerText = "";

    wsBannerClick.CountClick(UserHostAddress, OnCompleteBannerClick, OnTimeOutBannerClick, OnErrorBannerClick);

    LayerText += "<object codeBase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' ";
    LayerText += "width='726' height='436' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' VIEWASTEXT><param name='Movie' value='/CETN/WebSite/App_Structure/Header/Player.swf'><param name='src' value='/CETN/WebSite/App_Structure/Header/Player.swf'><param name='FlashVars' value=''><param name='WMode' value='Transparent'>";

    LayerText += "<param name='Play' value='-1'>";
    LayerText += "<param name='Loop' value='-1'>";
    LayerText += "<param name='Quality' value='High'>";
    LayerText += "<param name='SAlign' value=''>";
    LayerText += "<param name='Menu' value='-1'>";
    LayerText += "<param name='Base' value=''>";
    LayerText += "<param name='_cx' value='15425'>";
    LayerText += "<param name='_cy' value='741'>";
    LayerText += "<param name='DeviceFont' value='0'>";
    LayerText += "<param name='AllowScriptAccess' value=''>";
    LayerText += "<param name='Scale' value='ShowAll'>";
    LayerText += "<param name='EmbedMovie' value='0'>";
    LayerText += "<param name='BGColor' value=''>";
    LayerText += "<param name='SeamlessTabbing' value='1'>";
    LayerText += "<param name='SWRemote' value=''>";
    LayerText += "<param name='MovieData' value=''>";
    LayerText += "<param name='Profile' value='0'>";

    LayerText += "<param name='ProfileAddress' value=''>";
    LayerText += "<param name='ProfilePort' value='0'>";
    LayerText += "<embed type='application/x-shockwave-flash' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' ";
    LayerText += "src='/CETN/WebSite/App_Structure/Header/Player.swf' width='726' height='436' FlashVars='' _cx='15425' _cy='741' wmode='transparent' bgcolor='' Menu='-1' Scale='ShowAll' DeviceFont='0' EmbedMovie='0' SeamlessTabbing='1' Profile='0' ProfilePort='0'></embed></object>";

    document.getElementById('LayerFLV').innerHTML = LayerText;
    document.getElementById('LayerFLV').style.left = (parseInt(document.body.offsetWidth / 2) - 254) + 'px';
    document.getElementById('LayerFLV').style.top = '3px';
    document.getElementById('LayerFLV').style.display = 'block';
}

function CloseFLV() {
    document.getElementById('LayerFLV').innerHTML = '';
    document.getElementById('LayerFLV').style.display = 'none';
}

function OnCompleteBannerClick(value) { }
function OnTimeOutBannerClick(value) { }
function OnErrorBannerClick(value) { }

/*****************************************************
*** On-line
*****************************************************/
function Counter() {
    TypedText = document.getElementById('ctl00_ctl00_body_bodyOnline_txtTextCont').value;
    document.getElementById('divCounter').innerHTML = 500 - TypedText.length;
    VerifyCounter();
}

function VerifyCounter() {
    Remaining = 500 - document.getElementById('ctl00_ctl00_body_bodyOnline_txtTextCont').value.length;
    if (Remaining <= 0) {
        document.getElementById('divCounter').style.color = '#a10000';
        return false;
    } else {
        document.getElementById('divCounter').style.color = '#333333';
        return true;
    }
}

function ValidateDescription(src, args) {
    Remaining = 500 - document.getElementById('ctl00_ctl00_body_bodyOnline_txtTextCont').value.length;
    args.IsValid = (Remaining >= 0);
}

function ScrollEndPage() {
    window.scrollTo(0, 999999999999);
}

/*****************************************************
*** Publicity
*****************************************************/
function ShowPublicity() {
    wsPublicity.Show(OnCompletePublicity, OnTimeOutPublicity, OnErrorPublicity);
}

function OnCompletePublicity(value) {
    document.getElementById('PublicityContent').innerHTML = value;
}
function OnTimeOutPublicity(value) {
    document.getElementById('PublicityContent').style.display = 'none';
}
function OnErrorPublicity(value) {
    document.getElementById('PublicityContent').style.display = 'none';
}

/*****************************************************
*** Font Size
*****************************************************/
var PageFontSize = 3;
function FontSizeMore() {
    if (PageFontSize < 6) {
        PageFontSize += 1;
        document.getElementById('ctl00_body_lblPageText').className = 'PageText' + PageFontSize;
    }
}

function FontSizeLess() {
    if (PageFontSize > 1) {
        PageFontSize -= 1;
        document.getElementById('ctl00_body_lblPageText').className = 'PageText' + PageFontSize;
    }
}

/*****************************************************
*** Send To
*****************************************************/
var BoxWidth;
var BoxHeight;
function SendToFriend(TitleSend, LinkSend) {
    var PageWidth = document.body.offsetWidth;
    var PageHeight = document.getElementById('PageEnd').offsetTop + 20;
    
    document.getElementById('ctl00_body_pnlSendToPage').style.display = 'block';
    document.getElementById('ctl00_body_pnlSendToPage').style.width = PageWidth + 'px';
    document.getElementById('ctl00_body_pnlSendToPage').style.height = PageHeight + 'px';

    document.getElementById('ctl00_body_pnlSendToBox').style.display = 'block';
    BoxWidth = document.getElementById('ctl00_body_pnlSendToBox').offsetWidth;
    BoxHeight = document.getElementById('ctl00_body_pnlSendToBox').offsetHeight;
    document.getElementById('ctl00_body_pnlSendToBox').style.left = parseInt((PageWidth - BoxWidth) / 2) + 'px';
    document.getElementById('ctl00_body_pnlSendToBox').style.top = (parseInt((document.body.offsetHeight - BoxHeight) / 2) + document.documentElement.scrollTop) + 'px';

    while (LinkSend.indexOf("/") >= 0) {
        LinkSend = LinkSend.replace("/", "\\");
    }
    
    document.getElementById('ctl00_body_lblSendToBox').innerHTML = '<iframe id="frmSend" name="frmSend" src="/CETN/WebSite/SendTo/Default.aspx?title=' + escape(TitleSend) + '&link=' + escape(LinkSend) + '" height="258" width="500" frameborder="0" scrolling="no"></iframe>';
}

function SendToClose() {
    document.getElementById('ctl00_body_pnlSendToPage').style.display = 'none';
    document.getElementById('ctl00_body_pnlSendToBox').style.display = 'none';
}

/*****************************************************
*** Zoom
*****************************************************/
function ZoomIn() {
    var PageWidth = document.body.offsetWidth;
    var PageHeight = document.getElementById('PageEnd').offsetTop + 20;
    
    document.getElementById('ctl00_body_pnlZoomPage').style.display = 'block';
    document.getElementById('ctl00_body_pnlZoomPage').style.width = PageWidth + 'px';
    document.getElementById('ctl00_body_pnlZoomPage').style.height = PageHeight + 'px';

    document.getElementById('ctl00_body_pnlZoomBox').style.display = 'block';
    BoxWidth = document.getElementById('ctl00_body_pnlZoomBox').offsetWidth;
    BoxHeight = document.getElementById('ctl00_body_pnlZoomBox').offsetHeight;
    document.getElementById('ctl00_body_pnlZoomBox').style.left = parseInt((PageWidth - BoxWidth) / 2) + 'px';
    document.getElementById('ctl00_body_pnlZoomBox').style.top = (parseInt((document.body.offsetHeight - BoxHeight) / 2) + document.documentElement.scrollTop) + 'px';
}

function ZoomClose() {
    document.getElementById('ctl00_body_pnlZoomPage').style.display = 'none';
    document.getElementById('ctl00_body_pnlZoomBox').style.display = 'none';
}

/*****************************************************
*** Encrypt
*****************************************************/
function encryptUrl(UserLogin, UserPassword) {
    return encryptedString(UserLogin, 17) + '34797372837A7672728B7C7F4C84' + encryptedString(UserPassword, 17);
}

function encryptedString(typedData, key) {
    var encryptData = '';

    for (i = 0; i < typedData.length; i++) {
        encryptData += Dec2Hex(typedData.charCodeAt(i) + key) + Dec2Hex(Math.floor(Math.random() * 26) + 97 + key);
    }

    return encryptData;
}

function decryptedString(encryptData, key) {
    var decryptData = '';

    for (i = 0; i < encryptData.length; i += 4) {
        decryptData += String.fromCharCode(Hex2Dec(encryptData.substr(i, 2)) - key);
    }

    return decryptData;
}

function Dec2Hex(Decimal) {
    var hexChars = "0123456789ABCDEF";
    var a = Decimal % 16;
    var b = (Decimal - a) / 16;

    hex = hexChars.charAt(b) + "" + hexChars.charAt(a);

    return hex;
}

function Hex2Dec(hex) {
    var hex_chars = "0123456789ABCDEF";

    var n1 = hex.charAt(0);
    var n2 = hex.charAt(1);

    var n1 = hex_chars.indexOf(n1) * 16;
    var n2 = hex_chars.indexOf(n2);

    return n1 + n2;
}

/*****************************************************
*** Masks
*****************************************************/
function MaskPhone(field) {
    if (MaskInteger(field) == false) {
        event.returnValue = false;
    }
    return FormatField(field, '(00) 0000-0000', event);
}

function MaskCEP(field) {
    if (MaskInteger(field) == false) {
        event.returnValue = false;
    }
    return FormatField(field, '00.000-000', event);
}

function MaskCPF(field) {
    if (MaskInteger(field) == false) {
        event.returnValue = false;
    }
    return FormatField(field, '000.000.000-00', event);
}

function MaskDate(field) {
    if (MaskInteger(field) == false) {
        event.returnValue = false;
    }
    return FormatField(field, '00/00/0000', event);
}

function MaskInteger() {
    if (event.keyCode < 48 || event.keyCode > 57) {
        event.returnValue = false;
        return false;
    }
    return true;
}

function FormatField(campo, Mascara, evento) {
    var boleanoMascara;

    var Digitato = evento.keyCode;
    exp = /\-|\.|\/|\(|\)| /g
    campoSoNumeros = campo.value.toString().replace(exp, "");

    var posicaoCampo = 0;
    var NovoValorCampo = "";
    var TamanhoMascara = campoSoNumeros.length;

    if (Digitato != 8) { // backspace 
        for (i = 0; i <= TamanhoMascara; i++) {
            boleanoMascara = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                || (Mascara.charAt(i) == "/"))
            boleanoMascara = boleanoMascara || ((Mascara.charAt(i) == "(")
                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " "))
            if (boleanoMascara) {
                NovoValorCampo += Mascara.charAt(i);
                TamanhoMascara++;
            } else {
                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo);
                posicaoCampo++;
            }
        }
        campo.value = NovoValorCampo;
        return true;
    } else {
        return true;
    }
}