//<![CDATA[

function combobox(oggetto, evento)
{
	//xxx
}

function carica_img(idimg, tempo, tipo)
{
	
	if ( tempo == null ) tempo='slow';
	$('#loading_'+idimg).remove();
	
	if ( tipo == 'slideDown' )
	{  $('#image_'+idimg).slideDown(tempo); }
	else
	{ $('#image_'+idimg).fadeIn(tempo); }
}

function apici(oggetto)
{
	oggetto.value = oggetto.value.replace(/"/g, "'");
}


	function orderfile(corrente, futura, tabella)
	{
			
			
			
			//Viene selezionato l'id dell'ordine corrente e di quello successivo. 
			var id_corrente = $('.allegati_ordine_'+corrente).attr('id').replace("allegati_rigo_", "");
			var id_futura = $('.allegati_ordine_'+futura).attr('id').replace("allegati_rigo_", "");
			
			//alert(corrente+'='+id_corrente+' '+futura+'='+id_futura);
			

			
			//Viene salvato l'html delle due righe
			//Viene invertito l'html delle due righe
			var html_corrente = $('#allegati_rigo_'+id_corrente).html();
			var html_futura = $('#allegati_rigo_'+id_futura).html();
			$('#allegati_rigo_'+id_corrente).html(html_futura);
			$('#allegati_rigo_'+id_futura).html(html_corrente);
			
			
			//Viene scambiato il blocco di ordinamento
			var onclick_corrente = $('#ordine_'+id_corrente).html();
			var onclick_futura = $('#ordine_'+id_futura).html();
			$('#ordine_'+id_corrente).html(onclick_futura);
			$('#ordine_'+id_futura).html(onclick_corrente);

			//scambio degli id identificativi
			$('.allegati_ordine_'+corrente).attr('id', 'allegati_rigo_xxx');
			$('.allegati_ordine_'+futura).attr('id', 'allegati_rigo_'+id_corrente);
			$('.allegati_ordine_'+corrente).attr('id', 'allegati_rigo_'+id_futura);
			
			//Viene eseguita la pagina php che effettua la sostituzione
			$.ajax({ url: '/admin/ajax/allegati/move/'+id_corrente+'/'+corrente+'/'+id_futura+'/'+futura+'/'+tabella, success: function(data) {  } });
			

	}

function ajaxExecute(URL, OUTPUTID)
{
	if ( URL == '' ) return;
	
	var xmlHttp;
	try
	  {xmlHttp=new XMLHttpRequest();}
	catch (e)
	  {
	  try
		{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
	  catch (e)
		{
		try
		  {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
		catch (e)
		  {
		  alert("Your browser does not support AJAX!");
		  return;
		  }
		}
	  }
	  xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4 && OUTPUTID != '')
		  {
				document.getElementById(OUTPUTID).innerHTML=xmlHttp.responseText;
		  }
		}
	  xmlHttp.open("GET",URL,true);
	  xmlHttp.send(null);
}


function seleziona_tipo_video(valore)
{
	$('#upload_video_local').fadeOut('fast', function () { 
		
		$('#upload_video_remote').fadeOut('fast', function () {
			
			$('#'+valore).fadeIn();
			
			});
		
		 } );
	
}

function ShowDiv(ID)
{
	var stato = document.getElementById(ID).style.display;
	if(stato=='none' || stato=='' || stato == null ) { document.getElementById(ID).style.display='block'; }
	else if (stato=='block')  { document.getElementById(ID).style.display='none'; }
	else { document.getElementById(ID).style.display='none'; }
}


function ShowTab(ID, PREFIX)
{
	var TAG = 'div';
	var ATTRIB = 'id';
	var NAME = PREFIX+'_'+ID;
	if(document.getElementsByTagName)
	{
		//alert('nascondo tutto e visualizo '+NAME);
		var lista = document.getElementsByTagName(TAG);
		//alert('Elementi trovati: '+lista.length);
		for(i=0; i <= lista.length-1; i++)
		{
			if (  lista.item(i).getAttribute(ATTRIB) == null )
			{
					//trovato oggetto senza attributo
			}
			else
			{
				//alert( lista.item(i).getAttribute(ATTRIB) );
				var CURCLASS = lista.item(i).getAttribute(ATTRIB);
				
				if ( CURCLASS.length > 0 )
				{
					var NCLASS = CURCLASS.replace(PREFIX+'_', '');

					if ( CURCLASS == PREFIX+'_'+NCLASS &&  CURCLASS != NAME )
					{
						//alert('spengo il div '+CURCLASS);
						lista.item(i).style.display='none';
					}else{
						//alert( CURCLASS+' &egrave; diverso da '+PREFIX+'_'+NCLASS );
					}
					if ( CURCLASS == NAME )
					{
						//alert('accendo il div '+CURCLASS);
						lista.item(i).style.display='block';
					}
				}else{
					//alert('div non valido!');
				}
			}
		}
		return;
	}else{
		alert('Il tuo browser non supporta tutte le funzioni javascript di questo sito!');
		return;
	}
}
 function PopupCentrata(url,w,h)
 {
	if ( url == null ) { alert('Scegliere un indirizzo valido!'); return; }
	if ( h == null ) { alert('Scegliere una altezza valida!'); return; }
	if ( w == null ) { alert('Scegliere una larghezza valida!'); return; }

	
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	
	var stili = "top="+t+", left="+l+", width="+w+", height="+h+", status=no, menubar=no, toolbar=no scrollbar=no";

	window.open(url,"",stili);
 }


function share_selectall(prefix)
{
	var i = 0;
	var modulo = document.forms[prefix].elements;
	for (i=0; i<modulo.length; i++)
	{
		if(modulo[i].type == "checkbox")
		{
			modulo[i].checked = !(modulo[i].checked);
		}
	}
}


function mkdata(idelemento)
{
	var re1 = /^\d{2}[\/]\d{2}[\/]\d{4}$/;
	var re2 = /^\d{4}[\/]\d{2}[\/]\d{2}$/;
	var elemento = document.getElementById(idelemento);
	if (  elemento == null ) return;
	if ( elemento.value == '' )   elemento.value = '00/00/0000';
	var dato = elemento.value;
	dato = dato.replace(/[-.]/g,"/");
	var test1 = dato.search(re1);
	var test2 = dato.search(re2);
	var dt = dato.split('/');
	if ( test1 == 0 ) elemento.value = ( dt[2]+'-'+dt[1]+'-'+dt[0] );
	if ( test2 == 0 ) elemento.value = ( dt[0]+'-'+dt[1]+'-'+dt[1] );
	if ( test1 == -1 && test2 == -1 ) { alert('La Data '+elemento.value+' non ha un formato valido!\r\nUtilizzare il formato gg/mm/aaa'); elemento.value = ''; }
}
function test()
{
	alert("Js caricato correttamente!");
}

function chiudi()
{
	win = top;
	win.opener = top;
	win.close ();
}



function salva_e_chiudi(form)
{
	if ( document.getElementById(form) == null ) { alert('Il form '+form+' non esiste!'); return; }
	document.getElementById(form).submit();
	win = top;
	win.opener = top;
	win.close ();
	//window.close;
}

function conferma(titolo, frase, form)
{
	var risp;
	
	if ( document.getElementById(form) == null ) { alert('Il form '+form+' non esiste!'); return; }
	
	risp = confirm(titolo+'\r\n'+frase);
	
	
	
	if(risp==true)
	{
		document.getElementById(form).submit();
		//alert('operazione effettuata');//
	} else {
		alert('operazione annullata');
	}
}

function invia(form)
{
	document.getElementById(form).submit();
}

function cancella_allegato(id, percorso)
{
	risp = confirm('Cancellare il file selezionato?');
	if(risp==true) $('#'+id).load(percorso);
}


//]]>

