

function XMLHTTPRequest() { 
	var http = 0;
	if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
	} else {
		try { 
			http = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try { 
			http = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) { 
				http = false; 
			} 
		}
	} 
	return http; 
}

function mostrar_pagina(url, div) {
	var http = XMLHTTPRequest();
	if (http) {
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
				if (http.status == 200) {
					var retorno = unescape(http.responseText.replace(/\+/g," "));
					document.getElementById(div).innerHTML = retorno
				} else {
					alert('There was a problem with the request.');
				}
			}		
		}
		http.open('GET', url, true);
		http.send(null);
	}
	else {
		alert('Erro seu navegador nao suporta ajax');
	}
}	

function addEvent(obj, evType, fn) {
	if (typeof obj == "string") {
		if (null == (obj = $(obj))) {
			throw new Error("Cannot add event listener: HTML Element not found.");
		}
	}
	if (obj.attachEvent) {
		return obj.attachEvent(("on" + evType), fn);
	} else if (obj.addEventListener) {
		return obj.addEventListener(evType, fn, true);
	} else {
		throw new Error("Your browser doesn't support event listeners.");
	}
}

function iniciar() {	

var items = [], allItems = document.getElementById('menu-semanal').getElementsByTagName("li");
	
for (var i = 0; i < allItems.length; i++) {				
	allItems[i].onclick = function() {	
		for (var item = this.parentNode.firstChild; item; item = item.nextSibling) {		
			item.className = 'normal';			
		}
		this.className = 'current';				
		var padrao = /(<span(.*?)>(.*?)<\/span>)/i;	
		var pagina = this.innerHTML.replace(padrao, "$3");	
		var url = 'receber.php?pagina=' + pagina;						
		mostrar_pagina(url, 'programas');						
		//document.title = pagina;	
		mostraProgramas();
	}				
}	

var aba = document.getElementById('menu-semanal').getElementsByTagName("span");

	for (var j = 0; j < aba.length; j++) {		
		aba[j].onmouseover = function() {		
			if(this.className != 'link'){					
				this.className = 'link';
			} 	
		}		
		aba[j].onmouseout = function() {	
			if(this.className != 'normal'){		
				this.className = 'normal';
			} 	
		}
	}	
}
//para não mostrar os patrocinadores em 800x600
function patrocinios(){
	var p;
	p = document.getElementById('patrocinios');
	if(document.body.clientWidth > 810){
		p.style.display = "block";	
	}else{
		p.style.display = "none";	
	}
}
// mostra/esconde programas
function mostraProgramas(){
	var prog;
	prog = document.getElementById('programas');
	for(var i=0; i<prog.getElementsByTagName('h4').length; i++){
		prog.getElementsByTagName('h4')[i].onclick = function(){
			if(navigator.appName == "Microsoft Internet Explorer"){
				if(this.nextSibling.className != "mostra"){
					this.nextSibling.className = "mostra";
				}else{
					this.nextSibling.className = "esconde";
				}
			}else{
				if(this.nextSibling.nextSibling.className != "mostra"){
					this.nextSibling.nextSibling.className = "mostra";
				}else{
					this.nextSibling.nextSibling.className = "esconde";
				}
			}
		}		
	}
}
// verifica se patrocinadores devem ou não ser exibidos
addEvent(window, "load", patrocinios);




// parte da enquete 
function puxa_enquete(t){
	//var t= document.enquete;
	for (i=0; i<t.resposta.length; i++) {
		if (t.resposta[i].checked) {
			marcado = i
			resposta = t.resposta[i].value
		}
	}
 var url = "enquete/vota_enquete.php?resposta="+resposta+'&id_enquete='+t.id_enquete.value+'&registro='+t.registro.value;
 mostrar_pagina(url,'enquete');
	//alert('show'+t.id_enquete.value+'//'+resposta);	
}

// padrão de popup dreamweaver
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function inserir_swf($arquivo,$altura,$largura,$id){
    document.writeln('    <object id="globalnav-object" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + $largura + '" height="' + $altura + '" id="' + $id + '" name="' + $id + '">');
    document.writeln('        <param name="movie" value="' + $arquivo + '" />');
    document.writeln('        <param name="FlashVars" value="loc=en_US&htmlApp=false&gatewayURL=gwurl" />');
    document.writeln('        <param name="bgcolor" value="#ffffff" />');
    document.writeln('        <param name="menu" value="false" />');
    document.writeln('        <param name="quality" value="high" />');
    document.writeln('        <param name="salign" value="tl" />');
    document.writeln('        <param name="scale" value="noscale" />');
    document.writeln('        <param name="wmode" value="transparent" />');
    document.writeln('        <embed id="globalnav-embed" src="' + $arquivo + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" flashvars="loc=en_US&htmlApp=false&gatewayURL=gwurl" bgcolor="#ffffff" menu="false" quality="high" salign="tl" scale="noscale" id="' + $id + '" width="' + $largura + '" height="' + $altura + '"></embed>');
    document.writeln('    </object>');
}

function player() {
resultado=window.open('player.php','player',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=455,height=455");
}

function manda(enq) {
resultado=window.open('',enq,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=200,height=200");
}

function limitacarcter() {
    Campo = document.getElementById("msg");
    Display = document.getElementById("contador");
    Caracteres = 200 - Campo.value.length;
    Display.innerHTML = Caracteres;
    if(Campo.value.length >= 200){
        Campo.value = Campo.value.substring(0, 200);
    }
}