﻿var pathBase = "/";
//var pathBase = "/test/";

function gE(ID) {
    return document.getElementById(ID);
}
function gEs(tag) {
    return document.getElementsByTagName(tag);
}
function loadFunctions(divContent) {
    try {
        exibirBgBody();
        boxCel(divContent);
        anchor();
    }
    catch (Error) {
        alert(Error);
    }
}



function validaPhoneNumber(src, args){
  args.IsValid = (args.Value.length == 8)
}

function boxCel(divContent) {
    try
    {
        var elements = document.getElementsByTagName("select");
        for(var i = 0; i < elements.length; i++)
        {
            if(elements[i].id.indexOf('Pane') < 0 && elements[i].id.indexOf('Carrier') < 0)
                elements[i].style.display = 'none';
        }
    }
    catch(e)
    {}
    exibirBgBody();
    gE(divContent).style.display = 'block';
    gE('bgBody').style.display = 'block';
}

function esconderboxCel(divContent) {
  try
    {
        var elements = document.getElementsByTagName("select");
        for(var i = 0; i < elements.length; i++)
        {
            if(elements[i].id.indexOf('Pane') < 0)
                elements[i].style.display = 'block';
        }
    }
    catch(e)
    {}
    gE('bgBody').style.display = 'none';
    gE(divContent).style.display = 'none';
}

function setMSISDN(objRegionCode, objPhoneNumber){
  uscWizardStep1.SetMSISDN(document.getElementById(objRegionCode).value + document.getElementById(objPhoneNumber).value);
}

function changeCarrier(objCarrier, objRegionCode, objPhoneNumber, idImg){
   RemoveFirstItem(objCarrier.id);
if (objCarrier.value == '-1')
   document.getElementById(idImg).src = pathBase + 'style/images/operadoras/pixel.gif';
else{
  uscWizardStep1.SetChannelID(objCarrier.value); 
  document.getElementById(idImg).src = pathBase + 'style/images/operadoras/logo_'+ objCarrier.value + '.gif';
  }  
}

function exibirBgBody() {    
    var tagBody = gEs('body').item(0);
    var sizesPage = getPageSize();
    var bgBody = document.createElement('div');
    bgBody.setAttribute('id', 'bgBody');
    bgBody.style.height = arrayPageSize[1] + 'px';
    bgBody.style.width = arrayPageSize[0] + 'px'; 
    if (!gE('bgBody')) {
        tagBody.insertBefore(bgBody, tagBody.firstChild);
    }  
}
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) {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight + 10;
    }
    var windowWidth,
    windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth - 18;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
}
function OAS_VARS(OAS_page) {
    OAS_sitepage = 'celular.ig.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) {
    try {
        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>');
    } catch(Error) {}
}
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>');
    }
}
function OAS_AD(pos) {
    if (OAS_version >= 11) {
        OAS_RICH(pos);
    } else {
        OAS_NORMAL(pos);
    }
}
var RedirUrl = "";
var HasPhone;

function LoadContentItem(itemTypeId, divName,idAp,idCarrier) {
    loadXMLDocItem(pathBase + "auxItemlist.aspx?idt="+itemTypeId+"&idAp="+idAp+"&IC="+idCarrier, divName);
}

function RemoveFirstItem(element) {
    carrierPane = document.getElementById(element);
    if (carrierPane.options[0].value == -1) {
        carrierPane.options[0] = null;
    }
}
function LoadDefaultContentItem() {
    LoadContentItem(21);
}
function CalendarFocus() {
    var caledar = document.getElementById('ctl00_cphHome_date');
    if (caledar.checked) {
        document.getElementById("ctl00_cphHome_txtDateStart").disabled = false;
        document.getElementById("ctl00_cphHome_txtDateEnd").disabled = false;
        return;
    }
    document.getElementById("ctl00_cphHome_txtDateStart").disabled = true;
    document.getElementById("ctl00_cphHome_txtDateEnd").disabled = true;
    closeCalendar();
}

function alterFocus(current, maxlength, next) {
    if (current.value.length == maxlength) {
        if (document.getElementById(next).disabled == false)
          document.getElementById(next).focus();
    }
}

function alterFocusBuy(current, maxlength, next, objRegionCode, objPhoneNumber) {
    if (current.value.length == maxlength) {
        if (document.getElementById(next).disabled == false)
          document.getElementById(next).focus();
        else
          uscWizardStep1.SetMSISDN(document.getElementById(objRegionCode).value + document.getElementById(objPhoneNumber).value);  
    }
}

function loadXMLDocItem(url, divName) {
    var xmlhttp = false;
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch(e) {
            xmlhttp = false;
        }
    } 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() {
            if (document.getElementById(divName) != null) {
                document.getElementById(divName).innerHTML = '<img id="loadAjax" src="'+ pathBase +'style/images/ajax-loader.gif"/>';
            }
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    document.getElementById(divName).innerHTML = xmlhttp.responseText;
                }
                else
                {
                  document.getElementById(divName).innerHTML = '';
                }
            }
        };
        xmlhttp.open("GET", url, true);
        xmlhttp.send("");
    } else {
        alert("-Your browser does not support XMLHTTP.");
    }
}
function XmlHttp_StateChange() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            document.getElementById("listaModelos").innerHTML = xmlhttp.responseText;
        }
    }
}

function LoadContent(Manufacture, divManufactureName, IsUpdate, sign, imgManufacture, divNameModels) {
    if (Manufacture > '0') {
        if (!IsUpdate) {
            LoadURLHttpRequest(pathBase + 'listPhone.aspx?idap=' + Manufacture + '&sign=' + sign, divNameModels);
        } else {
            loadXMLDoc(pathBase + 'listPhoneUpdate.aspx?idap=' + Manufacture, divNameModels);
        }
        document.getElementById(imgManufacture).src = pathBase + 'style/images/manufactures/'+ Manufacture + '.gif';
    }
}

function LoadContentBuy(Manufacture, divManufactureName, IsUpdate, sign, imgManufacture, divNameModels) {
    if (Manufacture > '0') {
        document.getElementById(imgManufacture).src = pathBase + 'style/images/manufactures/' + Manufacture + '.gif';
            LoadURLHttpRequest(pathBase + 'listPhoneBuy.aspx?idap=' + Manufacture + '&sign=' + sign, divNameModels);
    }
}

function LoadContentFilterBuy(manufactureID, keyword, divModelsName) {
    var manufacture = document.getElementById(manufactureID);
    var selectedManufacture = manufacture[manufacture.selectedIndex].innerText;
    var textInputed = document.getElementById(keyword).value;
    var manufactureID = manufacture[manufacture.selectedIndex].value;
    var kwrd = textInputed;
    if (kwrd != '') {
        LoadURLHttpRequest(pathBase + 'listPhoneBuy.aspx?idap=' + manufactureID + '&kwrd=' + kwrd, divModelsName);
    }
}

function LoadFilterEnterKeyBuy(evt, manufacture, keyword, divNameModels) {
    var charCode = (evt.which) ? evt.which: event.keyCode;
    if (charCode == 13) {
        LoadContentFilterBuy(manufacture, keyword, divNameModels);
        return true;
    }
    return true;
}


function LoadContentFilterPopUp(manufactureID, keyword, divModelsName) {
    var manufacture = document.getElementById(manufactureID);
    var selectedManufacture = manufacture[manufacture.selectedIndex].innerText;
    var textInputed = document.getElementById(keyword).value;
    var manufactureID = manufacture[manufacture.selectedIndex].value;
    var kwrd = textInputed;
    if (kwrd != '') {
        loadXMLDoc(pathBase + 'listPhoneUpdate.aspx?idap=' + manufactureID + '&kwrd=' + kwrd, divModelsName);
    }
}
function LoadFilterEnterKeyPop(evt, manufacture, keyword, sign, divModelsName) {
    var charCode = (evt.which) ? evt.which: event.keyCode;
    if (charCode == 13) {
        LoadContentFilterPopUp(manufacture, keyword, sign, divModelsName);
        return true;
    }
    return true;
}
function LoadDefaultContent() {
    LoadContent(21);
}
function loadXMLDoc(url, divModelsName) {
    xmlhttp = false;
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch(e) {
            xmlhttp = false;
        }
    } 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();
        document.getElementById(divModelsName).innerHTML = '<img id="loadAjax" src="'+ pathBase +'style/images/ajax-loader.gif"/>';
        xmlhttp.onreadystatechange = XmlHttp_StateChange;
        xmlhttp.open("GET", url, true);
        xmlhttp.send("");
    } else {
        alert("_Your browser does not support XMLHTTP.");
    }
}
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 isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which: event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}
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 buyItem(itemTypeId, itemId) {
    if (HasPhone) {
        var idx = document.location.href.lastIndexOf("/");
        if (itemTypeId != '32') {
            var url = document.location.href.substr(0, idx) + pathBase + "login.aspx?idt=" + itemTypeId + "&id=" + itemId;
        } else {
            var url = document.location.href.substr(0, idx) + pathBase + "preImageChief.aspx?idt=" + itemTypeId + "&id=" + itemId;
        }
        window.location = url;
    } else {
        window.scroll(0,100);
        RedirUrl = "&idt=" + itemTypeId + "&id=" + itemId;
        loadFunctions('boxCel');
    }
}
var categoryList = new Array();
function rollout(category) {
    var i;
    for (i = 0; i < categoryList.length; i++) {
        if (category != categoryList[i]) {
            thisMenu = document.getElementById(categoryList[i]).style;
            thisMenu.display = "none";
        }
    }
    if (document.getElementById) {
        thisMenu = document.getElementById(category).style;
        if (thisMenu.display == "block") {
            thisMenu.display = "none";
        } else {
            thisMenu.display = "block";
            categoryList[i] = category;
        }
        return false;
    } else {
        return true;
    }
}
function AbrePopup(theURL, winName, features) {
    window.open(theURL, winName, features);
};
function PopupFullScrean(url) {
    window.open(url, '', 'fullscreen=yes,resizable=no');
}
function ObjetoExiste(paramObjeto) {
    return (typeof(paramObjeto) != "undefined" && paramObjeto != null);
}
function MostraEscondeBlocoHTML(paramID) {
    var prefixoElemento = paramID.split("_")[0];
    var elementoAtual = "";
    for (i = 0; i <= parseInt(numElementos); i++) {
        elementoAtual = prefixoElemento + "_" + i;
        if (ObjetoExiste(document.getElementById(elementoAtual))) {
            if (elementoAtual != paramID) {
                document.getElementById(elementoAtual).style.display = "none";
                document.getElementById(elementoAtual).parentNode.className = "ConteudoFechado";
            }
        }
    }
    document.getElementById(paramID).style.display = document.getElementById(paramID).style.display == "none" ? "block": "none";
    document.getElementById(paramID).parentNode.className = document.getElementById(paramID).parentNode.className == "ConteudoFechado" ? "ConteudoAberto": "ConteudoFechado";
}
function executaMontaTitulo(tag) {
    var Texto = eval(tag).innerHTML;
    Texto = Texto.toString();
    Texto = Texto.toUpperCase();
    Imgs = new Array();
    for (i = 0; i < Texto.length; i++) {
        Imgs[i] = new Image;
        CodAscii = Texto.charCodeAt(i);
        Imgs[i].src = VirtualDir + pathBase + 'Imgs/LetraTitulo/' + CodAscii + '.gif';
    }
    var Titulo = '';
    for (k = 0; k < Texto.length; k++) {
        CodAscii = Texto.charCodeAt(k);
        var Titulo = Titulo + '<img src="' + VirtualDir + pathBase + 'Imgs/LetraTitulo/' + CodAscii + '.gif" border="0">';
    }
    eval(tag).innerHTML = "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr style='line-height:12px;'><td width='1' height='1'><img src='" + VirtualDir + "/Imgs/BordasTabelas/BordaBoxTituloEsqTop.gif' width='12' height='12'></td><td rowspan='3' class='BordaTop BordaBotton' style='text-align:left;vertical-align:middle;padding-left:6px;padding-top:2px'>" + Titulo + "</td><td width='1' height='1'><img src='" + VirtualDir + "/Imgs/BordasTabelas/BordaBoxTituloDirTop.gif' width='12' height='12'></td></tr><tr><td class='BordasLaterais' style='border-right:0px;'><img src='/Imgs/Transparente.gif' width='1' height='6'></td><td class='BordasLaterais' style='border-left:0px;'><img src='/Imgs/Transparente.gif' width='1' height='6'></td></tr><tr style='line-height:12px;'><td width='1' height='1'><img src='" + VirtualDir + "/Imgs/BordasTabelas/BordaBoxTituloEsq.gif' width='12' height='12'></td><td width='1' height='1'><img src='" + VirtualDir + "/Imgs/BordasTabelas/BordaBoxTituloDir.gif' width='12' height='12'></td></tr></table>";
}
function MontaTitulo() {
    var tag = document.getElementsByTagName("p");
    var tag2 = document.getElementsByTagName("span");
    var p = false;
    for (i = 0; i < tag.length; i++) {
        if (tag[i].className == "TituloInternas") {
            executaMontaTitulo(tag[i]);
            p = true;
            break;
        }
    }
    if (p != true) {
        for (i = 0; i < tag2.length; i++) {
            if (tag2[i].className == "TituloInternas") {
                executaMontaTitulo(tag2[i]);
                break;
            }
        }
    }
}
isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true: false;
NS4 = (document.layers) ? true: false;
IEmac = ((document.all) && (isMac)) ? true: false;
IE4plus = (document.all) ? true: false;
IE4 = ((document.all) && (navigator.appVersion.indexOf("MSIE 4.") != -1)) ? true: false;
IE5 = ((document.all) && (navigator.appVersion.indexOf("MSIE 5.") != -1)) ? true: false;
ver4 = (NS4 || IE4plus) ? true: false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape') != -1) ? true: false;
var gSafeOnload = new Array();
function SafeAddOnload(f) {
    if (IEmac && IE4) {
        window.onload = SafeOnload;
        gSafeOnload[gSafeOnload.length] = f;
    } else if (window.onload) {
        if (window.onload != SafeOnload) {
            gSafeOnload[0] = window.onload;
            window.onload = SafeOnload;
        }
        gSafeOnload[gSafeOnload.length] = f;
    } else {
        window.onload = f;
    }
}
function SafeOnload() {
    for (var i = 0; i < gSafeOnload.length; i++) {
        gSafeOnload[i]();
    }
}
function MM_swapImgRestore() {
    var i,
    x,
    a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
        x.src = x.oSrc;
}
function MM_preloadImages() {
    var d = document;
    if (d.images) {
        if (!d.MM_p)
            d.MM_p = new Array();
        var i,
        j = d.MM_p.length,
        a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++) {
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
        }
    }
}
function MM_findObj(n, d) {
    var p,
    i,
    x;
    if (!d)
        d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (! (x = d[n]) && d.all)
        x = d.all[n];
    for (i = 0; ! x && i < d.forms.length; i++)
        x = d.forms[i][n];
    for (i = 0; ! x && d.layers && i < d.layers.length; i++) {
        x = MM_findObj(n, d.layers[i].document);
    }
    if (!x && d.getElementById) {
        x = d.getElementById(n);
    }
    return x;
}
function MM_swapImage() {
    var i,
    j = 0,
    x,
    a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3) {
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc)
                x.oSrc = x.src;
            x.src = a[i + 2];
        }
    }
}
function EscreveTitulosSeparadoresSemLinks(texto) {
    var StringTitulo;
    StringTitulo = "<table width='100%' border=0 cellspacing=0 cellpadding=0><tr><td width=1 valign=bottom><table width='100%' border=0 cellspacing=0 cellpadding=0><tr><td width=1><img src='" + VirtualDir + "/Imgs/MarcaSecaoEsqSemMais.gif' border=0/></td><td width='99%' nowrap=NOWRAP class='fundoOperadora Fonte11Branca'>" + texto + "</td><td width=1><img src='" + VirtualDir + "/Imgs/MarcaSecaoDir.gif'/></td></tr></table></td><td class=LinhaCorOperadora><img src='" + VirtualDir + "/Imgs/transparente.gif' height=10'/></td></tr></table>";
    document.write(StringTitulo);
}
function EscreveTitulosSeparadoresComLinks(texto, urllink) {
    var StringTitulo;
    StringTitulo = "<table width='100%' border=0 cellspacing=0 cellpadding=0><tr><td width=1 valign=bottom><table width='100%' border=0 cellspacing=0 cellpadding=0><tr><td width=1><a href='" + urllink + "'><img src='" + VirtualDir + "/Imgs/MarcaSecaoEsq.gif' border=0/></a></td><td width='99%' nowrap=NOWRAP class=fundoOperadora><a href='" + urllink + "' class=Fonte11Branca>" + texto + "</a></td><td width=1><img src='" + VirtualDir + "/Imgs/MarcaSecaoDir.gif'/></td></tr></table></td><td class=LinhaCorOperadora><img src='" + VirtualDir + "/Imgs/transparente.gif' height=10'/></td></tr></table>";
    document.write(StringTitulo);
}
function EscreveTitulosSeparadoresCinza(texto) {
    var StringTitulo;
    StringTitulo = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='539' height='23'><param name='movie' value='" + VirtualDir + "/swf/BarraDeTituloCinza.swf?texto=" + texto + "'><param name='quality' value='high'><embed src='" + VirtualDir + "/swf/BarraDeTituloCinza.swf?texto=" + texto + "' quality='high' pluginspage='www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='539' height='23'></embed></object>";
    document.write(StringTitulo);
}
function MontaTituloBox(Texto) {
    Texto = Texto.toUpperCase();
    var Titulo = '<div id="' + Texto + '" width="100%" nowrap class="TituloBox">' + Texto + '</div>';
    document.write(Titulo);
    if (navigator.appName.toLowerCase().indexOf("explorer") == "-1") {
        var tag = document.getElementById(Texto);
        if (typeof(tag.getElementsByTagName("a")) != "undefined") {
            var Link = tag.getElementsByTagName("a");
            tag.innerHTML = '<table border="0" cellspacing="0" cellpadding="0"><tr><td nowrap class="TituloBox"><a href="' + Link[0].href + '" style="color:#fff;text-decoration:none">' + Texto + '</a></td></tr></table>';
        }
    }
}
function AC_AddExtension(src, ext) {
    if (src.indexOf('?') != -1) {
        return src.replace(/\?/, ext + '?');
    } else {
        return src + ext;
    }
}
function AC_Generateobj(objAttrs, params, embedAttrs) {
    var str = '<object ';
    for (var i in objAttrs) {
        str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params) {
        str += '<param name="' + i + '" value="' + params[i] + '"/>';
    }
    str += '<embed ';
    for (var i in embedAttrs) {
        str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '></embed></object>';
    document.write(str);
}
function AC_FL_RunContent() {
    var ret = AC_GetArgs(arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
    AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_SW_RunContent() {
    var ret = AC_GetArgs(arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000", null);
    AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType) {
    var ret = new Object();
    ret.embedAttrs = new Object();
    ret.params = new Object();
    ret.objAttrs = new Object();
    for (var i = 0; i < args.length; i = i + 2) {
        var currArg = args[i].toLowerCase();
        switch (currArg) {
        case "classid":
            break;
        case "pluginspage":
            ret.embedAttrs[args[i]] = args[i + 1];
            break;
        case "src":
        case "movie":
            args[i + 1] = AC_AddExtension(args[i + 1], ext);
            ret.embedAttrs["src"] = args[i + 1];
            ret.params[srcParamName] = args[i + 1];
            break;
        case "onafterupdate":
        case "onbeforeupdate":
        case "onblur":
        case "oncellchange":
        case "onclick":
        case "ondblClick":
        case "ondrag":
        case "ondragend":
        case "ondragenter":
        case "ondragleave":
        case "ondragover":
        case "ondrop":
        case "onfinish":
        case "onfocus":
        case "onhelp":
        case "onmousedown":
        case "onmouseup":
        case "onmouseover":
        case "onmousemove":
        case "onmouseout":
        case "onkeypress":
        case "onkeydown":
        case "onkeyup":
        case "onload":
        case "onlosecapture":
        case "onpropertychange":
        case "onreadystatechange":
        case "onrowsdelete":
        case "onrowenter":
        case "onrowexit":
        case "onrowsinserted":
        case "onstart":
        case "onscroll":
        case "onbeforeeditfocus":
        case "onactivate":
        case "onbeforedeactivate":
        case "ondeactivate":
        case "type":
        case "codebase":
            ret.objAttrs[args[i]] = args[i + 1];
            break;
        case "width":
        case "height":
        case "align":
        case "vspace":
        case "hspace":
        case "class":
        case "title":
        case "accesskey":
        case "name":
        case "id":
        case "tabindex":
            ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i + 1];
            break;
        default:
            ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i + 1];
        }
    }
    ret.objAttrs["classid"] = classid;
    if (mimeType)
        ret.embedAttrs["type"] = mimeType;
    return ret;
}
function PreviewImageChef(itemId, formatId) {
    var text = document.getElementById('txtImageChef').value;
    document.getElementById('imgPreview').src = 'http://previews.ringring.com.br/Default.aspx?idt=32&id=' + itemId + '&idf=' + formatId + '&ext=gif&t=' + text;
}
function onEnter(e) {
    if (!e) {
        if (window.event) {
            e = window.event;
        } else {
            return;
        }
    }
    if (typeof(e.keyCode) == 'number') {
        e = e.keyCode;
    } else if (typeof(e.which) == 'number') {
        e = e.which;
    } else if (typeof(e.charCode) == 'number') {
        e = e.charCode;
    } else {
        return;
    }
    if (e == 13) {
        Search();
        return false;
    }
}
function Search() {
    var idx = document.location.href.lastIndexOf("/");
    var url = StoreIframeUrl + "?url=" + document.location.href.substr(0, idx) + pathBase + "auxItemlist.aspx?idt=";
    url += document.getElementById("idt").value;
    url += "%26k=";
    url += document.getElementById("k").value;
    self.parent.location.href = url;
}
function txtnumber(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (!evt) {
        evt = window.event;
    }
    var shiftkey = evt.shiftKey;
    if (!shiftkey) {
        if (charCode >= 96 && charCode <= 105 || charCode >= 48 && charCode <= 57 || charCode == 46 || charCode == 8 || charCode == 9){
            return true;
        }
        else {
            return false;
        }
    }
    return false;
}
function GetSelectedOptionExtract() {
    var month = document.getElementById('ctl00_cphHome_month');
    var all = document.getElementById('ctl00_cphHome_all');
    var date = document.getElementById('ctl00_cphHome_date');
    if (month.checked) {
        window.location = pathBase + 'extractPackage.aspx?filter=month';
    }
    if (all.checked) {
        window.location = pathBase + 'extractPackage.aspx?filter=all';
    }
    if (date.checked) {
        var txtdateIni = document.getElementById('ctl00_cphHome_txtDateStart').value;
        var txtdatEnd = document.getElementById('ctl00_cphHome_txtDateEnd').value;
        window.location = pathBase + 'extractPackage.aspx?filter=date' + '&dti=' + txtdateIni + '&dte=' + txtdatEnd;
    }
}
function CarrierPaneUpdate(CarrierId, IdName, isUpdate, ddlName, divPhoneName, imgCarrier, imgManufacture, divFilter) {
    try {
        document.getElementById(divFilter).style.display = 'block';
    } catch(Error) {}
    RemoveFirstItem(ddlName);
    try {
        document.getElementById(divPhoneName).innerHTML = '';
        document.getElementById(imgManufacture).src = pathBase + 'style/images/manufactures/pixel.gif';
        document.getElementById(imgCarrier).src = pathBase + 'style/images/operadoras/logo_'+  CarrierId + '.gif';
    } catch(Error) {}
    var tb = MasterPageItem.ListManusfacture(CarrierId);
    LoadManufacture_CallBack(tb, IdName);
}
function LoadManufacture_CallBack(response, idName) {
    if (response.error != null) {
        alert(response.error);
        return;
    }
    var states = response.value;
    if (states == null || typeof(states) != "object") {
        return;
    }
    var statesList = document.getElementById(idName);
    statesList.options.length = 0;
    statesList.options[statesList.options.length] = new Option('Fabricante', '-1');
    for (var i = 0; i < states.Rows.length;++i) {
        statesList.options[statesList.options.length] = new Option(states.Rows[i].Fabricante, states.Rows[i].IdFabricante);
    }
}

function ValidatePhoneNumber(ddd, phoneNumber, lblError) {
    var ddd = document.getElementById(ddd);
    var tel = document.getElementById(phoneNumber);
    var msisdn = ddd.value + tel.value;
    var aux = tel.value.substring(0, 1);
    var lblResultValidation = document.getElementById(lblError);
    if (msisdn.length < 10) 
    {
        lblResultValidation.innerHTML = "O número do telefone deve possuir 10 digitos.";
    } 
    else 
    {
        if (parseInt(aux) < 6) 
        {
            lblResultValidation.innerHTML = "Este número não é um celular válido.";
        } 
        else 
        {
            lblResultValidation.innerHTML = "";
        }
        if(isNaN(msisdn))
        {
          ddd.value = '';
          tel.value = '';
          lblResultValidation.innerHTML = "Número inválido. Digite novamente!";
        }
    }
}
function popAdult(url) {
    document.getElementById("btnAdultConfirm").href = 'javascript:window.location="' + url + '"';
    document.getElementById("btnAdultCancel").href = "javascript:esconderboxCel('boxAdult');";
    loadFunctions('boxAdult');
    
    return false;
}
function popAdultItemType(url) {
    popAdult(url);
}
function anchor()
{
  window.scroll(0, 0);
}
function anchort(destination) {
    var clearUrl = location.href.replace(/#Top/gi, "");
    clearUrl = clearUrl.replace(/#cel/gi, "");
    if (destination != '#cel')
        location.href = clearUrl + destination;
    else {
        location.href = clearUrl + destination;
    }
}
function closeBoxPhone() {
    try
    {
        var elements = document.getElementsByTagName("select");
        for(var i = 0; i < elements.length; i++)
        {
            if(elements[i].id.indexOf('Pane') < 0)
                elements[i].style.display = 'block';
        }
    }
    catch(e)
    {}

    MasterPageItem.closeBoxPhone();
    esconderboxCel('boxCel');
}
function LoadBoxCel() {
    try
    {
        var elements = document.getElementsByTagName("select");
        for(var i = 0; i < elements.length; i++)
        {
            if(elements[i].id.indexOf('Pane') < 0)
                elements[i].style.display = 'none';
        }
    }
    catch(e)
    {}
    loadFunctions('boxCel');
//    var CarrierCurrent = MasterPageItem.GetCarrier().value;
//    if(CarrierCurrent != '-1'){ 
//    document.getElementById('ctl00_CarrierPane').value = CarrierCurrent;
//    CarrierPaneUpdate(CarrierCurrent,'ctl00_ManufacturePane',true,'ctl00_CarrierPane','listaModelos','imgCarrierPop','imgManufacturePop','filtroModeloPop');
//    }
    
}
function MM_openBrWindow(theURL, winName, features) {
    if (theURL != '')
      window.open(theURL, winName, features);
}

function setPassword(objPasswd){
   uscWizardStep2.setPasswd(objPasswd.value);
}

function SaleByRR(objSaleByRR,idCheck){
  uscWizardStep2.SaleByPM(objSaleByRR);
  
  if(!document.getElementById(idCheck).checked)
  {  
    document.getElementById("ctl00_cphHome_uscstep2_uscWizardStep2_unSubscribed1_login_lnkNextStep2").href = "javascript:openPopUpGeneric('Termo de adesão', 'Você precisa concordar com o TERMO DE ADESÃO para prosseguir','popUpGeneric');";
  }
  else
  {
    document.getElementById("ctl00_cphHome_uscstep2_uscWizardStep2_unSubscribed1_login_lnkNextStep2").href = 'javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphHome$uscstep2$uscWizardStep2_unSubscribed1$login$lnkNextStep2", "", true, "step2", "", false, true))';
  }  
}

function SaleByRRObj(objSaleByRR){
 uscWizardStep2.SaleByPM(objSaleByRR.checked);
}

function setPhoneModel(idap) {
  var phoneList = document.getElementsByName("PhonemodelsList");
  for(var i=0; i < phoneList.length; i++)
  {
    document.getElementById("divAparelho_"+phoneList[i].id).className = "modeloCelular";
  }  
  document.getElementById("divAparelho_"+idap.id).className = "Selected";  
  MasterPageItem.setPhoneModel(idap.id).value;
}

function RedirectParameters(idap, idpack, idCarrier) {
    var sign = Request("sign");
    var carrierID = idCarrier;
    var ddd = document.getElementById('ctl00_cphHome_dddSelect');
    var tel = document.getElementById('telSelect');
    var aux = tel.value.substring(0, 1);
    var msisdn = ddd.value + tel.value;
    var carrier = document.getElementById('ctl00_cphHome_CarrierPane');
    if (msisdn.length < 10 || parseInt(aux) < 6) 
    {
        if (parseInt(aux) < 6) 
        {
            document.getElementById("ctl00_cphHome_lblValidation").innerHTML = "Este número não é um celular válido.";
        } 
        else 
        {
            document.getElementById("ctl00_cphHome_lblValidation").innerHTML = "O número do telefone deve possuir 10 dígitos.";
        }
    } 
    else 
    {
       
        var password;
        if (!sign) 
        {
            password = document.getElementById('ctl00_cphHome_ctl00_txtPassword').value;
            if (password != '') 
            {
                var resultValidation = _Default.VerifyCodeInserted(msisdn, carrierID, password).value;
                if (resultValidation != 'true') {
                    openPopUpGeneric("Oops!!", "Senha inválida. Tente novamente." + "", 'popUpGeneric');
                } 
                else 
                {
                    _Default.CreateSessionLogin(msisdn);
                    window.location = 'loadParameters.aspx?idp=' + idpack + '&id' + '&msisdn=' + msisdn + '&IC=' + carrierID;
                }
            } 
            else 
            {
                openPopUpGeneric("Oops!!", "Insira sua senha. Tente novamente." + "", 'popUpGeneric');
            } 
        } 
        else 
        {
          url = 'loadParameters.aspx?idp=' + idpack + '&idap=' + idap + '&id' + '&msisdn=' + msisdn + '&IC=' + carrierID;
          _Default.SetChannel(carrierID);
          var isSubscriber = _Default.IsSubscriber(msisdn).value;
          
            if(isSubscriber)
            {                     
              LoadPopUpPassword(url,carrierID,msisdn);
            }
            else
            {
              window.location = url;
            }
        }
    }
}


function LoadPopUpPassword(url,selected,msisdn)
{
  //ValidatePassword(url,idTxtPassword,selected,msisdn);
  document.getElementById('lnkValidate').href = "javascript:ValidatePassword('" + url + "','txtPassSelectPhone','" + selected + "','" + msisdn + "')";
  document.getElementById('lnkSend').href = "javascript:SendSMS('" + selected + "','" + msisdn + "')";
  loadFunctions('popUpSelectPhone');
}

function ValidatePassword(url,idTxtPassword,selected,msisdn,isValidate)
{
    var password = document.getElementById(idTxtPassword).value;
    var lblError = document.getElementById('lblErrorPassword');
    
    var resultValidation = _Default.VerifyCodeInserted(msisdn, selected, password).value;
    if (resultValidation != 'true') 
    {
        lblError.innerHTML =  'Senha inválida. Tente novamente.';
    } 
    else 
    {
        _Default.CreateSessionLogin(msisdn);
        window.location = url;
    }
}

function SendSMS(selected,msisdn)  
{
    var status = document.getElementById('statusPassword');
    status.innerHTML = '<img id="loadAjax" src="' + pathBase + 'style/images/ajax-loader.gif"/>';
    var result = _Default.SendCodeNewUser(msisdn,selected);
    status.innerHTML = '<!--' + result + '--->' + 'A Senha foi enviada para o número '+ msisdn;      
}

function UpdatePhone(idAp) {
    var carrier = document.getElementById('ctl00_cphHLigthIGPromo_uscHLigthIGPromo_CarrierPane');
    var selected = carrier.options[carrier.selectedIndex].value;
    if (RedirUrl == '') {
        window.location = pathBase + 'updatePhone.aspx?idAp=' + idAp + '&IC=' + selected;
    } else {
        window.location = pathBase + 'updatePhone.aspx?idAp=' + idAp + '&IC=' + selected + RedirUrl;
    }
}
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 RedirectBuyCredit() {
    document.location.reload(true);
}

function AlternateDiv(divNone, divBlock) {
    document.getElementById(divNone).style.display = 'none';
    document.getElementById(divBlock).style.display = 'block';
}

function openURLLocal(urlLocal, winName, params) {
    var url = window.location;
    var location = 'http://' + url.host + '/' + urlLocal;
    MM_openBrWindow(location, winName, params);
}

function LoadFunctionClearDiv() {
    document.getElementById('popup-content-center').style.display = 'block';
    var lblMessage = document.getElementById("status");
    if (lblMessage != null) {
        lblMessage.innerHTML = "";
    }
    loadFunctions('boxAddCredit');
}

function LoadFunctionAddCredit() {
    document.getElementById('popup-content-center').style.display = 'block';
    var lblMessage = document.getElementById("status");
    if (lblMessage != null) {
        lblMessage.innerHTML = "";
    }
    loadFunctions('boxAddCreditItem');
}


var ListNewsFrew = new Array();
function LoadInnerSelectFreeNews(index, Idcategory) {
    if (Idcategory != "") {
        var innerIndex = index;
        var nextIndex = innerIndex + 1;
        var innerDiv = document.getElementById('SelectNext' + innerIndex);
        var innerHTML;
        var tabNews;
        if (uscFreeNews.subCategoryNews(Idcategory).value) {
            tabNews = uscFreeNews.Load(Idcategory);
            innerHTML = '<label>Categoria:</label><select id="select' + innerIndex + '" onchange="LoadInnerSelectFreeNews(' + innerIndex + ',this.value)">';
            innerHTML += '<option value="-1">Selecione Categoria</option>';
            for (var i = 0; i < tabNews.value.Rows.length; i++) {
                innerHTML += '<option value="' + tabNews.value.Rows[i].IdCategory + '">' + tabNews.value.Rows[i].Category + '</option>';
            }
            innerHTML += '</select><div id="SelectNext' + nextIndex + '">';
            innerHTML += '</div>';
        } else {
            tabNews = uscFreeNews.LoadChannels(Idcategory);
            innerHTML = '<label>Canal</label><select id="select' + innerIndex + '" onchange="setChannelFreeNews(this.value,' + innerIndex + ')">';
            innerHTML += '<option value="-1">Selecione um Canal</option>';
            for (var i = 0; i < tabNews.value.length; i++) {
                innerHTML += '<option value="' + tabNews.value[i].IdDistributionChannelFormatPricePlan + '">' + tabNews.value[i].Name + '</option>';
            }
        }
        innerDiv.innerHTML = innerHTML;
    }
}
function CancelSign(IdDistributionChannel,paymentType) {
    document.getElementById("lblStatusCancel").innerHTML ="";
    var status = uscFreeNews.CancelSign(IdDistributionChannel,paymentType).value;
    if (!status) {
        document.getElementById("lblStatusCancel").innerHTML = "Não foi possivel realizar alteração";
    } else {
        window.location = "freeNews.aspx";
    }
}

function setChannelFreeNews(idChannel, next) {
    if (idChannel != "") {
        var Description = uscFreeNews.DescriptionNews(idChannel);
        var inennerHTML = "<p class=\"titulo\">Descrição</p>";
        inennerHTML += "<p><label id=\"lblTitle\">" + Description.value[0] + "</label></p><br>";
        inennerHTML += "<label>" + Description.value[1] + "<label>";
        document.getElementById("disclaimer" + next).innerHTML = inennerHTML;
    }
}
function sign(IdSelect, paymentType) {
    if (document.getElementById("select" + IdSelect).value != "-1") {
        window.location = "Sent.aspx?news=true&format=SMS&carrier=" + uscFreeNews.Carrier().value + "&msisdn=" + uscFreeNews.Phone().value + "&iddc=" + document.getElementById("select" + IdSelect).value + '&paymentType=' + paymentType;
    } else {
        loadFunctions('ChannelNotFound');
        
    }
}
function alterSign(IdDistributionChannel, IdSelect, paymentType) {
   document.getElementById("lblStatusAlter").innerHTML = "";
   var status = uscFreeNews.CancelSign(IdDistributionChannel, paymentType).value;
    if (status) {
        window.location = "Sent.aspx?news=true&format=SMS&carrier=" + uscFreeNews.Carrier().value + "&msisdn=" + uscFreeNews.Phone().value + "&iddc=" + document.getElementById("select" + IdSelect).value + "&rollback=" + IdDistributionChannel + '&paymentType=' + paymentType;
    } else {
        document.getElementById("lblStatusAlter").innerHTML = "Não foi possivel realizar alteração";
    }
}
function showPopUp(popUp, IdSelect, IdDistributionFormatPlacePlan, PaymentType) {
    if (document.getElementById("select" + IdSelect).value != "-1") {
        document.getElementById("lnkAlter").href = "javascript:alterSign('" + IdDistributionFormatPlacePlan + "','" + IdSelect +"','"+ PaymentType+"')";
        loadFunctions(popUp);
        
    } else {
        loadFunctions('ChannelNotFound');
        
    }
}
function CancelSignByIdDistribuitionChannelFormatPricePlan(IdNews,paymentType) {
    document.getElementById("lnkCancel").href = "javascript:CancelSign('" + IdNews + "','"+paymentType+ "')";
    loadFunctions('cancelNews');
    
}
function openPopUpGeneric(title, description, divId) {
    document.getElementById('genericTitle').innerHTML = title;
    document.getElementById('genericDescription').innerHTML = description;
    document.getElementById('closeGeneric').href = "javascript:esconderboxCel('" + divId + "')";
    loadFunctions(divId);
}
function LoadURLHttpRequest(url, divName) {
    var xmlhttp = false;
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch(e) {
            xmlhttp = false;
        }
    } 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="'+ pathBase + 'style/images/ajax-loader.gif"/>';
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    document.getElementById(divName).innerHTML = xmlhttp.responseText;
                }
            }
        };
        xmlhttp.open("GET", url, true);
        xmlhttp.send("");
    } else {
        alert(".Your browser does not support XMLHTTP.");
    }
}

var IE = document.all ? true: false;
if (!IE) {
    document.captureEvents(Event.MOUSEMOVE);
}
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
    try {
        if (IE) {
            tempX = event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
            tempY = event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
        } else {
            tempX = e.pageX;
            tempY = e.pageY;
        }
        tempY -= 50;
        tempX += 15;
        if (tempX < 0) {
            tempX = 0;
        }
        if (tempY < 0) {
            tempY = 0;
        }
        Tooltip.style.top = tempY + 'px';
        Tooltip.style.left = tempX + 'px';
    } catch(e) {}
    return true;
}
function Tip(body) {
  var Tooltip = document.getElementById('Tooltip');
    if (Tooltip.style.display != 'block') {
        Tooltip.innerHTML = body;
    }
    Tooltip.style.display = 'block';
}
function UnTip() {
    var Tooltip = document.getElementById('Tooltip');
    Tooltip.style.display = 'none';
    Tooltip.innerHTML = '';
}
document.onmousemove = getMouseXY;


function cancelPackage(idChb, idStatus) {
    var chbConfirm = document.getElementById(idChb).checked;

    if (chbConfirm) {

        if (uscCancelPackage.cancelPackage().value) {
            esconderboxCel('cancelPackage');
            loadFunctions('confirm-cancelPackage');
            anchor('#Top');
        }
        else {
            esconderboxCel('cancelPackage');
            openPopUpGeneric("Cancelar Assinatura", "Erro ao cancelar a assinatura. Tente novamente mais tarde.", 'popUpGeneric')
            //loadFunctions('error-cancelPackage'); 
            anchor('#Top');
        }
    }
    else {
        document.getElementById(idStatus).innerHTML = '<span id="lblUnchecked">Você precisa clicar acima para concordar com o cancelamento da assinatura.</span>';
    }
}

function LoadPopupHelp(param)
{
  var divName = 'divHelpFlash';
  var url = pathBase + 'helpFlash.aspx?param=' + param;
  LoadURLHttpRequest(url,divName);
  loadFunctions(divName); 
}

//////////////////////////////////////////////////////  SMS  //////////////////////////////////////////////////////////////////////
var xmlhttp;
var now = new Date();
var textCustom;
var idDistributionChannel;
   
function loadPreview()
{
  loadXMLDoc(pathBase + "MMS/cardPreview.aspx");
}

function LoadPreviewNews(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();
    
  if (xmlhttp.readyState==4)
  {
    if (xmlhttp.status==200)
    {
      document.getElementById(pathBase +  "MMS/cardPreview").innerHTML = xmlhttp.responseText;
    }
    else
       {
          alert("Problem retrieving XML data");
       }
  }
    xmlhttp.onreadystatechange = XmlHttp_StateChange;  
    xmlhttp.open("GET", url, true);    
    xmlhttp.send("");
  }
  else
  {
    alert("Your browser does not support XMLHTTP.");
  }
}

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) 
{
  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 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 LoadInnerSelectNews(index,Idcategory)
  {
      if(Idcategory!=""){
        var innerIndex = index + 1;
        var nextIndex = innerIndex + 1;        
        var innerDiv = document.getElementById('SelectNext' + innerIndex);
        var innerHTML;
        var tabNews;
                if(news.subCategoryNews(Idcategory).value)
                {
                  tabNews = news.Load(Idcategory);
                
                   innerHTML = ' <label>Categoria:</label> <select id="select' + innerIndex + '" onchange="LoadInnerSelectNews(' + innerIndex +  ',this.value)">';
                   innerHTML  += '<option value="-1">Selecione Categoria</option>';
                    for(var i=0;i<tabNews.value.Rows.length;i++)        
                    {
                        innerHTML  += '<option value="'+tabNews.value.Rows[i].IdCategory+'">'+tabNews.value.Rows[i].Category+'</option>';
                    }                     
                  innerHTML  += '</select><div id="SelectNext' + nextIndex + '">';
                  innerHTML  += '</div>';
                }
                else
                {
                   tabNews =   news.LoadChannels(Idcategory);
                   innerHTML = ' <label>Canal:</label> <select id="select' + innerIndex + '" onchange="setChannelPageNews(this.value)">';
                   innerHTML  += '<option value="-1">Selecione um Canal</option>';
                    for(var i=0;i<tabNews.value.Rows.length;i++)        
                    {
                        innerHTML  += '<option value="'+tabNews.value.Rows[i].IdDistributionChannelFormatPricePlan+'">'+tabNews.value.Rows[i].Name+'</option>';
                    }                     
                  innerHTML  += '</select><div id="SelectNext' + nextIndex + '">';
                  innerHTML  += '</div>'; 
                }     
                
                document.getElementById("ctl00_cphHome_ddlCarrier").value = -1;
                document.getElementById("disclaimer").innerHTML = "";
        
        innerDiv.innerHTML = innerHTML;  
        }
    
  }
  
  function getPrice(idCarrier) {
      try {
          var price = "";//news.getPriceCredit(idCarrier).value;
          var inennerHTML = "<br/><label>" + price + "</label>";
          document.getElementById("priceCredit").innerHTML = inennerHTML;
          document.getElementById('ctl00_cphHome_txtddd').focus();
      }
      catch (Error) {
      }
  }
  
  
 function setChannelPageNews(idChannel)
  {
    if(idChannel!=""){ 
           var Description = news.DescriptionNews(idChannel);						
           var inennerHTML = "<label class=\"lblTitle\">"+Description.value[0]+"</label>";
           inennerHTML+= "<label class=\"lblDescription\">"+Description.value[1]+"<label>";
           inennerHTML+= "<label class=\"lblSendNumber\">"+Description.value[2]+"<label>";
           inennerHTML+= "<label id=\"priceCredit\" class=\"lblPriceCredit\"></label>";  
           document.getElementById("disclaimer").innerHTML =inennerHTML ;
           document.getElementById("ctl00_cphHome_ddlCarrier").value = -1;
     }     
  }
  
function ValidatePhoneNumber(txtValue)
{
    var ddd = document.getElementById('ctl00_cphHome_dddSelect');
    var tel = document.getElementById('telSelect');
    var msisdn = ddd.value + tel.value;
    var aux = tel.value.substring(0,1); 
    if(msisdn.length < 10)
    {
       if(document.getElementById('ctl00_cphHome_ddlCarrier').value != "-1")
       {
          if(ddd.value.length == 2){
          document.getElementById("lblrespects").innerHTML = "O n&uacute;mero do telefone deve <br/> possuir 8 digitos.";
          return false;
          }
          else
          {
           document.getElementById("lblrespects").innerHTML ="O n&uacute;mero do ddd <br/> &eacute; Inv&aacute;lido";
           return false;
          }  
        }
        else
        {
            document.getElementById("lblrespects").innerHTML = "Selecione a operadora.";
            return false;
        }
    }
    else
    {
        if(aux <6 || aux > 9)
        {
            document.getElementById("lblrespects").innerHTML = "Este n&uacute;mero n&atilde;o &eacute; um<br/> celular v&aacute;lido.";
            return false;   
        } 
        else
        {
            document.getElementById("lblrespects").innerHTML = "";
            return true;
        }       
    }
}

function ValidatePhoneNumberToNews(txtValue)
{
    var ddd = document.getElementById('ctl00_cphHome_txtddd');
    var msisdn = ddd.value + txtValue;
    var aux = txtValue.substring(0,1); 
    if(msisdn.length < 10)
    {
       if(document.getElementById('ctl00_cphHome_ddlCarrier').value != "-1")
       {
          if(ddd.value.length == 2){
          document.getElementById("lblrespects").innerHTML = "O n&uacute;mero do telefone deve <br/> possuir 8 digitos.";
          return false;
          }
          else
          {
           document.getElementById("lblrespects").innerHTML ="O n&uacute;mero do ddd <br/> &eacute; Inv&aacute;lido";
           return false;
          }  
        }
        else
        {
            document.getElementById("lblrespects").innerHTML = "Selecione a operadora.";
            return false;
        }
    }
    else
    {
        if(aux <6 || aux > 9)
        {
            document.getElementById("lblrespects").innerHTML = "Este n&uacute;mero n&atilde;o &eacute; um<br/> celular v&aacute;lido.";
            return false;   
        } 
        else
        {
            document.getElementById("lblrespects").innerHTML = "";
            return true;
        }       
    }
}

  
function sendCodeValidation(idLblError)
{
    var msisdn = document.getElementById("ctl00_cphHome_txtddd").value + document.getElementById("ctl00_cphHome_txtnumberPhone").value;	 
	  if(VerifyNews(msisdn,idLblError))
	  {
	      notVisibilityDropDown();
	      var thisPackageSign = news.ThisPackageSign(msisdn).value;
	      if(thisPackageSign)    
	      { 
	          loadFunctions('CodeValidation');	          
	      }
	      else  
		    {      
		      loadFunctions('confirm-NotSign');
		    }	
	 }	   
}

function CloseNotSign(divName)
{
    VisibilityDropDown();
    esconderboxCel(divName);
}

function BackCodeValidation(divName)
{
    VisibilityDropDown();
    esconderboxCel(divName);
}


function notVisibilityDropDown()
{
	  try{
			  if(document.all)
			  {
			  document.getElementById("ctl00_ddlOtherChannel").style.visibility = 'hidden';
			  document.getElementById("ctl00_cphHome_ddlNewSMS").style.visibility = 'hidden';	  
			  document.getElementById("ctl00_cphHome_ddlCarrier").style.visibility = 'hidden';
			  document.getElementById("select3").style.visibility = 'hidden';
			  }
			 else
			 {
			  document.getElementById("ctl00_ddlOtherChannel").style.display = 'none';
			  document.getElementById("ctl00_cphHome_ddlNewSMS").style.display = 'none';	  
			  document.getElementById("ctl00_cphHome_ddlCarrier").style.display = 'none';
			  document.getElementById("select3").style.display = 'none';
			 }
	  }
	  catch(Error)
	  {
		  document.getElementById("select2").style.display = 'none';
	  }
}


function VisibilityDropDown()
{
	try{
	if(document.all)
	{
		document.getElementById("ctl00_ddlOtherChannel").style.visibility = 'visible';
		document.getElementById("ctl00_cphHome_ddlNewSMS").style.visibility = 'visible';	
		document.getElementById("ctl00_cphHome_ddlCarrier").style.visibility = 'visible';	
		document.getElementById("select3").style.visibility = 'visible';
	}	
	else
	{
			  document.getElementById("ctl00_ddlOtherChannel").style.display = 'block';
			  document.getElementById("ctl00_cphHome_ddlNewSMS").style.display = 'block';	  
			  document.getElementById("ctl00_cphHome_ddlCarrier").style.display = 'block';
			  document.getElementById("select3").style.display = 'block';	
	}
	 
	}
	catch(Error)
	{
			document.getElementById("select2").style.display = 'block';
	}

}

function closeboxPartners()
{
	esconderboxCel('boxPartnersIG');	
	VisibilityDropDown();
}

function closeBoxSign()
{
		esconderboxCel('CodeValidation');
		VisibilityDropDown();
}

function validateCode()
{
  var code = document.getElementById('txtCode').value;
  var carrierId = document.getElementById("ctl00_cphHome_ddlCarrier").value;
  var msisdn = document.getElementById("ctl00_cphHome_txtddd").value + document.getElementById("ctl00_cphHome_txtnumberPhone").value;
  var result = uscValidationCode.CheckCodeInserted(code,carrierId,msisdn);
 
  if(result.value)
   signPaid();    
  else
      document.getElementById('lblMessagecode').innerHTML = "C&oacute;digo de valida&ccedil;&atilde;o incorreto. Insira novamente.";
}

function VerifyNews(msisdn,idLblError)
{
  try {
    
    if(document.getElementById("ctl00_cphHome_ddlNewSMS").value!="") {

      if(document.getElementById("select2").value!="-1") {
        
        if(document.getElementById("ctl00_cphHome_ddlCarrier").value == "-1") {
          document.getElementById("lblrespects").innerHTML = 'Informe sua operadora.';
          return false;
        }                 
        if(msisdn.length < 10) {
            document.getElementById("lblrespects").innerHTML = 'O número do celular deve possuir 10 dígitos.';
          return false;
      }
      return ValidatePhoneNumberToNews(msisdn.substr(2,(msisdn.length -1)));       
      }
      else {
          document.getElementById("lblrespects").innerHTML = 'Escolha pelo menos um canal de notícia.';
        return false;
      }    
    }
    else {
        document.getElementById("lblrespects").innerHTML = 'Escolha a categoria.';
      return false;
    }
  }
  catch(Error)
  {
      document.getElementById("lblrespects").innerHTML = 'Escolha a categoria.';
    return false;
  }
}


function SendSMSCode()
{
  var carrierId = document.getElementById("ctl00_cphHome_ddlCarrier").value;
  var msisdn = document.getElementById("ctl00_cphHome_txtddd").value + document.getElementById("ctl00_cphHome_txtnumberPhone").value;
 
    var result = uscValidationCode.SendCodeValidation(carrierId,msisdn).value;
    if(result)  
    {
     document.getElementById("lblMessagecode").innerHTML = 'Mensagem Enviada com sucesso.';
    }
    else
    {
       document.getElementById("lblMessagecode").innerHTML = 'Erro ao enviar a mensagem.';
    }
} 

function popAdult(url)
{
  document.getElementById("btnAdultConfirm").href ='javascript:window.location ="' + url+'"';
  document.getElementById("btnAdultCancel").href = "javascript:esconderboxCel('boxAdult');";  
  loadFunctions('boxAdult');
  anchor('#Top');   
}

function redirectChannel(url)
{
   window.open(url,'','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}

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;
}

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];
    }
}

//////////////////////////////////////////////////////  MMS  //////////////////////////////////////////////////////////////////////

function loadXMLDocMMS(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_StateChangeMMS;
        xmlhttp.open("GET", url, true);
        xmlhttp.send("");
      
    }
    else {
        alert("Your browser does not support XMLHTTP.");
    }
}

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 selectItem(itemTypeId, idItem) {
    idt = itemTypeId;
    id = idItem;
    loadXMLDocMMS(pathBase +  "MMS/cardPreview.aspx?idt=" + idt + "&id=" + id);
    window.scrollTo(0,100);
}

function redirectNewsMMS(distribuitionChannelID, categoryID ) {
    document.getElementById("lnkPopUpNextNews").href = pathBase+"noticia/assinar/"+distribuitionChannelID+"/Tc";
    loadFunctions('boxCardMMS');
    document.getElementById("divLnkNews").style.display = 'block';
    document.getElementById("divLnkCardMMS").style.display = 'none';  
}

function redirectSelectItem(itemTypeId, idItem) {
    idt = itemTypeId;
    id = idItem;
    loadXMLDocMMS(pathBase +  "MMS/cardPreview.aspx?idt=" + idt + "&id=" + id);
    setTimeout('window.location = "'+ pathBase +'MMS/itens/4/-1"',100);
}

function selectCard(cardId, ImageId, AudioId, TextId) {
    loadXMLDocMMS(pathBase +  "MMS/cardPreview.aspx?idt=29&id=" + cardId + "&imageId=" + ImageId + "&audioId=" + AudioId + "&textId=" + TextId);
    if(!(window.location.toString().toLowerCase().indexOf("itemlist") > 0) && !(window.location.toString().toLowerCase().indexOf("mms/itens") > 0))
      {  setTimeout('window.location = "'+ pathBase +'MMS/itens/29/-1";',100);}
      else{window.scrollTo(0,100);}
  
}

 function settingTextCustom()
      {
        idt = 28;
        textCustom = this.document.getElementById("ctl00_cphHome_ctl01_textsms").value;
        uscTextInput.settingTextCustom(textCustom);
        loadPreviewList(28);
      }
      
 function loadPreviewList(itemtype) {
    loadXMLDocMMS(pathBase +  "MMS/cardPreview.aspx?ItemType=" + itemtype);    
}




function XmlHttp_StateChangeMMS() {
 
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            try {                
                document.getElementById("cardPreview").innerHTML = xmlhttp.responseText;
            }
            catch (err) {            
            }
        }
        else {
            alert("Problem retrieving XML data");
        }
    }
}

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 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) {
    var url = '/noticia/' + iddc + '/' + idc + '/' + store;
    window.location = url;
}

// --- 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');
}




