/*FUNZIONI GENERICHE UTILIZZABILI DA QUALSIASI PAGINA*/
function sendNews(lan){
	if (!lan) {lan='it';}
	nWidth=490;
	nHeight=450;
	window.open("/dynnew/"+lan+"/popup/popSendNews.phtml?link="+escape(window.location.href),"WinPopUp","width="+nWidth+",height="+nHeight+",directories=no,toolbar=no,scrollbars=no,resizable=no,status=no");
}

function submitForm(button, form){
		button.disabled=true;
		form.submit();
}

/*FUNZIONI NON GENERICHE MA CONDIVISE DA DUE O PIU' PAGINE AVENTI SIMILE STRUTTURA*/

function ctrlNomeCognomeEmailPhoneNumber ()
{
	prefisso = document.ull.pref.value;
	numero = document.ull.tel.value;
	prefisso = trim_string(prefisso);
	numero = trim_string(numero);

	if ((prefisso == '') && (numero == '' ))
	{
		alert('Inserire il prefisso e il numero.');
		return(false);
	}

	if(prefisso == '')
	{
		alert('Inserire il prefisso.');
		return(false);
	}
	if(numero == '' )
	{
		alert('Inserire il numero telefonico.');
		return(false);
	}
	if(!Is_Number(prefisso))
	{
		alert('Inserire un prefisso valido');
		return(false);
	}

	if(prefisso.substr(0,1)!='0')
	{
		alert('Inserire un prefisso valido');
		return(false);
	}


	if(!Is_Number(numero))
	{
		alert('Inserire un numero di telefono valido');
		return(false);
	}

	if ((numero.substr(0,1)=='0') || (numero.substr(0,1)=='1'))
	{
		alert('Inserire un numero di telefono valido');
		return(false);
	}


	var espressione = /^[a-zA-Z][àèéùòa-zA-Z\ ]*$/;
	var stringa = document.ull.nome.value;
	if (!espressione.test(stringa)  )
	{
		alert("Nome non valido!");
		return false;
	}

	if ( stringa.length<3 )
	{
		alert("Il nome deve contenere almeno 3 caratteri!");
		return false;
	}

	espressione = /^[a-zA-Z][àèéùòa-zA-Z\ ]*$/;
	stringa = document.ull.cognome.value;
	if (!espressione.test(stringa))
	{
		alert("Cognome non valido!");
		return false;
	}


	if ( stringa.length<2 )
	{
		alert("Il cognome deve contenere almeno 2 caratteri!");
		return false;
	}



	espressione = /^[a-zA-Z][a-zA-Z1-9_\-\.]*$/;
	stringa = document.ull.username.value;
	if (!espressione.test(stringa))
	{
		alert("E-mail non valido!");
		return false;
	}
	if ( stringa.length<2 )
	{
		alert("Errore nel campo E-mail!");
		return false;
	}

	espressione = /^[a-zA-Z1-9_\-][a-zA-Z1-9._\-]*\.[a-zA-Z1-9]+$/;
	stringa = document.ull.domain.value;
	if (!espressione.test(stringa))
	{
		alert("Dominio non valido!");
		return false;
	}

	if ( stringa.length<3 )
	{
		alert("Errore nel campo E-mail!");
		return false; 
	}


	return(true);

}


function trim_string(string)
{
	var ichar, icount;
	var strValue = string;
	ichar = strValue.length - 1;
	icount = -1;
	while (strValue.charAt(ichar)==' ' && ichar > icount)
		--ichar;
	if (ichar!=(strValue.length-1))
		strValue = strValue.slice(0,ichar+1);
	ichar = 0;
	icount = strValue.length - 1;
	while (strValue.charAt(ichar)==' ' && ichar < icount)
		++ichar;
	if (ichar!=0)
		strValue = strValue.slice(ichar,strValue.length);
	return strValue;
}

function Is_Number(sDato)
{
	var i;
	var CodeChr;
	for (i = 0;  i < sDato.length;  i++)
	{
		CodeChr = sDato.charAt(i);
		if ((CodeChr<'0') || (CodeChr>'9'))
		return(false);
	}
	return(true);
}

function PhoneNumber()
{
	if (typeof(document.ull[0].pref) != "undefined")
	{
		prefisso = document.ull[0].pref.value;
		numero = document.ull[0].tel.value;
	}
	else
	{
		prefisso = document.ull.pref.value;
		numero = document.ull.tel.value;
	}
	prefisso = trim_string(prefisso);
	numero = trim_string(numero);

	if ((prefisso == '') && (numero == '' ))
	{
		alert('Inserire il prefisso e il numero.');
		return(false);
	}

	if(prefisso == '')
	{
		alert('Inserire il prefisso.');
		return(false);
	}
	if(numero == '' )
	{
		alert('Inserire il numero telefonico.');
		return(false);
	}
	if(!Is_Number(prefisso))
	{
		alert('Inserire un prefisso valido');
			return(false);
	}

	if(prefisso.substr(0,1)!='0')
	{
		alert('Inserire un prefisso valido');
			return(false);
	}


	if(!Is_Number(numero))
	{
		alert('Inserire un numero di telefono valido');
		return(false);
	}

/*
	    if ((numero.substr(0,1)=='0') || (numero.substr(0,1)=='1'))
	    {
		    alert('Inserire un numero di telefono valido');
			return(false);
	    }
*/

	if ( numero.length<4 ) {
		alert("Inserire un numero di telefono valido");
		return false;
	}

	var mercato = document.ull.mkt.value;
	if (mercato=='RES') {
		if (    (prefisso.length + numero.length > 10)
			&& !( (prefisso.length + numero.length == 11) && (numero.substr(0,1)=='1') )
		) {
			alert("Inserire un telefono valido");
			return false;
			}
	}

// *****************************

	document.getElementById('wait').style.display=''; 
	document.getElementById('tastoverif').style.display='none'; 
	document.getElementById('tipo').style.display='none'; 

	return(true);
}


function Invia()
{
	if(PhoneNumber()) document.ull.submit();
}


/*utilizzato per le form di tutto incluso*/
function PhoneNumber_TI()
{

	if (typeof(document.ull1[0].indirizzo) != "undefined")
	{
		indirizzo = document.ull1[0].indirizzo.value;
		civico = document.ull1[0].civico.value;
		comune = document.ull1[0].comune.value;
		provincia = document.ull1[0].provincia.value;
		cap = document.ull1[0].cap.value;
		tipoindirizzo = document.ull1[0].tipoindirizzo.value;
	}
	else
	{
		indirizzo = document.ull1.indirizzo.value;
		civico = document.ull1.civico.value;
		comune = document.ull1.comune.value;
		provincia = document.ull1.provincia.value;
		cap = document.ull1.cap.value;
		tipoindirizzo = document.ull1.tipoindirizzo.value;
	}

	indirizzo = trim_string(indirizzo);
	civico = trim_string(civico);
	comune = trim_string(comune);
	provincia = trim_string(provincia);
	cap = trim_string(cap);
	tipoindirizzo = trim_string(tipoindirizzo);

	if(tipoindirizzo == '')
	{
		alert('Inserire il tipo indirizzo.');
		return(false);
	}
	if(indirizzo == '')
	{
		alert('Inserire l\'indirizzo.');
		return(false);
	}
	if(civico == '' )
	{
		alert('Inserire il civico .');
		return(false);
	}
	if(cap == '' )
	{
		alert('Inserire il cap .');
		return(false);
	}
	if(!Is_Number(cap))
	{
		alert('Inserire un cap valido');
		return(false);
	}
	if(comune == '')
	{
		alert('Inserire il comune.');
		return(false);
	}
	if(provincia == '' )
	{
		alert('Selezionare la provincia .');
		return(false);
	}

	document.getElementById('wait2').style.display=''; 
	// document.getElementById('tastoverifTI').style.display='none'; 
	document.getElementById('tipoTI').style.display='none'; 

	return(true);
}

function Invia_TI()
{
		if(PhoneNumber_TI()) document.ull.submit();
}



function get_url_param(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
	var regexS = "[\\?&]"+name+"=([^&#]*)"; 
	var regex = new RegExp( regexS ); 
	var results = regex.exec( window.location.href ); 
	if( results == null ) return ""; 
	else return results[1];
}


// Popup video verso Libero Video
function videoPopup(theID) {
	vPopup = window.open("about:Blank","videopopupid","width=420,height=353,status=no,menubar=no,resizable=no,scrollbars=no,toolb	ar=no,location=no,directories=no");
	vPopup.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	vPopup.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
	vPopup.document.write('<head>');
	vPopup.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
	vPopup.document.write('<title>infostrada.it</title>');
	vPopup.document.write('</head>');
	vPopup.document.write('<body>');
	vPopup.document.write('<object width="400" height="333"><param name="movie" value="http://video.libero.it/static/swf/eltvplayer.swf?id='+ theID +'&ap=1" /><embed src="http://video.libero.it/static/swf/eltvplayer.swf?id='+ theID +'&ap=1" width="400" height="333" type="application/x-shockwave-flash"></embed></object>');
	vPopup.document.write('</body>');
	vPopup.document.write('</html>');
}

// Popup video verso Libero Video
// Si apre solo se chiamato con un url che abbia un parametro openvideo==OpenVideoValue
function videoPopupIf(theID, OpenVideoValue) {
	ovvalue = get_url_param("openvideo");
	if (ovvalue == OpenVideoValue) {
		videoPopup(theID);
	}
}

function validate_this(obj) {	 	
	
	var stringa = obj.value; 
	switch(obj.name) {
		case 'cap':  
		  var pattern_esatto   = new RegExp("^([0-9]?){5}$"); 
		  var pattern          = new RegExp("([0-9]?){5}"); 
		  break;
		case 'civico':  // NUM.CIVICO 123 || 123/A1
		  var pattern_esatto = new RegExp("^(([1-9]{1}[0-9]*)(/{1}[a-zA-Z]*[0-9]*[a-zA-Z]*)?|[^0-9/]{1}.*)$");
		  var pattern        = new RegExp("^(([1-9]{1}[0-9]*)(/{1}[a-zA-Z]*[0-9]*[a-zA-Z]*)?|[^0-9/]{1}.*)");   
		  break;
		
	}

	var result = stringa.search(pattern_esatto);
	var campo = obj.value;
	var new_campo='';	

	if (result<0) {
		if (stringa.match(pattern)) {
			if (obj.name=='civico') alert('Formato numero civico errato.');
			obj.value = stringa.match(pattern)[0];
		} else {
		  obj.value='';
		}
	} 
	
}	