﻿function CallHigh(src) {
    parent.location.href = src;
}

function CallHomePicture(src) {
    parent.location.href = src;
}

function NewsletterScrollBottom() {
    $(document).scrollTop(999999999999999);
}

/*****************************************************
*** Search
*****************************************************/
function CallSearch(Keyword) {
    if (Keyword == '') {
        parent.location.href = '/busca/';
    } else if (Keyword.length < 3) {
        alert('A palavra-chave tem que ter pelo menos 3 caracteres.');
    } else {
        parent.location.href = '/busca/' + MyUrlEncode(Trim(Keyword));
    }
}

function SearchClick() {
    CallSearch(document.getElementById('txtSearchHeader').value);
}

function KeyPressEnterOnSearch() {
    keyPressed = event.keyCode;
    if (keyPressed == 13) {
        SearchClick();
        return false;
    }
}

function Trim(str) {
    return str.replace(/^\s+|\s+$/g, "");
}

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 SearchTextBoxOnEnter() {
    document.getElementById('ctl00_Header_txtSearchHeader').className = 'HeaderSearchTextBoxBlack';
    if (document.getElementById('ctl00_Header_txtSearchHeader').value == 'Digite aqui o que procura ...') { document.getElementById('ctl00_Header_txtSearchHeader').value = ''; }
}

function SearchTextBoxOnExit() {
    if (document.getElementById('ctl00_Header_txtSearchHeader').value == '') {
        document.getElementById('ctl00_Header_txtSearchHeader').value = 'Digite aqui o que procura ...';
        document.getElementById('ctl00_Header_txtSearchHeader').className = 'HeaderSearchTextBoxGray';
    }
}

function Trim(str) { return str.replace(/^\s+|\s+$/g, ""); }
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;
}

/*****************************************************
*** 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.camaraportofeliz.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;
    }
}
