﻿function CallHigh(src) {
    parent.location.href = src;
}

function CallHomePicture(src) {
    parent.location.href = src;
}

function OpenLinkBanner() {
    parent.location.href = '/cursos/pos-graduacao-lato-sensu';
}

/*****************************************************
*** Restrict Area
*****************************************************/
function Logon() {
    location.href = '/Online/Login.aspx?keyString=' + encryptUrl(document.getElementById('txtLoginMail').value, document.getElementById('txtLoginPassword').value);
}

function KeyPressEnter() {
    keyPressed = event.keyCode;
    if (keyPressed == 13) {
        Logon();
        return false;
    }
}

/*****************************************************
*** 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);
}

/*****************************************************
*** 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;
}

/*****************************************************
*** Home
*****************************************************/
function OpenFLV() {
    var LayerText = "";
    
    LayerText += "<object codeBase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' ";
    LayerText += "width='680' height='380' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' VIEWASTEXT><param name='Movie' value='/Home/Player.swf'><param name='src' value='/Home/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='/Home/Player.swf' width='680' height='380' 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.display = 'block';
    document.getElementById('LayerBanner').style.display = 'none';
}

function CloseFLV() {
    document.getElementById('LayerFLV').innerHTML = '';
    document.getElementById('LayerFLV').style.display = 'none';
    document.getElementById('LayerBanner').style.display = 'block';
}

/*****************************************************
*** Picture
*****************************************************/
function HiddenPhoto() {
    document.getElementById('ctl00_body_pnlPagePhoto').style.display = 'none';
}

function ShowPicture(src, label) {
    document.getElementById('ctl00_body_imgPictureAmp').src = '/App_Common/Pix.gif';
    document.getElementById('ctl00_body_imgPictureAmp').src = 'http://file.cetn.com.br/' + src;
    document.getElementById('ctl00_body_lblPictureAmp').innerHTML = label;
}

function PreviousPicture() {
    CurrentPicture = CurrentPicture - 1;
    if (CurrentPicture < 0) { CurrentPicture = PictureCount; }
    ShowPicture(arrPictures[CurrentPicture], arrPicturesLabel[CurrentPicture]);
}

function NextPicture() {
    CurrentPicture = CurrentPicture + 1;
    if (CurrentPicture > PictureCount) { CurrentPicture = 0; }
    ShowPicture(arrPictures[CurrentPicture], arrPicturesLabel[CurrentPicture]);
}

function CallPicture(numItem) {
    try {
        CurrentPicture = numItem;
        ShowPicture(arrPictures[CurrentPicture], arrPicturesLabel[CurrentPicture]);
    } catch (err) { }
}

/*****************************************************
*** 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;
    }
}

/*****************************************************
*** 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';
}

/*****************************************************
*** Mask
*****************************************************/
function MaskCEP(field) {
    if (MaskInteger(field) == false) {
        event.returnValue = false;
    }
    return FormatField(field, '00.000-000', event);
}

function MaskPhone(field) {
    if (MaskInteger(field) == false) {
        event.returnValue = false;
    }
    return FormatField(field, '(00) 0000-0000', event);
}

function MaskDate(field) {
    if (MaskInteger(field) == false) {
        event.returnValue = false;
    }
    return FormatField(field, '00/00/0000', event);
}

function MaskHour(field) {
    if (MaskInteger(field) == false) {
        event.returnValue = false;
    }
    return FormatField(field, '00.00', event);
}

function MaskCNPJ(cnpj) {
    if (MaskInteger(cnpj) == false) {
        event.returnValue = false;
    }
    return FormatField(cnpj, '00.000.000/0000-00', event);
}

function MaskCPF(cpf) {
    if (MaskInteger(cpf) == false) {
        event.returnValue = false;
    }
    return FormatField(cpf, '000.000.000-00', 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;
    }
}
