﻿var xmlhttp;
var now = new Date();
var textCustom;
function loadXMLDoc(url) {
    xmlhttp = false;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            xmlhttp = new XMLHttpRequest();
        }
        catch (e) {
            xmlhttp = false;
        }
        // branch for IE/Windows ActiveX version
    }
    else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                xmlhttp = false;
            }
        }
    }
    if (xmlhttp != null) {
        if (url.substr(url.lastIndexOf('.')).length > 5)
            url += '&';
        else
            url += '?';

        var now = new Date();
        url += 'd=' + now.getTime();

        xmlhttp.onreadystatechange = XmlHttp_StateChange;
        xmlhttp.open("GET", url, true);
        xmlhttp.send("");
    }
    else {
        alert("Your browser does not support XMLHTTP.");
    }
}

function Request(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}
function expandCollapse() {
    for (var i = 0; i < expandCollapse.arguments.length; i++) {
        var element = document.getElementById(expandCollapse.arguments[i]);
        element.style.display = (element.style.display == "none") ? "block" : "none";

    }
}
function alterFocus(current, maxlength, next) {
    if (current.value.length == maxlength) {
        document.getElementById(next).focus();
    }
}
function selectItem(itemTypeId, idItem) {
    idt = itemTypeId;
    id = idItem;
    window.scrollTo(0,100);
    loadXMLDoc("cardPreview.aspx?idt=" + idt + "&id=" + id);
}
function redirectSelectItem(itemTypeId, idItem) {
    idt = itemTypeId;
    id = idItem;
    window.location = "itemList.aspx?idt=4";
    loadXMLDoc("cardPreview.aspx?idt=" + idt + "&id=" + id);
}
function selectCard(cardId, ImageId, AudioId, TextId) {
    loadXMLDoc("cardPreview.aspx?idt=29&id=" + cardId + "&imageId=" + ImageId + "&audioId=" + AudioId + "&textId=" + TextId);
}
function redirectSelectCard(cardId, ImageId, AudioId, TextId) {
    loadXMLDoc("cardPreview.aspx?idt=29&id=" + cardId + "&imageId=" + ImageId + "&audioId=" + AudioId + "&textId=" + TextId);
    SetChannelName();
}
function XmlHttp_StateChange() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            try {
                document.getElementById("cardPreview").innerHTML = xmlhttp.responseText;
            }
            catch (err) {
            }
        }
        else {
            alert("Problem retrieving XML data");
        }
    }
}
function loadPreview() {
    loadXMLDoc("cardPreview.aspx");
}

function loadPreviewList(itemtype) {
    loadXMLDoc("cardPreview.aspx?ItemType=" + itemtype);
}

function showDiv(id) {
    if (document.getElementById) {
        document.getElementById(id).style.display = 'block';
    }
    else {
        if (document.layers) {
            document.id.display = 'block';
        }
        else {
            document.all.id.style.display = 'block';
        }
    }
}
function hideDiv(id, popup) {

    expandCollapse(popup, 'over');


    if (document.getElementById) {
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) {
            document.id.display = 'none';
        }
        else {
            document.all.id.style.display = 'none';
        }
    }
}
function SetCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function GetCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
// --- Area Onde setamos o Cookie do Cartão MMS

function OpenMMs(idc) {
    main.SetChannel(idc);
    var url = "sendItem.aspx";
    window.location = url;
}
function SetChannelName() {
    var channel = main.GetChannel().value;
    if (channel == null || channel == "null" || channel == "") {
        location.href = location.href.replace(/#Top/g, "") + "#Top";
        loadFunctions('boxCardMMS');
    }
    else {
        OpenMMs(channel);
    }
}
// --- Area Onde setamos o Cookie do Cartão noticias  
function OpenNews(idc, store) {
    SetCookie('store', store, 1);

    var iddc = GetIdDistChannel(store, dcName);

    var url = keyUrl + '/news.aspx?iddc=' + iddc + '&idc=' + idc + '&format=MMS&CarrierName=' + store;

    window.location = url;
}
function SetDcName(Name) {
    dcName = Name;
    var store = GetCookie('store');
    if (store == null || store == "null" || store == "") {
        location.href = location.href.replace(/#Top/g, "") + "#Top";
        loadFunctions('boxNews');
    }
    else {
        OpenNews(-1, store);
    }
 }
// --- Area de Listagem de categoria inicial dos itens  
function ListNews(store, type) {
    SetCookie('store', store, 1);
    //var iddc = GetIdDistChannel(store, dcName);
    openListNews(store, type);
}

function SetBoxListNews(type)
{
   document.getElementById('openListNewsTC').href = 'javascript:ListNews(\''+type+'\',\'TC\')';
   
   //document.getElementById('openListNewsAC').href = 'javascript:ListNews(\''+type+'\',\'AC\')';
    loadFunctions('boxListNews');
}

function ConfirmCredit(Msisdn) {
    var lblError = document.getElementById('<%=lblError.ClientID%>');
    var result = sendItem.CheckChannel(Msisdn, 29, main.GetChannel().value).value;
    switch (result) {
        case "NotHasCredit":
            lblError.innerHTML = 'Seus créditos são insuficientes.';
            break;
        case "Error":
            return false;
            break;
        default:
            return true;
    }
    return false;
}

function openListNews(store , type) {
    var store = GetCookie('store');
    if (store == null || store == "null" || store == "") {
        location.href = location.href.replace(/#Top/g, "") + "#Top";
        loadFunctions('boxListNews');
    }
    else {        
            window.location = main.GetUrlSetting(type,store).value;
        }
}
function popAdult(url) {
    document.getElementById("btnAdultConfirm").href = 'javascript:window.location ="' + url + '"';
    document.getElementById("btnAdultCancel").href = "javascript:esconderboxCel('boxAdult');";
    loadFunctions('boxAdult');
    anchor('#Top');
    return false;
}
function redirectChannel(url) {
    window.open(url, '', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}
/*Generic HttpRequest---------------------------------------------------------------------------------------------*/

function LoadURLHttpRequest(url, divName) {

    var xmlhttp = false;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            xmlhttp = new XMLHttpRequest();
        }
        catch (e) {
            xmlhttp = false;
        }
        // branch for IE/Windows ActiveX version
    }
    else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                xmlhttp = false;
            }
        }
    }
    if (xmlhttp != null) {
        if (url.substr(url.lastIndexOf('.')).length > 5)
            url += '&';
        else
            url += '?';

        var now = new Date();
        url += 'd=' + now.getTime();

        xmlhttp.onreadystatechange = function() {
            document.getElementById(divName).innerHTML = "<img id='loadAjax' src='ajax-loader.gif' />";
            // if xmlhttp shows "loaded"
            // window.status = "StateChange: " + xmlhttp.readyState;
            if (xmlhttp.readyState == 4) {
                // if "OK"
                if (xmlhttp.status == 200) {
                    document.getElementById(divName).innerHTML = xmlhttp.responseText;
                    //alert(xmlhttp.responseText);
                }
                else {
                    alert("Problem retrieving XML data")
                }
            }
        }
        alert(url);
        xmlhttp.open("GET", url, true);

        xmlhttp.send("");
    }
    else {
        alert("Your browser does not support XMLHTTP.");
    }
}
/*endGeneric HttpRequest---------------------------------------------------------------------------------------------*/

/* Pop-up --------------------------------------------------------------------------------------------------------------------*/

// Utilizado para evitar de digitar: document.getElementById toda hora, tornando o processo mais prático
function gE(ID) {
    return document.getElementById(ID);
}
// Utilizado para evitar de digitar: document.getElementsByTagName toda hora, tornando o processo mais prático
function gEs(tag) {
    return document.getElementsByTagName(tag);
}
// Chama a função loadFunctions ao carregar a página
//window.onload = loadFunctions;

// Função que chama outras funções
function loadFunctions(divContent) {
    exibirBgBody()
    boxCel(divContent)
}
// Cria a div denominada como boxCel, a qual conterá o formulário dpara escolha de celulares
function boxCel(divContent) {
    exibirBgBody()
    gE(divContent).style.display = 'block'
    gE('bgBody').style.display = 'block'
}
function esconderboxCel(divContent) {
    gE('bgBody').style.display = 'none'
    gE(divContent).style.display = 'none'
}
// Utilizado para criar o fundo sobre a página (wiewport), body.
function exibirBgBody() {
    // Seleciona a tag body. item(0) por que só existe uma tag body
    var tagBody = gEs('body').item(0);
    // Pega os tamanhos atuais da página, como largura, altura, ...
    var sizesPage = getPageSize();
    // Vamos criar uma tag div
    var bgBody = document.createElement('div');

    // Setar o atributo ID a div criada
    bgBody.setAttribute('id', 'bgBody');
    // Essa div terá o tamanho exato da página
    bgBody.style.height = arrayPageSize[1] + 'px';
    // Essa div terá a largura exata da página
    bgBody.style.width = arrayPageSize[0] + 'px';
    // Evita criar a div novamente
    if (!gE('bgBody')) {
        tagBody.insertBefore(bgBody, tagBody.firstChild);
    }
}
//-------
//
/* Funções de terceiros */
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight + 10;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth - 18;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
}

/* end Pop-up--------------------------------------------------------------------------------------------------------------------------------*/

/*-----------OPEC TAGS DE PUBLICIDADE. NÃO ALTERAR ESSE TRECHO-------------*/
function OAS_VARS(OAS_page) {
    OAS_sitepage = 'www.igcelular.com.br/' + OAS_page;


    if (OAS_page == 'login') {
        OAS_VARSpos('x15,Top2,Right1');
    } else {
        OAS_VARSpos('x15,Top2,Right1');
    }
}
function OAS_VARSpos(OAS_pos) {
    OAS_listpos = OAS_pos;
}
OAS_url = 'http://adserver.ig.com.br/RealMedia/ads/';
OAS_query = '';
OAS_target = '_blank';
OAS_version = 10;
OAS_rn = '001234567890'; OAS_rns = '1234567890';
OAS_rn = new String(Math.random()); OAS_rns = OAS_rn.substring(2, 11);
function OAS_NORMAL(pos) {
    document.write('<a href="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" target="' + OAS_target + '">');
    document.write('<img src="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" border="0"></a>');
}
function OAS_START() {
    OAS_version = 11;
    if (navigator.userAgent.indexOf('Mozilla/3') != -1 || navigator.userAgent.indexOf('Mozilla/4.0 WebTV') != -1)
        OAS_version = 10;
    if (OAS_version >= 11)
        document.write('<SCRIP' + 'T LANGUAGE=JavaScript1.1 SRC="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '"><\/SCRIP' + 'T>');
}
document.write('');
function OAS_AD(pos) {
    if (OAS_version >= 11)
        OAS_RICH(pos);
    else
        OAS_NORMAL(pos);
}
/*-----------OPEC-------------*/

/*-----------end OPEC TAGS DE PUBLICIDADE. NÃO ALTERAR ESSE TRECHO-------------*/


function LoadURLHttpRequest(url, divName) {

    var xmlhttp = false;
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            xmlhttp = new XMLHttpRequest();
        }
        catch (e) {
            xmlhttp = false;
        }
        // branch for IE/Windows ActiveX version
    }
    else if (window.ActiveXObject) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                xmlhttp = false;
            }
        }
    }
    if (xmlhttp != null) {
        if (url.substr(url.lastIndexOf('.')).length > 5)
            url += '&';
        else
            url += '?';

        var now = new Date();
        url += 'd=' + now.getTime();

        xmlhttp.onreadystatechange = function() {
            document.getElementById(divName).innerHTML = "<img id='loadAjax' src='style/images/ajax-loader.gif' />";
            if (xmlhttp.readyState == 4) {
                // if "OK"
                if (xmlhttp.status == 200) {
                    document.getElementById(divName).innerHTML = xmlhttp.responseText;
                }
                else {
                    //alert("Problem retrieving XML data")
                }
            }
        }
        xmlhttp.open("GET", url, true);

        xmlhttp.send("");
    }
    else {
        alert("Your browser does not support XMLHTTP.");
    }

}


