// váriaveis globais //
var tms = new Array()
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

// esta função abre um canal para as chamadas Ajax //
function getRequestXml(){
    if(window.XMLHttpRequest) { // Mozilla, Safari,...
        return new XMLHttpRequest();
        
        if (http_request.overrideMimeType) http_request.overrideMimeType('text/xml');
        
    }else if (window.ActiveXObject) { // IE
        try{
            return new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            try{
                return new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e){
            }
        }
    }

    if (!http_request) {
        alert('Sem suporte há esta funcionalidade');
        return false;
    }
}

// esta função é para carregar combobox //
function ajax_destaqueProgramacao(genero,div)
{
    // instancia objeto que irá fazer a chamado da página //
    xmlHttp = getRequestXml();

    url = "/ajax/destaqueProgramacao/destaqueHome.aspx?genero="+genero;            

    // chamada //    
    xmlHttp.onreadystatechange = function() {ajax_destaqueProgramacao_carregando(xmlHttp, div);}
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

// método complementar ^ //
function ajax_destaqueProgramacao_carregando(xmlHttp, div){
    if (xmlHttp.readyState == 4){
        if (xmlHttp.status == 200){
            div.innerHTML = xmlHttp.responseText;
        }
    }
}

// esta função é para carregar combobox //
function ajax_combo(url,objetoCboDest)
{
    // instancia objeto que irá fazer a chamado da página //
    xmlHttp = getRequestXml();
            
    // chamada //    
    xmlHttp.onreadystatechange = function() {ajax_carregando(xmlHttp, objetoCboDest);}
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
}

// esta função é para carregar combobox //
function ajax_combo_sem_Selecione(url,objetoCboDest)
{
    // instancia objeto que irá fazer a chamado da página //
    xmlHttp = getRequestXml();
            
    // chamada //    
    xmlHttp.onreadystatechange = function() {ajax_carregando_sem_Selecione(xmlHttp, objetoCboDest);}
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
}




// método complementar ^ //
function ajax_carregando(xmlHttp, objetoCboDest){
    var docEle;
    if (xmlHttp.readyState == 4){
        if (xmlHttp.status == 200){
            // Lê o xml com o DOM
            if (window.ActiveXObject){
                xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
                xmlDoc.async = false;
                xmlDoc.loadXML(xmlHttp.responseText);
                docEle = xmlDoc.documentElement;
                // alert(docEle.selectSingleNode("registro/id"));
            }else{
                var parser = new DOMParser();
                xmlDoc = parser.parseFromString(xmlHttp.responseText,"text/xml");
                // obtem o documento de retorno //    
                docEle = xmlDoc.documentElement;
            }  

            // registros //
            arrId = docEle.selectNodes('registro/id') ;
            arrDesc = docEle.selectNodes('registro/desc') ;
            qtdeReg = arrId.length;
            // alert(arrId.length);
            
            // remove os dados anteriores //
            removeComboAll(objetoCboDest);
            
            // adiciona o [selecione] no combo //
            addCombo(objetoCboDest, '[Selecione]', '0' );
                        
            // percorre os dados do XML //        
            for(i=0; i < qtdeReg; i++)
            {
                // alert(arrDesc[i].childNodes[0].nodeValue);
                addCombo(objetoCboDest, arrDesc[i].childNodes[0].nodeValue, arrId[i].childNodes[0].nodeValue );
            }
            
        }
    }
}

// método complementar ^ //
function ajax_carregando_sem_Selecione(xmlHttp, objetoCboDest){
    var docEle;
    if (xmlHttp.readyState == 4){
        if (xmlHttp.status == 200){
            // Lê o xml com o DOM
            if (window.ActiveXObject){
                xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
                xmlDoc.async = false;
                xmlDoc.loadXML(xmlHttp.responseText);
                docEle = xmlDoc.documentElement;
                // alert(docEle.selectSingleNode("registro/id"));
            }else{
                var parser = new DOMParser();
                xmlDoc = parser.parseFromString(xmlHttp.responseText,"text/xml");
                // obtem o documento de retorno //    
                docEle = xmlDoc.documentElement;
            }  

            // registros //
            arrId = docEle.selectNodes('registro/id') ;
            arrDesc = docEle.selectNodes('registro/desc') ;
            qtdeReg = arrId.length;
            // alert(arrId.length);
            
            // remove os dados anteriores //
            removeComboAll(objetoCboDest);
            
            // adiciona o [selecione] no combo //
            addCombo(objetoCboDest, '[Selecione]', '', '' );
                        
            // percorre os dados do XML //        
            for(i=0; i < qtdeReg; i++)
            {
                // alert(arrDesc[i].childNodes[0].nodeValue);
                addCombo(objetoCboDest, arrDesc[i].childNodes[0].nodeValue, arrId[i].childNodes[0].nodeValue );
            }
            
        }
    }
}



// Esta função insere novos options na combo que passarem pelo objeto //
function addCombo(objeto,texto,valor){
	objeto.options[objeto.length] = new Option(texto,valor);
}

// esta função remove o option de um combo passado pelo objeto //
function removeCombo(objeto,item){
	try{
		objeto.remove(item);
	}catch(e){
		alert("Selecione um item no combo "+objeto.name);
	}
}

// esta função insere novos options na combo que passarem pelo objeto de uma matrix passado por lista //
function addComboAll(objeto,lista){
	var i;
	for (i=0; i<lista.length; i++){
		addCombo(objeto,lista[i].chave,lista[i].valor);
	}
}

// esta função remove todos os options de um combo passado pelo objeto //
function removeComboAll(objeto){
	while (objeto.length > 0){
		removeCombo(objeto,0);
	}
}

// esta função procura o valor do combobox para deixar o valor como Selected //
function comboSelected(objeto,valor){
    
    if(valor == ''){
        objeto.selectedIndex = 0;
        return;
    }
    
    for (i=0; i<objeto.length; i++){
        objeto.selectedIndex = i;
        if(objeto.options[i].value == valor)
            break;
    }
}

function getNoAr(Tipo,abrevCanal,canal_id, horario, id_destaque){
    document.form1.Tipo.value = Tipo;
    document.form1.AbrevCanal.value = abrevCanal;
    document.form1.canal_id.value = canal_id;
    document.form1.Horario.value = horario;
    document.form1.action = "/Telas/Detalhes/detalhe_noar.aspx?Id_Destaque=" + id_destaque;
    document.form1.submit();
}

// esta função executa um Auto-TAB //
function autoTab(input,len,e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
}

function containsElement(arr, ele) {
    var found = false, index = 0;
    
    while(!found && index < arr.length)
        if(arr[index] == ele)
            found = true;
        else
            index++;
    
    return found;
}

function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
}

function trim(texto)
{
texto = ltrim(texto);
texto = rtrim(texto);
return texto;
}

function ltrim(texto)
{
var array_texto = texto.split('');
var i = 0;
var verificador = ' '; 
while(verificador == ' ' && i< texto.length){
    verificador = array_texto[i]
    i++;
}
texto = texto.substr(i-1,texto.length);
return texto;
}

function rtrim(texto){
var array_texto = texto.split('');
var i = texto.length -1;
var verificador = ' '; 
while(verificador == ' ' && i >= 0){
    verificador = array_texto[i]
    i--;
}
texto = texto.substr(0,i+2);
return texto;
}

 function $(id) 
 { 
	o = document.getElementById(id); 
	if (o == null) 
	{ 
		alert('JS-Error: O Elemento ' + id + ' não foi encontrado.') 
	} 
	return o; 
 } 


//exibe os campos SELECT da página
function MostraCombo()
{
    if (document.getElementById('LoginRelogio1_ddlTipoLogin') != null)
    {
        document.getElementById('LoginRelogio1_ddlTipoLogin').style.visibility = "visible";
    }
}

//oculta campos SELECT da página
function EscondeCombo()
{
    if ( document.getElementById('LoginRelogio1_ddlTipoLogin') != null)
    {
        document.getElementById('LoginRelogio1_ddlTipoLogin').style.visibility = "hidden";
    }
}


// Mostra o submenu no mouseover
function over(n){	
	if(navigator.appName.toLowerCase() == ('netscape')) {
		if(typeof(tms[n])!="undefined")clearTimeout(tms[n])
			document.getElementById("s"+n).style.display="block";
	}else{
		if(typeof(tms[n])!="undefined")clearTimeout(tms[n])
			document.getElementById("s"+n).style.display="block";
	}
	EscondeCombo();
	
}

//Esconde o submenu no mouseout
function out(n){
	tms[n] = setTimeout('document.getElementById("s'+n+'").style.display="none"',200);
	//regule o tempo aqui!//
	MostraCombo();
}





//função adiciona Favoritos
function AdicionarFavoritos(){ 
    var titulo = 'Viacabo'; 
    var url = location.href; 
 
    try { 
        window.external.AddFavorite(url, titulo); 
    }catch(ex){
        window.sidebar.addPanel( titulo, url, ''); 
    } 
}

//usado nas perguntas do FAQ
function ToggleDiv(ctrl, ctrlpai)
{
    div = $(ctrl);
    divPai = $(ctrlpai);

    if (divPai.hasChildNodes()) {
        cleanWhitespace(divPai);               
        var filhos = divPai.childNodes;
        //alert(filhos.length);
        for (i=0;i<filhos.length;i++){
            if ((filhos[i].id != "") && (filhos[i].id != ctrl))
            {
                if ($(filhos[i].id).style.display == "block")
                    $(filhos[i].id).style.display = "none";
            }
        }
    }
    if (div.style.display == "none")
        div.style.display = "block";
    else
        div.style.display = "none";
}

// função abre e fecha submenus internos 
function toggle(obj, objbg) {
	var el = document.getElementById(obj);
	var elbg = document.getElementById(objbg);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
		elbg.style.background = 'url(/Imagens/bgs/submenu_internas.gif) no-repeat left top';
		
	}else{
		el.style.display = 'block';
		elbg.style.background = 'url(/Imagens/bgs/submenu_internas.gif) no-repeat left bottom';
		
	}
}

function meligue(obj)
{
    var el = document.getElementById(obj);
	
	if (el.style.display != "none" )
	{
	    el.style.display = "none";
	    MostraCombo();
	}
	else
	{
	    el.style.display = "block";
	    EscondeCombo();
	}
}



// função abre e fecha generos 
function generos(obj, objbg) {
	var el = document.getElementByClass(obj);
	var elbg = document.getElementByClass(objbg);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
		elbg.style.background = 'url(/Imagens/bgs/servicos/grupos_canais.jpg)no-repeat left top !important';
	}else{
		el.style.display = '';
		elbg.style.background = 'url(/Imagens/bgs/servicos/grupos_canais.jpg) no-repeat no-repeat left bottom !important';
	}
}

// função para chamar imagem //
function getPopupIMG(srcIMG){
    // imagem //
    var IMG = new Image();
        IMG.src = srcIMG;
    // tamanho da janela
    var height = IMG.height + 25;
    var width = IMG.width + 25
        // abre janela //
    window.open (srcIMG, 'IMAGEM', config='height='+height+',width='+width+', toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no');
}

// função que expande ou oculta o objeto
function expande(nomeelemento){
    var elemento = document.getElementById(nomeelemento);
	var elemento_a = document.getElementById('a_'+nomeelemento);
	
	if (elemento.style.display != "none" ){
	    elemento.style.display = 'none';
	    elemento_a.classname = '';
	}else{ 
	    elemento.style.display = '';
	    elemento_a.classname = 'ativo';
	}
}

//função abre e fecha os servicos 
function servicos(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}else {
		el.style.display = '';
	}
}

//função abre janelas guia eletronico 
function janela(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}else{
		el.style.display = '';
	}
}

function fecha(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != '' ) {
		el.style.display = '';
	}else {
		el.style.display = 'none';
	}
}

function popUpFaturaFacil()
{ 
    var winWidth = 600;
    var winHeight = 480;
    var winTop = parseInt((screen.availHeight - winHeight) / 2);
    var winLeft = parseInt((screen.availWidth - winWidth) / 2);
     
    popupWin = window.open("/Telas/CentralAssinante/Cobranca/fatura_Facil.aspx",'FaturaFacil',"width=" + winWidth + ",height=" + winHeight + ",top=" + winTop + ",left=" + winLeft + ",resizable=no,scrollbars=no,statusbar=no");
    if (popupWin.opener == null) popupWin.opener = self;
}

function popUpCliqueFale(){
    var winWidth = 360;
    var winHeight = 431;
    var winTop = parseInt((screen.availHeight - winHeight) / 2);
    var winLeft = parseInt((screen.availWidth - winWidth) / 2);
     
    popupWin = window.open("http://www.voipsharing.com.br/0800/viacabo/0800.htm",'FaturaFacil',"width=" + winWidth + ",height=" + winHeight + ",top=" + winTop + ",left=" + winLeft + ",resizable=no,scrollbars=no,statusbar=no");
    if (popupWin.opener == null) popupWin.opener = self;
}

function popUpMeLigue(){
    var winWidth = 360;
    var winHeight = 431;
    var winTop = parseInt((screen.availHeight - winHeight) / 2);
    var winLeft = parseInt((screen.availWidth - winWidth) / 2);
   
    popupWin = window.open("/Telas/Assine/popMeLigue.aspx", 'MeLigue', "width=" + winWidth + ",height=" + winHeight + ",top=" + winTop + ",left=" + winLeft + ",resizable=no,scrollbars=no,statusbar=no");
    
    if (popupWin.opener == null) popupWin.opener = self;
}	

	
// Atendimento OnLine //
function atendimentoOnLine(url, name)
{ 
    var winWidth = 315;
    var winHeight = 458;
    var winTop = parseInt((screen.availHeight - winHeight) / 2);
    var winLeft = parseInt((screen.availWidth - winWidth) / 2);
     
    popupWin = window.open(url,name,"width=" + winWidth + ",height=" + winHeight + ",top=" + winTop + ",left=" + winLeft + ",resizable=no,scrollbars=no,statusbar=no");
    if (popupWin.opener == null) popupWin.opener = self;
}	

// Indique //
function indique()
{
    indique(null, null, null, null, null, null);
}
function indique(tituloPagina, areaCustomizavel, nomeSite, link, tipo, tipo_id)
{
    var winWidth = 360;
    var winHeight = 431;
    var winTop = parseInt((screen.availHeight - winHeight) / 2);
    var winLeft = parseInt((screen.availWidth - winWidth) / 2);
    var url = "/Telas/Indique/Default.aspx?";
    if (tituloPagina != null)
    {
        url += "TituloPagina=" + tituloPagina + "&";
    }
    if (areaCustomizavel != null)
    {
        url += "hidAreaCustomizavel=" + areaCustomizavel + "&";
    }
    if (nomeSite != null)
    {
        url += "nomeSite=" + nomeSite + "&";
    }
    if (link != null)
    {
        url += "link=" + link + "&";
    }
    if (tipo != null)
    {
        url += "tipo=" + tipo + "&";
    }
    if (tipo_id != null)
    {
        url += "tipo_id=" + tipo_id + "&";
    }
    // alert(url.substring(url.length - 1));
    var ultimoCaracter = url.substring(url.length - 1);
    if (ultimoCaracter == "&" || ultimoCaracter == "?")
    {
        url = url.substring(0, url.length - 1);
    }
    var name = "popIndique";
    
    //alert(url);
    
    popupWin = window.open(url,name,"width=" + winWidth + ",height=" + winHeight + ",top=" + winTop + ",left=" + winLeft + ",resizable=no,scrollbars=no,statusbar=no");
    if (popupWin.opener == null) popupWin.opener = self;
}



function onlynumber(myfield, e,tolerado)
{
	if (myfield.length ==0)
		myfield.value=0;  
	
	var key;
	var keychar;
	
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	
	keychar = String.fromCharCode(key);
	
	if ((key==null) || (key==0) || (key==8) || (key==9)|| (key==13)|| (key==27) )
		return true;
	else if ((("0123456789"+tolerado).indexOf(keychar) > -1)){
		if (((myfield.value).indexOf(tolerado) > -1)&&(keychar==tolerado))
			return false;
		else if ((myfield.value.length==0)&&(keychar==tolerado))
		{   
			myfield.value = "0";
			return true;	
		}
		else
			return true;
	}
	else
		return false;	
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function Formato_Data(input) {
var keyCode = (isNN) ? event.which : event.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
var strPonto = "."; 
var strBarra = "/"; 
var strTraco = "-"; 
if (keyCode != 8 ){ 
	if(input.value.length == 2){input.value = input.value+strBarra}
	else if(input.value.length == 5){input.value = input.value+strBarra}
	if(input.value.length >= 10 && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, 10);
	//input.form[(getIndex(input)+1) % input.form.length].focus();
	}
}
}

function Formato_CPF(input)
{
	var keyCode = (isNN) ? event.which : event.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	var strPonto = "."; 
	var strTraco = "-";
	
	if (keyCode != 8)
	{ 
		if(input.value.length == 3)
		{
			input.value = input.value+strPonto
		}
		else if(input.value.length == 7)
		{
			input.value = input.value+strPonto
		}
		else if(input.value.length == 11)
		{
			input.value = input.value+strTraco
		}
		else if(input.value.length == 14)
		{
			input.value = input.value+strPonto
		}
	
		if(input.value.length >= 14 && !containsElement(filter,keyCode))
		{
			input.value = input.value.slice(0, 14);
			//input.form[(getIndex(input)+1) % input.form.length].focus();
		}
	}
}

function Formato_CGC(input) {
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
var keyCode = (isNN) ? event.which : event.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
var strPonto = "."; 
var strBarra = "/"; 
var strTraco = "-"; 
if (keyCode != 8 ){
	if(input.value.length == 2){input.value = input.value+strPonto}
	else if(input.value.length == 6){input.value = input.value+strPonto}
	else if(input.value.length == 10){input.value = input.value+strBarra}
	else if(input.value.length == 15){input.value = input.value+strTraco}
	if(input.value.length >= 18 && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, 18);
	//input.form[(getIndex(input)+1) % input.form.length].focus();
	}
}
}	




// --------------------------------------------------------------------------------------------- //
// Autor/Copiador   : Lucas Corrêa Braz - 23/04/2007
// Função   : dateMsk - coloca máscara em campos data
// Parametros:
// aWidget - o objeto TextBox
// Exemplo de uso -  onkeyup="dateMsk( this );"
// --------------------------------------------------------------------------------------------- //
var mskFlag = "blank";

function dateMsk( aWidget ){
    if ( mskFlag == "getOut" ) return true;
        var tmp = strip( aWidget.value , "/");
    if ( 4 < tmp.length ) aWidget.value = tmp.substr(0,2) + '/' + tmp.substr(2,2) + '/' + tmp.substr(4,4);
        else if ( 2 < tmp.length ) aWidget.value = tmp.substr(0,2) + '/' + tmp.substr(2,2);
	        else aWidget.value = tmp;
}

// --------------------------------------------------------------------------------------------- //
// Autor/Copiador   : Lucas Corrêa Braz - 23/04/2007
// Função   : CEPMsk - coloca máscara em campos CEP
// Parametros:
// aWidget - o objeto TextBox
// Exemplo de uso -  onkeyup="CEPMsk( this );"
// --------------------------------------------------------------------------------------------- //
function CEPMsk ( aWidget ) {
    if ( mskFlag == "getOut" ) return true;
     var tmp = strip( aWidget.value , "-");
      //alert( tmp ) ;
    if ( 5 < tmp.length ) aWidget.value = tmp.substr( 0 , 5 ) + '-' + tmp.substr( 5 , 3 );
    else aWidget.value = tmp;
}

// --------------------------------------------------------------------------------------------- //
// Autor/Copiador   : Lucas Corrêa Braz - 23/04/2007
// Função   : strip - função auxiliar chamada pelas funções de máscaras
// --------------------------------------------------------------------------------------------- //
function strip( str, c ) {
    var tmp = str.split( c );
    return tmp.join("");
}

//---------------------------------------------------------------------------------------------- //
//                  FLASH                                                                        //
/**
 * FlashObject v1.2.3: Flash detection and embed - http://blog.deconcept.com/flashobject/
 *
 * FlashObject is (c) 2005 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof com == "undefined") var com = new Object();
if(typeof com.deconcept == "undefined") com.deconcept = new Object();
if(typeof com.deconcept.util == "undefined") com.deconcept.util = new Object();
if(typeof com.deconcept.FlashObjectUtil == "undefined") com.deconcept.FlashObjectUtil = new Object();
com.deconcept.FlashObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, redirectUrl, detectKey){
   this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
   this.skipDetect = com.deconcept.util.getRequestParameter(this.DETECT_KEY);
   this.params = new Object();
   this.variables = new Object();
   this.attributes = new Array();

   if(swf) this.setAttribute('swf', swf);
   if(id) this.setAttribute('id', id);
   if(w) this.setAttribute('width', w);
   if(h) this.setAttribute('height', h);
   if(ver) this.setAttribute('version', new com.deconcept.PlayerVersion(ver.toString().split(".")));
   if(c) this.addParam('bgcolor', c);
   var q = quality ? quality : 'high';
   this.addParam('quality', q);
   this.setAttribute('redirectUrl', '');
   if(redirectUrl) this.setAttribute('redirectUrl', redirectUrl);
   if(useExpressInstall) {
   // check to see if we need to do an express install
   var expressInstallReqVer = new com.deconcept.PlayerVersion([6,0,65]);
   var installedVer = com.deconcept.FlashObjectUtil.getPlayerVersion();
      if (installedVer.versionIsValid(expressInstallReqVer) && !installedVer.versionIsValid(this.getAttribute('version'))) {
         this.setAttribute('doExpressInstall', true);
      }
   } else {
      this.setAttribute('doExpressInstall', false);
   }
}
com.deconcept.FlashObject.prototype.setAttribute = function(name, value){
	this.attributes[name] = value;
}
com.deconcept.FlashObject.prototype.getAttribute = function(name){
	return this.attributes[name];
}
com.deconcept.FlashObject.prototype.getAttributes = function(){
	return this.attributes;
}
com.deconcept.FlashObject.prototype.addParam = function(name, value){
	this.params[name] = value;
}
com.deconcept.FlashObject.prototype.getParams = function(){
	return this.params;
}
com.deconcept.FlashObject.prototype.getParam = function(name){
	return this.params[name];
}
com.deconcept.FlashObject.prototype.addVariable = function(name, value){
	this.variables[name] = value;
}
com.deconcept.FlashObject.prototype.getVariable = function(name){
	return this.variables[name];
}
com.deconcept.FlashObject.prototype.getVariables = function(){
	return this.variables;
}
com.deconcept.FlashObject.prototype.getParamTags = function(){
   var paramTags = ""; var key; var params = this.getParams();
   for(key in params) {
        paramTags += '<param name="' + key + '" value="' + params[key] + '" />';
    }
   return paramTags;
}
com.deconcept.FlashObject.prototype.getVariablePairs = function(){
	var variablePairs = new Array();
	var key;
	var variables = this.getVariables();
	for(key in variables){
		variablePairs.push(key +"="+ variables[key]);
	}
	return variablePairs;
}
com.deconcept.FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
        if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); }
        flashHTML += '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" id="'+ this.getAttribute('id') + '" name="'+ this.getAttribute('id') +'"';
		var params = this.getParams();
        for(var key in params){ flashHTML += ' '+ key +'="'+ params[key] +'"'; }
		pairs = this.getVariablePairs().join("&");
        if (pairs.length > 0){ flashHTML += ' flashvars="'+ pairs +'"'; }
        flashHTML += '></embed>';
    } else { // PC IE
        if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); }
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" id="'+ this.getAttribute('id') +'">';
        flashHTML += '<param name="movie" value="' + this.getAttribute('swf') + '" />';
		var tags = this.getParamTags();
        if(tags.length > 0){ flashHTML += tags; }
		var pairs = this.getVariablePairs().join("&");
        if(pairs.length > 0){ flashHTML += '<param name="flashvars" value="'+ pairs +'" />'; }
        flashHTML += '</object>';
    }
    return flashHTML;
}
com.deconcept.FlashObject.prototype.write = function(elementId){
	if(this.skipDetect || this.getAttribute('doExpressInstall') || com.deconcept.FlashObjectUtil.getPlayerVersion().versionIsValid(this.getAttribute('version'))){
		if(document.getElementById){
		   if (this.getAttribute('doExpressInstall')) {
		      this.addVariable("MMredirectURL", escape(window.location));
		      document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		      this.addVariable("MMdoctitle", document.title);
		   }
            if (document.getElementById(elementId) )
            {
			    document.getElementById(elementId).innerHTML = this.getHTML();
			}
		}
	}else{
		if(this.getAttribute('redirectUrl') != "") {
			document.location.replace(this.getAttribute('redirectUrl'));
		}
	}
}
/* ---- detection functions ---- */
com.deconcept.FlashObjectUtil.getPlayerVersion = function(){
   var PlayerVersion = new com.deconcept.PlayerVersion(0,0,0);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new com.deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (window.ActiveXObject){
	   try {
   	   var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
   		PlayerVersion = new com.deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
	   } catch (e) {}
	}
	return PlayerVersion;
}
com.deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) || 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
com.deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
com.deconcept.util.getRequestParameter = function(param){
	var q = document.location.search || document.location.href.hash;
	if(q){
		var startIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
		if (q.length > 1 && startIndex > -1) {
			return q.substring(q.indexOf("=", startIndex)+1, endIndex);
		}
	}
	return "";
}

/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use / backwards compatibility */
var getQueryParamValue = com.deconcept.util.getRequestParameter;
var FlashObject = com.deconcept.FlashObject;


function foco(control)
{
   $(control).focus();
}

function getDetalheInternet(internet_id, internet_finalidade){
    document.form1.action = "/Telas/Internet/produtos_internet_detalhes.aspx";
    document.form1.Internet_Id.value = internet_id;
    document.form1.Internet_Finalidade.value = internet_finalidade;
    document.form1.submit();
}

    
 function focusEnviar(obj, event)
{
    //var keycode = event.keyCode? event.keyCode: event.which? event.which: event.charCode;

    if ((window.event? event.keyCode: event.which ) == 13 ){
        $(obj).focus();
        return validaIdArea();
    }
}

// Remove os espaços em branco que o Firefox trata como se fosse um nó filho
        notWhitespace = new RegExp(/\S/);

        function cleanWhitespace(node) {
          for (var x = 0; x < node.childNodes.length; x++) {
            var childNode = node.childNodes[x]
            if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
                // that is, if it's a whitespace text node
              node.removeChild(node.childNodes[x])
            }
            if (childNode.nodeType == 1) {
        // elements can have text child nodes of their own
              cleanWhitespace(childNode)
            }
          }
        }


//valida email
function isEmail(text){
   var 	arroba = "@",
       	ponto = ".",
	   	posponto = 0,
	   	posarroba = 0;
	
	 if (text =="") return false;
	
	 for (var indice = 0; indice < text.length; indice++){
	 	if (text.charAt(indice) == arroba) {
	 		posarroba = indice;
	      	break;
		 }
	 }
	
	for (var indice = posarroba; indice < text.length; indice++){
		if (text.charAt(indice) == ponto) {
			posponto = indice;
	     	break;
		}
	}
	if (posponto == 0 || posarroba == 0) return false;
	if (posponto == (posarroba + 1)) return false;
	if ((posponto + 1) == text.length) return false;
	return true;
}

// funções AJAX para incrementar clique nas perguntas do FAQ
function incrementaClique(id_pergunta){
    xmlHttp = getRequestXml();
    url = "/ajax/ajuda/incrementa_clique.aspx?id_pergunta=" + id_pergunta;
    xmlHttp.onreadystatechange = function(){ executaIncrementoClique(xmlHttp) }
    xmlHttp.open("POST", url, true);
    xmlHttp.send(null);
}

function executaIncrementoClique(xmlHttp){
    if (xmlHttp.readyState == 4){
        if (xmlHttp.status == 200){
            return;
        }
    }
}

// funções AJAX Indique outros programas
   
 function getDadosPrograma(id_programa, id_canal, link){
    xmlHttp = getRequestXml();
    url = "/ajax/proximasExibicoes/indique.aspx?id_programa=" + id_programa;
    // chamada //
    xmlHttp.onreadystatechange = function() { returnDadosPrograma(xmlHttp, id_programa, id_canal, link); }
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
 }
 
 function returnDadosPrograma(xmlHttp, id_programa, id_canal, link){
    if (xmlHttp.readyState == 4){
        if (xmlHttp.status == 200){
           objDiv = document.getElementById('dv');
           
           //Lê o XML com o DOM
           if (window.ActiveXObject){
                xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
                xmlDoc.loadXML(xmlHttp.responseText);
                doc = xmlDoc.documentElement;
           }
           else{
                var parser = new DOMParser();
                xmlDoc = parser.parseFromString(xmlHttp.responseText, "text/xml");
                doc = xmlDoc.documentElement;
           }
           
           var tituloPagina = "Indique este programa a um amigo";
           var link_final = link + "?Id_Destaque="+id_programa + "EEId_Canal=" + id_canal;
           var areaCustomizavel = "";
            var nomePrograma = "";
           
           if (doc != null){           
               //ler doc XML retornado
                arrTitulo = doc.selectNodes('Programa/titulo');
                arrTitOriginal = doc.selectNodes('Programa/titoriginal');
                arrAno = doc.selectNodes('Programa/ano');
                arrSinopse = doc.selectNodes('Programa/sinopsetv');
                arrDuracao = doc.selectNodes('Programa/duracao');
                arrGen = doc.selectNodes('Programa/gen');
           
                areaCustomizavel = "<div class=\"sinopse\">" +
				    "<h4>Sinopse</h4>" +
				    "<p>" + arrSinopse[0].childNodes[0].nodeValue + "</p>" +
				    "<div>" +
				    "	<p>" + arrGen[0].childNodes[0].nodeValue + " - " + arrAno[0].childNodes[0].nodeValue +
				    "  -  " + arrDuracao[0].childNodes[0].nodeValue +
				    "</div>" +
			        "</div>";
			    
			    nomePrograma = arrTitulo[0].childNodes[0].nodeValue;
           }
           
           indique(tituloPagina, areaCustomizavel, nomePrograma, link_final, "P", id_programa);
        }
    }
 }