function popCorso(idCorso)
{
	window.open("act/opencourse.php?idCourse="+idCorso,"Corso","width=500px,height=550px,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function alertkey(e) 
{
  if( !e ) 
  {
    if( window.event ) {
     //Internet Explorer
      e = window.event;
    } else {
      return;
    }
  }
  if( typeof( e.keyCode ) == 'number'  ) {
    //DOM
      e = e.keyCode;
  } else if( typeof( e.which ) == 'number' ) {
    //NS 4 compatible
      e = e.which;
  } else if( typeof( e.charCode ) == 'number'  ) {
    //also NS 6+, Mozilla 0.9+
      e = e.charCode;
  } else {
    //total failure, we have no way of obtaining the key code
    return;
  }
  if(e==13) {
     doSubmit();
     return false;
  }
}

function openVideoWin(strUrl)
{
	window.open(strUrl,'Video','width=655px,height=340px,top=100px,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
}

function ControllaPIVA(pi)
{
	s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;
	}
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
    return false;

	return true;
}


//	Controllo della Partita I.V.A.
//	Linguaggio: JavaScript

function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;

	cf = cf.toUpperCase();

	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return false;
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return false;
	return true;
}

function OpenHelp(id)
{
	finestra = window.open("popup.php?page=help&id="+id,"Help","width=350,height=250,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes");
	finestra.focus();
}
function doSubmitCarrello()
{
	if (controllaQta())
		document.getElementById("dati").submit();
}
function controllaQta()
{
	for(i=0;i<100;i++)
	{
		voInputQta = document.getElementById("arrayQta["+i+"]");
		if (voInputQta)
		{
			voInputQtaMax = document.getElementById("maxQta["+i+"]");
			voInputCorso = document.getElementById("nomeProd["+i+"]");
			if (voInputQtaMax && voInputCorso)
			{
				vnValore = voInputQta.value.replace(/^0+/,"");
				if (parseInt(vnValore) > parseInt(voInputQtaMax.value))
				{
					alert("Attenzione: la quantita' massima acquistabile per il corso \""+voInputCorso.value+"\" e' "+voInputQtaMax.value);
					voInputQta.value = voInputQtaMax.value;
				}
				else
					voInputQta.value = vnValore;
			}
		}
	}
	return true;
}
