var actualVideo=0;
function pippo(){
	alert('pippo');
}
function toggle(id) {
	var display = document.getElementById(id).style.display ? '' : 'none';
	document.getElementById(id).style.display = display;
}
function closeDivs(id){
	if(document.getElementById(id).style.display==''){
		toggle(id);
		return;
	}
	var divs = document.getElementsByTagName('div');
	for(var i=0; i<divs.length; i++){
		if(divs[i].id.substr(0,9)==id.substr(0,9)) divs[i].style.display='none';
	}
	toggle(id);
}	
		
function URLDecode(utftext){
	utftext = utftext.replace(/%%/g, "%");
	utftext = utftext.replace(/%1/g, "\\'");
	return utftext.replace(/%2/g, '\\"');
}
function displayCentralFrame(w, h){
	$("#centralFrame").modal({maxWidth:w,maxHeight:h,minWidth:w,minHeight:h});
}
function chiudiDiv(id) {
	document.getElementById(id).style.display = 'none';
}
function apriDiv(id) {
	document.getElementById(id).style.display = '';
}
function stripslash(stringa){
	stringa = stringa.replace(/\\"/g, '"');
	return str_replace("\\", "", stringa);
}

//POPUP======================================================
//=====IFRAME================================================
var tb_url;
var tb_title;

function impostaDimensioniIframe(w, h){
	var url = tb_url+'&width='+w;
	if(h!=0) url = url+'&height='+h;
	tb_show('', url, false);
	/*document.getElementById("centralIframe").width=w;
	if(h!=0){
		document.getElementById("centralIframe").height=h;
		displayCentralFrame(w+20, h+10);
	}
	else displayCentralFrame(w+20, 550);*/
}
function impostaUriIframe(uri){
	//document.getElementById("centralIframe").src=uri;
	tb_url=uri+"&TB_iframe=true";
}
//=====WIDGET================================================
function apriMarquee(){
	impostaUriIframe("http://www.messinaweb.tv/scripts/news/news.php?dummy=0");
	impostaDimensioniIframe(400,420);
}
function apriNews(i){
	impostaUriIframe("http://www.messinaweb.tv/scripts/news/news.php?i="+i);
	impostaDimensioniIframe(400,420);
}

function apriFarmacie(){
	impostaUriIframe("http://www.messinaweb.tv/scripts/widget.php?p=11");
	impostaDimensioniIframe(900,450);
}
function apriSanti(){
	impostaUriIframe("http://www.messinaweb.tv/scripts/santi.php?dummy=0");
	impostaDimensioniIframe(300,370);
}
function apriCinema(){
	impostaUriIframe("http://www.messinaweb.tv/scripts/widget.php?p=12");
	impostaDimensioniIframe(600, 0);
}
function apriMercatino(){
	impostaUriIframe("http://www.messinaweb.tv/scripts/mercatino.php?dummy=0");
	impostaDimensioniIframe(700, 0);
}
function apriSpettacoli(){
	impostaUriIframe("http://www.messinaweb.tv/scripts/widget.php?p=14");
	impostaDimensioniIframe(700, 0);
}
function apriEnalotto(){
	impostaUriIframe("http://www.messinaweb.tv/scripts/enalotto.php?dummy=0");
	impostaDimensioniIframe(310, 410);
}

function apriMeteo(){
	meteo3();
}
function meteo3(){
	return;
}
//=====ARTICOLI==============================================
function contattaAutore(numero){
	impostaUriIframe("http://www.messinaweb.tv/scripts/contatta.php?a="+numero);
	impostaDimensioniIframe(450, 440);
}
function codiceVideo(numero){
	impostaUriIframe("http://www.messinaweb.tv/scripts/codiceVideo.php?v="+numero);
	impostaDimensioniIframe(460, 150);
}
function apriArticolo(i){
	//window.open("articolo.php?a="+i, "articolo", "width=760,height=460,location=no,left=30,top=30,status=no,scrollbars=yes,resizable=no");
	displayArticolo(i);
}
function displayArticolo(a){
	if(location.href.indexOf("http://www.messinaweb.tv/index2.php")) impostaUriIframe("http://www.messinaweb.tv/scripts/articolo.php?a="+a);
	else impostaUriIframe("http://www.messinaweb.tv/scripts/articolo2.php?a="+a);
	impostaDimensioniIframe(680, 450);
}
//===========================================================
function rsstematici(){
	//window.open("rss/rss_tematici.php", "RSS", "width=320,height=440,location=no,left=30,top=30,status=no,scrollbars=yes,resizable=no");
	impostaUriIframe("http://www.messinaweb.tv/rss/rss_tematici.php?dummy=0");
	impostaDimensioniIframe(320, 480);
}



//RICERCA====================================================
function arancio(){
	document.getElementById('camporicerca').style.background="#616161 url(images/search.jpg) no-repeat left -33px";
}
function blue(){
	document.getElementById('camporicerca').style.background="#616161 url(images/search.jpg) no-repeat left top";
}
//===========================================================
function commutaVideo(numero){
	var so = new SWFObject('flash/player.swf','mpl','480','320','9');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addParam('flashvars','&file=http://91.121.136.203/video/'+numero+'.flv&image=video/preview/'+numero+'.jpg&controlbar=over&fullscreen=true');
	so.write('pageContent');
}
function caricaContenuto(numero, titolo, autore, data, mail, articolo, tipo, homepage){
	if(tipo==1) apriArticolo(numero);
	else cambiaVideo(numero, titolo, autore, data, mail, articolo, homepage);
}
function informazioniVideo(numero, autore, mail, articolo, data){
	var infoVideo = '<p><font color="#ff7a00">Autore: <br></font>';
	if(mail==1){
		infoVideo = infoVideo + '<a class="option" onclick="contattaAutore('+numero+');">';
	}
	infoVideo = infoVideo + autore;
	if(mail==1){
		infoVideo = infoVideo + '</a>';
	}
	infoVideo = infoVideo + '<br><font color="#ff7a00">pubblicato il: </font>'+data+'<br>';
	if(articolo==1){
		infoVideo = infoVideo + '<a href="javascript:apriArticolo('+numero+');">Leggi l\'articolo</a>' ;
	}
	return infoVideo;
}
function informazioniVideo2(numero, autore, mail, articolo, data){
	var infoVideo = '<div class="infoVideoSel">Autore:&nbsp;</div><div class="infoVideo">';
	if(mail==1){
		infoVideo = infoVideo + '<a href="javascript:contattaAutore('+numero+');">';
	}
	infoVideo = infoVideo + autore;
	if(mail==1){
		infoVideo = infoVideo + '</a>';
	}
	infoVideo = infoVideo + '&nbsp;</div><div class="infoVideoSel">pubblicato il:&nbsp;</div><div class="infoVideo">'+data+'</div>';
	if(articolo==1){
		infoVideo = infoVideo + '<div class="infoVideoRight"><a href="javascript:apriArticolo('+numero+');">&raquo;&raquo;&raquo;&nbsp;Leggi l\'articolo</a></div>' ;
	}
	return infoVideo;
}

function socialNetworking(numero){
	return '<center><a href="http://www.messinaweb.tv/video/'+numero+'.flv">Scarica questo video</a>&nbsp;-&nbsp;<a class="option" onclick="codiceVideo('+numero+');">Questo video sul tuo sito!</a></center>'
}

function changeVideo(numero){
	actualVideo=numero;
	changeVideoImage(numero);
	$f().setClip({url:"http://91.121.136.203/video/"+numero+".flv"});
	
}


function changeVideoImage(numero){
	document.getElementById('plutone').style.backgroundImage="url(http://91.121.136.203/images/dynamic/video_preview/?v="+numero+")";	
	document.getElementById('plutone').style.display='';
}

function cambiaVideo(numero, titolo, autore, data, mail, articolo, homepage){
	if(location.href.indexOf("http://www.messinaweb.tv/index2.php")) commutaVideo(numero);
	else{
		changeVideo(numero);
	}	
	titolo = stripslash(titolo);
	if(homepage != 1) document.title=titolo + " - MessinaWeb.Tv";
	document.getElementById('pageTitle').innerHTML=titolo;
	/*
	 *
	 *
	 *
	 */
	if(location.href.indexOf("http://www.messinaweb.tv/index2.php")) document.getElementById('videoExtraConteiner').innerHTML=socialNetworking(numero);
	else loadHTML('../scripts/codiceVideo2.php?v='+numero, 'socialNetwork');
	if(location.href.indexOf("http://www.messinaweb.tv/index2.php")) document.getElementById('bannerBodyInfo').innerHTML=informazioniVideo(numero, autore, mail, articolo, data);
	else document.getElementById('videoExtraConteiner').innerHTML=informazioniVideo2(numero, autore, mail, articolo, data);
	/*
	 *
	 *
	 *
	 */
	
}

//CARICAMENTO DINAMICO DI HTML================================
var loadedHTML = new Array();
function loadCategory(n, url, target){
	for(var i=0; i<loadedHTML.length; i++){
		if(loadedHTML[i]==n) return;
	}
	loadedHTML.push(n);
	loadHTML(url, target);
}
function loadHTML(url, target) {
  var req;
  if (window.XMLHttpRequest) req = new XMLHttpRequest();
  else if (window.ActiveXObject) req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req != undefined) {
    req.onreadystatechange = function() {loadHTMLBody(url, target, req);};
    req.open("GET", url, true);
    req.send("");
  }
}  
function loadHTMLBody(url, target, request) {
  if (request.readyState == 4) {
    if (request.status == 200) document.getElementById(target).innerHTML = request.responseText;
    else document.getElementById(target).innerHTML="ERRORE!:\n"+ request.status + "\n" +request.statusText;
  }
}
//============================================================

//RICERCA=====================================================
function iniziaRicerca(){
	document.getElementById('categorie').style.display='none'; 
	var q=document.getElementById('camporicerca').value;
	//http://www.messinaweb.tv/test/googlesearch/dom.php?query='+q
	loadHTML('http://www.messinaweb.tv/test/googlesearch/dom.php?query='+q, 'searchresults');
	document.getElementById('cerca_button').style.display='none';
	document.getElementById('chiudi_button').style.display='';
	return false;
}
function fineRicerca(){
	document.getElementById('searchresults').innerHTML='';
	document.getElementById('categorie').style.display='';
	document.getElementById('cerca_button').style.display='';
	document.getElementById('chiudi_button').style.display='none';
	document.getElementById('camporicerca').value="Cerca...";
	return false;
}
	
//============================================================
