var mw = null;
function openWindowDimBars(FileName,w,h,barre) {
	myWindow=window.open(FileName,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+barre+',resizable=0,top=10,left=10,width='+w+',height='+h);
	return myWindow;
}

/*
	Inserisce dinamicamente un filmato Flash.
	Per scavalcare il blocco di IE 6, che altrimenti ne richiede l'attivazione manuale.
*/
function print_flash_movie(nomefile, width, height, version) {
	var str;

	str = ('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + '" ID="ticker_news" WIDTH="' + width + '" HEIGHT="' + height + '">');
	str = str + ('<PARAM NAME=movie VALUE="' + nomefile + '">');
	str = str + ('<PARAM NAME=quality VALUE=high>');
	str = str + ('<embed src="' + nomefile + '" quality=high ');
	str = str + ('swLiveConnect="FALSE" WIDTH="' + width + '" HEIGHT="' + height + '" border="0" TYPE="application/x-shockwave-flash"');
	str = str + ('PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></embed></OBJECT>');

	document.write(str);
}

function MM_preloadImages() { //v3.0
	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_swapImgRestore() { //v3.0
  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_findObj(n, d) { //v4.01
	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() { //v3.0
	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];
		}
	}
}

/*
Controllo della validita' di un indirizzo e-mail.
Versione 2

Utilizzo: checkemail(document.userForm.u_email.value);

Puo', ad esempio, essere inserito nella funzione submitRecord() in questo modo:
	if (checkemail(document.my_form_name.email_field.value)==false) {
		alert("Attenzione: e' necessario inserire un indirizzo e-mail valido.")
		return;
	}
*/
var testresults;
function checkemail(email_addr) {
	var filter=/^[\'+\\./0-9A-Z^_\`a-z{|}~\-]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+){1,3}$/i;
	if (filter.test(email_addr)) {
		testresults = true;
	}
	else {
		testresults = false;
	}

	return(testresults);
}

function getE(id) {
	return document.getElementById(id);
}

function confirmLink(theLink, confirmMsg) {
	if (typeof(window.opera) != 'undefined') {
		return true;
	}

	var is_confirmed = confirm(confirmMsg);

	return is_confirmed;
}

/*
	Effettua la chiamata AJAX utilizzando JQuery e JSON.
	Autore:	Cristian Zuddas
	Data:	2007-11-19

	Params:
		query_str			string			Parametri da passare allo script che gestisce le risposte AJAX
		is_admin			bool			TRUE significa che questa funzione e' stata richiamata dal CMS
		func_success		function		Funzione da richiamare in caso di successo; deve avere un parametro nel quale viene inserito il risultato JSON della richiesta. Esempio: function(oResponse) {...}
		func_error			function		Opzionale, funzione da richiamare in caso di errore. Se viene passato un valore il cui tipo non e' "function", ne viene presa una di default
		func_complete		function		Opzionale, funzione da richiamare una volta completata la richiesta, sia in caso di successo sia in caso di errore. Se viene passato un valore il cui tipo non e' "function", ne viene presa una di default
		external_url		string			URL della risposta, esterno a quello locale (aggiunto per Applejack 0.5)

	Note:
		Deve essere definita una variabile "ajax_main_script" (string) che contiene il nome/URL
		dello script gestore delle risposte.
*/
function doAjax(query_str, is_admin, func_success, func_error, func_complete, external_url) {
	if (typeof func_success=='function') {
		var url = ajax_main_script;
		if (is_admin) {
			url = '../'+url;
		}

		if (typeof external_url=='string' && external_url!=null && external_url.length>0) {
			url = external_url;
		}
		//window.location = url+'?'+query_str;
		if (typeof func_error!='function') {
			func_error = function() {
										alert("Si e' verificato un errore durante il caricamento dei dati. Si consiglia di riprovare in un secondo momento.");
									};
		}

		if (typeof query_str!='string')
			query_str = '';

		$.ajax({
			type: "POST",
			url: url,
			data: query_str,
			dataType: "json",
			success: func_success,
			error: func_error,
			complete: func_complete
		});
	}
	else {alert('doAjax error: success function is not defined.');}
}

function ch_vid_o(o, segno)
{
	if((o > 0) && (segno > 0))
	{
		doAjax(
			'a_ajax=1&o='+o+'&segno='+segno,
			false,
			function(oResponse) {
			if(oResponse.length > 0)
			{
				getE("video_titolo").innerHTML = '<span class="titolo_bianco_14 maius">' + oResponse[0] + '</span>';
				getE("video_segno").innerHTML = '<img src="images/' + oResponse[0].toLowerCase() + '_on.gif" alt="" />';
				getE("flv_player").SetVariable("player:jsUrl", oResponse[1]);
				getE("flv_player").SetVariable("player:jsStop", "");
				getE("flv_player").SetVariable("player:jsPlay", "");
			}

			}
		);
	}
	return false;
}

function ch_vid_t(id_video)
{
	if(id_video > 0)
	{
		doAjax(
			'a_ajax=2&t='+id_video,
			false,
			function(oResponse) {
				if(oResponse.length > 0)
				{
					getE("video_data").innerHTML = '<span class="titolo_bianco_12">' + oResponse[0] + '</span>';
					getE("video_titolo").innerHTML = '<span class="titolo_bianco_14">' + oResponse[1] + '</span>';
	
					getE("flv_player").SetVariable("player:jsUrl", oResponse[2]);
					getE("flv_player").SetVariable("player:jsStop", "");
					getE("flv_player").SetVariable("player:jsPlay", "");
				}
				else
				{
					if(oResponse == -1)
					{
						getE("div_videoplayer").innerHTML = '<div class="titolo_bianco_12"><a class="rosso" href="signup.php">Registrati</a> o effettua il <a class="rosso" href="login.php">login</a> per visualizzare il filmato.</div>';
					}
				}
			}


		);
	}
	return false;
}