// JavaScript Document

function addEvent(obj, evt, func) { 
	// AGGIUNGE una funzione all'event-handler di un oggetto (es. aggiunge funzione a window.onload)
	// anzichè sovrascriverlo (e permette l'uso di "this" nella funzione)
	  if(obj[evt]) { 
		obj[evt]=function(f,g){ 
		   return function(){ 
			 f.apply(this,arguments); 
			 return g.apply(this,arguments); 
		   }; 
		}(func, obj[evt]); 
	  } else obj[evt]=func; 
} 

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_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];}}
}

// PER NASCONDERE/MOSTRARE DIV (MANTENENDO LO SPAZIO OCCUPATO)
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// PER NASCONDERE/MOSTRARE DIV
function displayLayers() { //v6.0
  var i,p,v,obj,args=displayLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

// PER NASCONDERE/MOSTRARE UN DIV (se visibile, nasconde, e viceversa)
function mostraNascondi(idElemento) {
    current=(document.getElementById(idElemento).style.display == 'none') ? 'block' : 'none';
    document.getElementById(idElemento).style.display = current;
}

// PER EVIDENZIARE (per es.l'etichetta relativa al campo selezionato per la compilazione)
function evidenzia(objId) {  //reloads the window if Nav4 resized
  var obj;
  if ((obj=document.getElementById(objId))!= null)
  {
  	if (obj.className.indexOf("evidenzia_bold")==-1 ) 
  	{	
  		obj.className = obj.className + " evidenzia_bold";
	}
   }
 }

// PER TOGLIERE EVIDENZIAZIONE (per es. quando si seleziona un altro campo)
function spegni(objId) {  //reloads the window if Nav4 resized
  var obj;
  if ((obj=document.getElementById(objId))!= null){
  	if (obj.className.indexOf("evidenzia_bold")!=-1 ) {	
  		obj.className = obj.className.replace("evidenzia_bold","");
	}
  }
 }
	
// PER AGGIUNGERE AI PREFERITI
function aggiungiPreferiti() {
	
	var urlAddress = "http://www.click2drive.it"; 
	var pageName = "CLICK2DRIVE"; 
 
	if ( window.sidebar && window.sidebar.addPanel ) {
		window.sidebar.addPanel( pageName, urlAddress, "" );
	} else if (window.external) {
		window.external.AddFavorite(urlAddress,pageName) ;
	} else { 
		alert("Il tuo browser non supporta questa funzione.\nDovrai aggiungere tu CLICK2DRIVE ai Preferiti..."); 
  } 

}

// PER APRIRE L'ONDEMAND
function apriLezioneDaLista(idListaLezioni,idUtente, webRoot) {
	var idLezione = "#";
	if (document.getElementById(idListaLezioni)){
	    idLezione = document.getElementById(idListaLezioni).value;
	} else {
	    idLezione = document.getElementsByName(idListaLezioni)[0].value;
	}
	if (idLezione!="#"){
		apriOnDemand(webRoot + '/script/restricted/ELearningOnDemand_LessonViewer.aspx?lesson_id=' + idLezione + '&account_id=' + idUtente);
	}
}
function apriLezione(idLezione,idUtente, webRoot) {
	if (idLezione!="#"){
		apriOnDemand(webRoot + '/script/restricted/ELearningOnDemand_LessonViewer.aspx?lesson_id=' + idLezione + '&account_id=' + idUtente);
	}
}
function apriOnDemand(pagina) {		
	var w = (1000<screen.availWidth)?1000:screen.availWidth;
	var h = (700<screen.availHeight)?700:screen.availHeight;
	var l = Math.floor((screen.availWidth-w)/2);
	var t = Math.floor((screen.availHeight-h)/2);
	var win = window.open(pagina,"ondemand","scrollbars=yes,resizable=yes,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
	if (win.window.focus) {win.window.focus();} 
}

// PER APRIRE IL SIMULATORE
function apriSimulatore(pagina) {		
	var w = (850<screen.availWidth)?850:screen.availWidth;
	var h = (700<screen.availWidth)?700:screen.availHeight;
	var l = Math.floor((screen.availWidth-w)/2);
	var t = Math.floor((screen.availHeight-h)/2);
	var win = window.open(pagina,"simulatore","scrollbars=yes,resizable=yes,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
	if (win.window.focus) {win.window.focus();} 
}

// PER APRIRE IL LIVE
function apriLive(pagina) {		
	var w = (1000<screen.availWidth)?1000:screen.availWidth;
	var h = (700<screen.availHeight)?700:screen.availHeight;
	var l = Math.floor((screen.availWidth-w)/2);
	var t = Math.floor((screen.availHeight-h)/2);
	var win = window.open(pagina,"ondemand","scrollbars=yes,resizable=yes,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
	if (win.window.focus) {win.window.focus();} 
}

// PER LA GESTIONE DELLE OFFERTE
function AddCap(inputId, listId) {
        var inputCap, capList, newCap;
        
        inputCap = document.getElementById(inputId);
        capList = document.getElementById(listId);
        newCap = inputCap.value;
        
        capList.options[capList.options.length] = new Option(newCap, newCap);
        inputCap.value = '';
        inputCap.focus();
}

function RemoveCap(listId) {
        var capList;
        
        capList = document.getElementById(listId);
        while (capList.selectedIndex != -1) {
                capList.options[capList.selectedIndex] = null;
        }
}
