/*
iRadio .::.::. 4 anos de sucesso
iradio.com.br

Rafael Carvalho :: carvalho@rafaelcarvalho.net
*/

function getXMLHTTPRequest(){var xml=null;try{xml=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xml=new ActiveXObject("Microsoft.XMLHTTP");}catch(sc){xml=null;}}if(!xml && typeof XMLHttpRequest!="undefined"){xml=new XMLHttpRequest();}return xml;}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function bt_MOver(img){
	img_endereco = img.src;
	img_partes_barras = img_endereco.split("/");
	img_nome = img_partes_barras[img_partes_barras.length-1];
	img_partes = img_nome.split(".");
	if(img_partes[0].substr(img_partes[0].length-4,4) != "over"){
		nova_img = "images/"+img_partes[0]+"_over."+img_partes[1];
		img.src = nova_img;
	}
}

function bt_MOut(img){
	img_nome = img.src;
	img_partes = img_nome.split("_over");
	if(img_partes.length == 2){
		nova_img = img_partes[0]+"_over."+img_partes[1];
		img.src = nova_img;
	}
	nova_img = img_partes[0]+img_partes[1];
	img.src = nova_img;
}
function abre_playerAba(i){
	if(typeof fechaTimer != 'undefined')clearTimeout(fechaTimer);
	aba = document.getElementById('playerAba_aba');
	if(i == null){	
		area = document.getElementById('playerAba');
		barra01 = document.getElementById('playerAba_barra01');
		bt_MOver(barra01);
		aba.bgColor = "#100E0F";
		area.style.height="361px";
		i = aba.height;
		if(i=="")i=50;
		abreTimer = setTimeout("abre_playerAba("+i+")",50);
	} else if(i<300) {
		if(i==75)carregarInfoPlayer();
		aba.height=i+"px";
		i += 25;
		abreTimer = setTimeout("abre_playerAba("+i+")",50);
	} else {
		aba.height="327px";
	}
}

function fecha_playerAba(i){
	if(typeof abreTimer != 'undefined')clearTimeout(abreTimer);
	aba = document.getElementById('playerAba_aba');
	if(i == null){
		i = aba.height;
		i -= 25;
		fechaTimer = setTimeout("fecha_playerAba("+i+")",50);
	} else if(i>27) {
		if(i==277)descarregarInfoPlayer();
		aba.height=i+"px";
		i -= 25;
		fechaTimer = setTimeout("fecha_playerAba("+i+")",50);
	} else {
		area = document.getElementById('playerAba');
		barra01 = document.getElementById('playerAba_barra01');
		aba.height="";
		area.style.height="34px";
		aba.bgColor = "";
		bt_MOut(barra01);
	}
}

function ajustarPosicaoPlayer(){
	area = document.getElementById('playerAba');
	largura_pagina = document.documentElement.clientWidth;
	if(largura_pagina <= 800){
		x = 5;
	} else {
		x = ((largura_pagina - 800)/2)+5;
	}
	y = 5;
	area.style.top = y+"px";
	area.style.left = x+"px";
}

function submeterFormulario(formulario){
	if(formulario == "per_capa"){
		area = document.getElementById('per_area');
		nome_v = document.getElementById('nome').value;
		cidade_v = document.getElementById('cidade').value;
		uf_v = document.getElementById('estado').value;
		p_r = document.getElementById('per_p_r').value;
		txt = document.getElementById('texto').value;
		if(!is_branco([nome_v,cidade_v,uf_v,p_r,txt])){
			/*do {
				txt = txt.replace('\n', "<br />");
			} while (txt.indexOf('\n') != -1);*/
			req=getXMLHTTPRequest();
			if(req){		
				if(p_r == "pedido"){ acao = "P"; } else { acao = "R"; }	
				req.open("GET","enviarPedido.php?nome="+nome_v+"&cidade="+cidade_v+"&estado="+uf_v+"&tipo="+acao+"&texto="+txt,true);
				envioStatus('carregando','per_area');
				req.onreadystatechange=function(){
					if(req.readyState == 4){
						if(req.responseText=="ok"){ alert('Pedido/Recado enviado com sucesso!'); }
					  carregarPeR();
					}
				};
				req.send(null);
			}
		}
	}
}

function is_branco(vars){
	for(i=0;i<vars.length;i++){
		if(vars[i] == ""){
			alert('Não deixe campos em branco');
			$retorno = true;
			break;
		} else {
			$retorno = false;
		}
	}
	return $retorno;
}

function selecionarRadio(formulario,campo){
	if(formulario=="per"){
		pedido = document.getElementById('per_pedido');
		recado = document.getElementById('per_recado');
		p_r = document.getElementById('per_p_r');
		if(campo == "pedido"){
			pedido.src = "images/form_radio_on.jpg";
			recado.src = "images/form_radio_off.jpg";
			p_r.value = "pedido";
		} else if(campo == "recado"){
			recado.src = "images/form_radio_on.jpg";
			pedido.src = "images/form_radio_off.jpg";
			p_r.value = "recado";
		}
	} else if(formulario=="per2"){
		pedido = document.getElementById('per_pedido');
		recado = document.getElementById('per_recado');
		per_acao = document.getElementById('acao');
		if(campo == "P"){
			pedido.src = "images/form_radio_on.jpg";
			recado.src = "images/form_radio_off.jpg";
			per_acao.value = "P";
		} else if(campo == "R"){
			recado.src = "images/form_radio_on.jpg";
			pedido.src = "images/form_radio_off.jpg";
			per_acao.value = "R";	
		}
	} else if(formulario=="per3"){
		pedido = document.getElementById('per_pedido');
		recado = document.getElementById('per_recado');
		per_acao = document.getElementById('acao');
		if(campo == "P"){
			pedido.src = "images/form_radio_on.jpg";
			recado.src = "images/form_radio_off.jpg";
			per_acao.value = "P";
		} else if(campo == "R"){
			recado.src = "images/form_radio_on.jpg";
			pedido.src = "images/form_radio_off.jpg";
			per_acao.value = "R";	
		}
	}
}

function envioStatus(status,area,resposta){
	areaOBJ = document.getElementById(area);
	carregando = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='25' height='25'><param name='movie' value='swf/carregando.swf'><param name='quality' value='high'><param name='wmode' value='transparent'><embed src='swf/carregando.swf' wmode='transparent' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='25' height='25'></embed></object>";
	if(status=='carregando'){
		areaOBJ.innerHTML = carregando;
	} else if(status=='carregado'){
		areaOBJ.innerHTML = resposta;
	} else if(status=='carregando2'){
		
	}
}

function carregarPeR(){
	req=getXMLHTTPRequest();
		if(req){		
			req.open("GET","per_capa.php",true);
			envioStatus('carregando','per_area');
			req.onreadystatechange=function(){
				if(req.readyState == 4){
				  setTimeout("envioStatus('carregado','per_area','"+req.responseText+"')",2000);
				}
			};
			req.send(null);
		}
}

function carregarInfoPlayer(){
	req=getXMLHTTPRequest();
		if(req){		
			req.open("GET","infoPlayer.php",true);
			envioStatus('carregando','playerAba_aba');
			req.onreadystatechange=function(){
				if(req.readyState == 4){
				  setTimeout("envioStatus('carregado','playerAba_aba','"+req.responseText+"')",100);
				}
			};
			req.send(null);
		}
}

function descarregarInfoPlayer(){
	setTimeout("envioStatus('carregado','playerAba_aba','')",100);
}

function carregarLetreiro(){
	req=getXMLHTTPRequest();
		if(req){		
			req.open("GET","letreiro.php",true);
			envioStatus('carregando2','area_letreiro');
			req.onreadystatechange=function(){
				if(req.readyState == 4){
				  setTimeout("envioStatus('carregado','area_letreiro','"+req.responseText+"')",100);
				  setTimeout("carregarLetreiro()",300000);
				}
			};
			req.send(null);
		}
}
