﻿function CallMovie(item, channel) {
    location.href = '/AveSui2010/WebSite/Anais/Movie.aspx?item=' + item;
}

function CallMenu(src) {
    var Page;

    switch (src) {
        case 1: Page = '/AveSui2010/WebSite/Exhibitor/Default.aspx'; break;
        case 2: Page = '/AveSui2010/WebSite/Visitor/Default.aspx'; break;
        case 3: Page = '/AveSui2010/WebSite/Seminario/Default.aspx'; break;
        case 4: Page = '/AveSui2010/WebSite/Contact/Default.aspx'; break;

        case 5: Page = '/AveSui2010/WebSite/Search/Default.aspx'; break;

        case 6: Page = '/AveSui2010/WebSite/Credential/Default.aspx'; break;
        case 7: Page = '/AveSui2010/WebSite/Seminario/Default.aspx'; break;

        case 8: Page = '/AveSui2010/WebSite/Seminario/Temario.aspx'; break;
        case 9: Page = '/AveSui2010/WebSite/GeneralText/Default.aspx?item=018'; break;
        case 10: Page = '/AveSui2010/WebSite/GeneralText/Default.aspx?item=019'; break;

        default: Page = '/AveSui2010/WebSite/Home/Default.aspx';
    }
    location.href = Page;
}

function CallLanguage(src) {
    var Culture;

    switch (src) {
        case 1: Culture = 'en'; break;
        case 2: Culture = 'es'; break;
        default: Culture = 'pt';
    }
    location.href = '/AveSui2010/WebSite/Home/Default.aspx?NewLanguage=' + Culture;
}

function CallSearch(Keyword) {
    if (Keyword.length < 3) {
        alert('A palavra-chave tem que ter pelo menos 3 caracteres.');
    } else {
        parent.location.href = '/AveSui2010/WebSite/Search/Default.aspx?key=' + MyUrlEncode(Keyword);
    }
}

function MyUrlEncode(Keyword) {
    Keyword = Keyword.toLowerCase();
    Keyword = escape(Keyword);

    while (Keyword.indexOf('%C') >= 0) { Keyword = Keyword.replace('%C', '%c3%8'); }
    while (Keyword.indexOf('%D') >= 0) { Keyword = Keyword.replace('%D', '%c3%9'); }
    while (Keyword.indexOf('%E') >= 0) { Keyword = Keyword.replace('%E', '%c3%a'); }
    while (Keyword.indexOf('%F') >= 0) { Keyword = Keyword.replace('%F', '%c3%b'); }

    return Keyword;
}

function GoToSubscribe() {
    location.href = '/AveSui2010/WebSite/Seminar/Subscribe.aspx';
}

function GoToCourse() {
    location.href = '/AveSui2010/WebSite/Curso/Default.aspx';
}

function GoToCourseSubscribe(src) {
    location.href = '/AveSui2010/WebSite/Curso/Subscribe.aspx?theme=' + src;
}

/*****************************************************
*** Mask
*****************************************************/
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num)) num = "0";

    cents = Math.floor((num * 100 + 0.5) % 100);
    num = Math.floor((num * 100 + 0.5) / 100).toString();
    if (cents < 10) cents = "0" + cents;

    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));
    return ("R$ " + num + "," + cents);
}

function formatNumber(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num)) num = "0";

    cents = Math.floor((num * 100 + 0.5) % 100);
    num = Math.floor((num * 100 + 0.5) / 100).toString();
    if (cents < 10) cents = "0" + cents;

    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));
    return (num + "," + cents);
}

function IsCPFValid(cpf) {
    var i;

    while (cpf.indexOf('.') >= 0) { cpf = cpf.replace('.', ''); }
    while (cpf.indexOf('-') >= 0) { cpf = cpf.replace('-', ''); }
    while (cpf.indexOf(' ') >= 0) { cpf = cpf.replace(' ', ''); }

    if ((cpf == '11111111111') || (cpf == '22222222222') || (cpf == '33333333333') || (cpf == '44444444444') || (cpf == '55555555555') || (cpf == '66666666666') || (cpf == '77777777777') || (cpf == '88888888888') || (cpf == '99999999999')) {
        return false;
    }

    var c = cpf.substr(0, 9);
    var dv = cpf.substr(9, 2);
    var d1 = 0;

    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i) * (10 - i);
    }

    if (d1 == 0) {
        return false;
    }

    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1) {
        return false;
    }

    d1 *= 2;
    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i) * (11 - i);
    }

    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(1) != d1) {
        return false;
    }

    return true;
}

function IsCNPJValid(CNPJ) {
    IsValid = false;

    if ((CNPJ.length > 17) && (CNPJ.charAt(2) == ".") && (CNPJ.charAt(6) == ".") && (CNPJ.charAt(10) == "/") && (CNPJ.charAt(15) == "-")) {
        if (document.layers && parseInt(navigator.appVersion) == 4) {
            x = CNPJ.substring(0, 2);
            x += CNPJ.substring(3, 6);
            x += CNPJ.substring(7, 10);
            x += CNPJ.substring(11, 15);
            x += CNPJ.substring(16, 18);
            CNPJ = x;
        } else {
            CNPJ = CNPJ.replace(".", "");
            CNPJ = CNPJ.replace(".", "");
            CNPJ = CNPJ.replace("-", "");
            CNPJ = CNPJ.replace("/", "");
        }

        var nonNumbers = /\D/;
        if (!nonNumbers.test(CNPJ)) {
            var a = [];
            var b = new Number;
            var c = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
            for (i = 0; i < 12; i++) {
                a[i] = CNPJ.charAt(i);
                b += a[i] * c[i + 1];
            }
            if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11 - x }
            b = 0;
            for (y = 0; y < 13; y++) {
                b += (a[y] * c[y]);
            }
            if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11 - x; }
            if ((CNPJ.charAt(12) == a[12]) && (CNPJ.charAt(13) == a[13])) {
                IsValid = true;
            }
        }
    }

    return IsValid;
}

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;
    }
}

/*****************************************************
*** Login
*****************************************************/
function Logon() {
    location.href = '/AveSui/WebSite/Login/Default.aspx?keyString=' + encryptUrl(document.getElementById('ctl00_Header_txtLoginUser').value, document.getElementById('ctl00_Header_txtLoginPassword').value);
}

function KeyPressEnter() {
    keyPressed = event.keyCode;
    if (keyPressed == 13) {
        Logon();
        return false;
    }
}

/*****************************************************
*** 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="/AveSui2010/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';
}

/*****************************************************
*** 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 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; 
    }
}

/*****************************************************
*** 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;
}