//espressione regolare che controlla che in una stringa ci siano solo numeri lettere e . - _
regExp=/[a-z0-9A-Z]|\.\_\-/;

//Le Funzioni apriPopUp e testPopUp permettono di ritornare un messaggio di errore se č presente un blocco di popUp
//La libreria deve essere inclusa nella pagina chiamante.
//nella pagina chiamante deve essere settata una variabile popUpAperta=false
//nella pagina chamata deve essere eseguita l'istruzione window.opener.popUpAperta=true
//la popUp deve esssere aperta tramite la funzione apriPopUp
function apriPopUp(url,nWindow,param)
{  
	window.open(url,nWindow,param);
	setTimeout("testPopUp()",10000);
}

function chiudiLezione(){
	location.href('/corso/index.asp');
	window.close();
	window.opener.focus();
}

function controllaTel(nTel){
	if(nTel.indexOf('0')==0){
		nTel=nTel.slice(1,(nTel.length))
	}
	
	if((isNaN(nTel)) || (nTel.length<5)){
		return false;
	}else{
		return true;
	}
}

//data una form myForm restituisce il primo campo non compilato oppure Null
function controllaRichiesti(myForm)
{
	for (i=0;i<myForm.elements.length;i++)
	{
		if (myForm.elements[i].value=="")
		{
			return myForm.elements[i];
		}
	}
	return null;
}

function controllaRichiesti2(myForm)
{
	for (i=0;i<myForm.elements.length;i++)
	{
		if ((myForm.elements[i].value=="") && (myForm.elements[i].name!="webA") && (myForm.elements[i].name!="codVendA") && (myForm.elements[i].name!="codScontoA") && (myForm.elements[i].name!="areeA") && (myForm.elements[i].name!="corsoA"))
		{
			return myForm.elements[i];
		}
	}
	return null;
}

function controllaRichiesti3(myForm)
{
	for (i=0;i<myForm.elements.length;i++)
	{
		if ((myForm.elements[i].value=="") && (myForm.elements[i].name!="nomeA") && (myForm.elements[i].name!="indirizzoA") && (myForm.elements[i].name!="pivaA") && (myForm.elements[i].name!="telA") && (myForm.elements[i].name!="webA") && (myForm.elements[i].name!="codVendA") && (myForm.elements[i].name!="codScontoA") && (myForm.elements[i].name!="areeA") && (myForm.elements[i].name!="corsoA"))
		{
			return myForm.elements[i];
		}
	}
	return null;
}


function testPopUp()
{
	if(popUpAperta==false)
		alert("Attenzione! Blocco PopUp attivo. Disattivarlo.");
}	

function formattaTesto(stringa)
{
//rende il testo stampabile sistemandi quello che puņ dare fastidio a JScipt
return stringa.replace("'","~")	
}

function Confronta(a,b){
	if(!(isNaN(a)&&isNaN(b))){
		if(Number(a)>Number(b)){
			return true;
		}
	}
	else
	{
		if(a>b){
			return true;
		}
	}
	return false;
}

function Ordina(valOrd,valori){
	for(a=0;a<valori.rows.length;a++)
		for(i=a;i<valori.rows.length;i++)
			if(Confronta(valori.rows[i].cells[valOrd].innerHTML,valori.rows[a].cells[valOrd].innerHTML))
				valori.rows[i].swapNode(valori.rows[a]);
}

function ControllaMail(EmailAddr)
{
Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (Filtro.test(EmailAddr))
  return true;
else
  return false;
}

//ritorna l'elemento 
function el(id) {
  return document.getElementById(id);
}

//cambia classe 
function sc(obj,cn)
{
  obj.className=cn;
}

/*function toNumber(i)
{
	return i.replace(",",".")*1
}*/

function toNumber(i)
{
	i=i.toString();
	return i.replace(",",".")*1
}

function readTextFile(url)
{
	dojo.io.bind({
		url: url,
		load: function(type, data, evt){ vReturn=data},
		error: function(type, error){ vReturn=""},
		mimetype: "text/plain"
	});
	return vReturn
}

function rimettiVirgolette(stringa){
	arrStringa=stringa.split("~")
	if(arrStringa.length!=0){
		for (i=1; i<=(arrStringa.length)-1 ;i++){
			stringa=stringa.replace("~","\"")	
		}
	}
	
	arrStringa=stringa.split("|")
	if(arrStringa.length!=0){
		for (i=1; i<=(arrStringa.length)-1 ;i++){
			stringa=stringa.replace("|","'")	
		}
	}
	return stringa;
}

function posizionaFinestra(finestra,HTML,elWidth,elHeight){
	elemento=el(finestra)
	
	larghezza=elemento.style.width=elWidth
	larghezza=larghezza/2
	altezza=elemento.style.height=elHeight
	altezza=altezza/2
	
	hScreen=screen.Height
	hScreen=hScreen/2
	var top=(hScreen-altezza+document.documentElement.scrollTop)-80

	wScreen=screen.Width
	wScreen=wScreen/2
	var left=wScreen-larghezza

	elemento.style.top=top
	elemento.style.left=left

	elemento.innerHTML=HTML;
	elemento.className="";
}

function controlloIVA(vIVA)
{
iva = /^([0-9]{11})+$/;
if (iva.test(vIVA)){
	var i=0;
	var s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += vIVA.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( vIVA.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;}
	if( ( 10 - s%10 )%10 != vIVA.charCodeAt(10) - '0'.charCodeAt(0) )
		return false;
	else
		return true;}
else
	return false;
}

function apiciForJS(stringa){
	arrStringa=stringa.split("'")
	if(arrStringa.length!=0){
		for (i=1; i<=(arrStringa.length)-1 ;i++){
			stringa=stringa.replace("'","\'")	
		}
	}
	return stringa;
}

function over(i,stato){
	if (stato=='dis'){
		document.getElementById('elenco'+i).className='rolldis'
	}else{
		document.getElementById('elenco'+i).className='roll'
	}
}
function out(i,stato){
	if (stato=='dis'){
		document.getElementById('elenco'+i).className='disabilitato'
	}else{
		document.getElementById('elenco'+i).className=''
	}
}