function IsEmpty(str)
{
	return (str.replace(/ /g,"").length == 0);
}

/* 
Parametri
	form: la form (mettere tutto il nome della form es. document.forms[0])
	il resto dei parametri sono triplette:
	1:	Stringa nome campo form es. 'nome' -> document.forms[0].nome
	2:	Stringa messaggio errore es. 'E\' necessario inserire un valore'
	3:	Stringa contenete due numeri es: '10' -> Obbligatorio Numerico
		il secondo numero può essere omesso se semplicemente obbligatorio o select obbligtoria
		1: se richiesto o select
			0: non richiesto
			1: obbligatorio
			2: data (ci devono essere tutti e tre i campi della data separati da una virgola nel parametro 1)
		2: tipo di dato
			se data:
			0: non obbligatorio
			1: obbligatorio
			altrimenti:
			0: numerico
			1: email
			2: alfanumerico
			3: almento un checkbox o un radiobutton selezionato
			4: un indirizzo internet (senza @ per non confonderla con l'email)
*/
function Control(form)
{
	var args=Control.arguments;
	var Err=false;
	var chr1;
	var chr2;
	var str;
	for(var i=1; i < args.length; i+=3)
	{
		chr1=""+args[i+2].substring(0,1);
		chr2=""+args[i+2].substring(1,2);
		switch(chr1)
		{
			case '0':
			case '1':
				if(""+form[args[i]]=="undefined")
					return false;

				if(""+form[args[i]].type=="select-one" || ""+form[args[i]].type=="select-multiple")
					str=""+form[args[i]][form[args[i]].selectedIndex].value; 
				else
					str=""+form[args[i]].value;

				if(IsEmpty(str) && chr1=="1")
				{
					Err=true;
					break;
				}
				if(!IsEmpty(str))
				{
					switch(chr2)
					{
						case "0":	// Numerico
							if(isNaN(str))
								Err=true;
							break;
						case "1":	// E-Mail
							if(!IsEmail(str))
								Err=true;
							break;
						case "2":	// Alfanumerico
							var stringa=""+str;
							for(var po=0; po < stringa.length; po++)
							{
								if(!(stringa.charCodeAt(po) >= 97 && stringa.charCodeAt(po) <= 122 || stringa.charCodeAt(po)==32)) // Lettere minuscole e lo spazio
								{
									if(!(stringa.charCodeAt(po) >= 65 && stringa.charCodeAt(po) <= 90)) // Lettere maiuscole
									{
										if(!(stringa.charCodeAt(po) >= 48 && stringa.charCodeAt(po) <= 57)) // Numeri
										{
											Err=true;
											break;
										}
									}
								}
							}
							break;
						case "3":	// Checkbox / Radio - Almeno uno selezionato
							var Chk=false;
							if(""+form[args[i]].length!="undefined")
							{
								for(var kk=0; kk < form[args[i]].length; kk++)
								{
									if(form[args[i]][kk].checked)
									{
										Chk=true;
										break;
									}
								}
								Err=!Chk;
							}
							else
								Err=!form[args[i]].checked;
							break;
						case "4":
							if(""+str.indexOf("@")!=-1)
								Err=true;
							break;
					}
				}
				break;
			case '2':
				{
					var params=args[i].split(",");
					if(!isDate(""+form[params[0]][form[params[0]].selectedIndex].value,""+form[params[1]][form[params[1]].selectedIndex].value,""+form[params[2]][form[params[2]].selectedIndex].value,(""+chr2=="0")))
					{
						alert(args[i+1]);
						if(""+form[params[0]].type!="hidden" && ""+form[params[0]].disabled != "true")
							form[params[0]].focus();
						return false;
					}
				}
				break;
		}
		if(Err)
			break;
	}
	if(Err)
	{
		alert(args[i+1]);
		if(""+form[args[i]].length!="undefined")
		{
			if(""+form[args[i]][0].type=="checkbox" || ""+form[args[i]][0].type=="radio") 
			{
				if(""+form[args[i]][0].type!="hidden" && ""+form[args[i]][0].disabled != "true")
				{
					form[args[i]][0].focus();
				}
			}
			else
			{
				if(""+form[args[i]].type!="hidden" && ""+form[args[i]].disabled != "true")
					form[args[i]].focus();
			}
		}
		else
		{
			if(""+form[args[i]].type!="hidden" && ""+form[args[i]].disabled != "true")
				form[args[i]].focus();
		}
		return false;
	}
	return true;
}

function IsEmail(email)
{
	var at, punto;
	at=email.indexOf("@",0);
	if(at==-1) // Se manca la chiocciola
		return false;
	if(email.substring(0,at) == "") // Se manca il nome dell'utente
		return false;
	punto=email.indexOf(".",at+1);
	if(punto==-1) // Se manca il punto
		return false;
	if(email.substring(at+1,punto) == "") // Se manca il nome del server
		return false;
	if(email.substring(punto+1,email.length) == "") // Se manca il tipo del server
		return false;

	return true;
}

function MaxChar(E,max)
{
	if(E.value.length >= max)
		E.value=E.value.substring(0,(max-1))
}

function NoFrame()
{
	if(""+window.name!="")
	{
		window.parent.location=""+window.location;
	}
}

var T1;
function BlankStatus(txt)
{
	window.status=""+txt;
	T1=setTimeout("Blank('" + txt+ "')",0);
}

function TypeWriterStatus(StatusTxt)
{
	//clearTimeout(T1);
	var str=""+window.status;
	if(str != "undefined" && str.length < StatusTxt.length)
	{
		window.status+=""+StatusTxt.charAt(str.length);
		setTimeout("TypeWriterStatus('" + StatusTxt + "')",100);
	}
	else
	{
		//Blank(""+window.status);
		//setTimeout("clearTimeout(T1); Blank('');",1500)
		setTimeout("window.status=''",1500)
		setTimeout("TypeWriterStatus('" + StatusTxt + "')",2500);
	}
}

function ScrollTextStatus(StatusTxt)
{
	var str=""+window.status;
	if(str.replace(/ /g,"")!="" && str.replace(/ /g,"")!="undefined")
	{
		window.status=""+str.substring(1,str.length)+str.charAt(0);
		setTimeout("ScrollTextStatus('" + StatusTxt + "')",100);
	}
	else
	{
		window.status="                                                                                                                                "+StatusTxt;
		ScrollTextStatus(StatusTxt);
	}
}

// Il secondo parametro (boolean) specifica se può essere vuota
function isValid(str)
{
	var canBeEmpty=true;
	if(isValid.arguments.length>1)
		canBeEmpty=isValid.arguments[1];
	if(""+str=="null" || ""+str=="undefined" || (((canBeEmpty)?false:((IsEmpty(str))?true:false))))
		return false;
	return true;
}

function isDate(day, month, year)
{
	var cbe=true;
	if(isDate.arguments.length>3)
		cbe=isDate.arguments[3];
	if(day=="" && month=="" && year=="" && cbe)
		return true;
	if(isValid(day,false) && isValid(month,false) && isValid(year,false))
	{
		var days4month=new Array(31,28,31,30,31,30,31,31,30,31,30,31);

		if(parseInt(day) <= (parseInt(days4month[parseInt(month)-1]) + (((parseInt(month) == 2) && ((parseInt(year) % 4 == 0) && ((!(parseInt(year) % 100 == 0)) || (parseInt(year) % 400 == 0))))?1:0)))
			return true;
	}
	return false;
}

function getParams()
{
	var strurl=""+window.document.location;
	strurl=((strurl.indexOf("?")==-1)?"":strurl.substring(strurl.indexOf("?")+1,strurl.length));
	var splitstr=strurl.split("&");
	var a;
	var paramarray=new Array();
	for(var i in splitstr)
	{
		a=splitstr[i].split("=");
		paramarray[""+a[0]]=""+a[1];
	}
	return paramarray;
}

function Submit()
{
	var frm=Submit.arguments[0];
	if(""+frm!="undefined")
	{
		for(var i=1; i < Submit.arguments.length; i+=2){
			frm[Submit.arguments[i]].value=Submit.arguments[i+1];
		}
		frm.submit();
	}
}

function removeSelectedOptions()
{
	var el=removeSelectedOptions.arguments[0];
	while(el.selectedIndex!=-1)
		el.remove(el.selectedIndex);
}

function selectAllOptions()
{
	var el=selectAllOptions.arguments[0];
	for(var i=0; i < el.length; i++)
		el[i].selected=true;
	return true;
}

function removeAllOptions()
{
	var el=removeAllOptions.arguments[0];
	while(el.length>0)
		el.remove(0);
}

function addOption()
{
	var ok=true;
	var el=addOption.arguments[0];
	var val=addOption.arguments[1];
	var text=addOption.arguments[2];
	for(var i=0; i < el.length; i++)
	{
		if(el[i].value==val)
		{
			ok=false;
			break;
		}
	}
	if(ok)
	{
		var newel = el.ownerDocument.createElement('option');
		newel.text = text;
		newel.value = val;
		el.options.add(newel);
	}
}

function checkAll()
{
	var el=checkAll.arguments[0];
	var from=checkAll.arguments[1];
	if(""+from=="undefined")
		from="";
	if(""+el!="undefined")
	{
		if(""+el.length!="undefined")
		{
			for(var i=0; i < el.length; i++)
			{
				if(""+from!="")
					//el[i].checked=document.frm.chkall.checked;
					el[i].checked=from;
				else
					el[i].checked=!el[i].checked;
			}
		}
		else
		{
			if(""+from!="")
				//el[i].checked=document.frm.chkall.checked;
				el.checked=from;
			else
				el.checked=!el.checked;
		}
	}
}

function OpenWin()
{
	var win=OpenWin.arguments[0];
	var target=OpenWin.arguments[1];
	if(""+target=="undefined")
		target="_blank";
	var options=OpenWin.arguments[2];
	if(""+options=="undefined")
		options="";
	var w=window.open(win,target,options);
	w.focus();
}

function OpenTest(win)
{
	var w=792;
	var h=550;
	if(OpenTest.arguments.length>1)
		w=OpenTest.arguments[1];
	if(OpenTest.arguments.length>2)
		h=OpenTest.arguments[2];

	var numofparts=prompt("Inserire un numero da 2 a 4 e premere \"Consenti\" su ciascuna finestra.",2);
	if(numofparts!=null && !isNaN(numofparts))
	{
		if(numofparts<2)
			numofparts=2;
		else if(numofparts>4)
			numofparts=4;
		for(var i=0; i < numofparts; i++)
		{
			setTimeout("OpenWind('" + win + "'," + w + "," + h + ")",i*7000);
		}
	}
}

function OpenWind(win)
{
	var w=792;
	var h=550;
	if(OpenWind.arguments.length>1 && OpenWind.arguments[1]!=null)
		w=OpenWind.arguments[1];
	if(OpenWind.arguments.length>2 && OpenWind.arguments[2]!=null)
		h=OpenWind.arguments[2];
	var l=(window.screen.availWidth - w - 10) / 2;
	var t=(window.screen.availHeight - h - 20) / 2;
	var opt="";
	if(OpenWind.arguments.length>3)
		opt=""+OpenWind.arguments[3];
	if(opt!="" && opt!="null" && opt.charAt(0)!=",")
		opt="," + opt;
		
	if(""+opt!="null")
		window.open(win,"_blank","width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + opt);
	else
		window.open(win,"_blank");
}

function CloseWin()
{
	try
	{
		if(""+window.opener.location!="undefined")
			window.opener.location.reload();
	}
	catch(e){}
	window.close();
}

function ControlCheck()
{
	var el=ControlCheck.arguments[0];
	var chk=true;
	if(""+ControlCheck.arguments[1]!="undefined")
		chk=ControlCheck.arguments[1];
	ret=false;
	if(""+el!="undefined")
	{
		if(""+el.length!="undefined")
		{
			for(var i=0; i < el.length; i++)
			{
				if(""+el[i].checked==""+chk)
				{
					ret=true;
					break;
				}
			}
		}
		else
		{
			if(""+el.checked==""+chk)
			{
				ret=true;
			}
		}
	}
	return ret;
}

function Controlregistrazione()
{
	if(!document.reg.FlagConsenso[0].checked && !document.reg.FlagConsenso[1].checked)
	{
		alert("E' necessario esprimere il proprio consenso!");
		document.reg.FlagConsenso[0].focus();
		return false;
	}
	if(document.reg.FlagConsenso[1].checked)
	{
		document.reg.action="default.asp";
		//document.forms[0].target="_top";
		document.reg.target="_self";
		document.reg.method="post";
		alert("Registrazione annullata");
	}
	return true;	
}

function TestAudioVideo(server)
{
	var w=750;
	var h=500;
	var l=(window.screen.width/2)-(w/2);
	var t=(window.screen.height/2)-(h/2)-20;
	window.open("http://www.fastmeeting.net/fastmeeting/TestAudioVideo.asp" + ((""+server!="undefined" && ""+server!="")?"?server=" + server:""),"_blank","width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ",scrollbars=0");
}

function delete_dati() {
	if(confirm("Attenzione!\nSe clicchi su Ok, i tuoi dati verranno eliminati definitivamente."))
		window.location.href='reg.asp?elimina=y';
}
function popup() { 
	theURL = "http://www.tinnova.it/portali_lista.asp";
	features=",width=330,height=250,scrollbars=1";
	winName = "";
  window.open(theURL,winName,features);
}

function popup_fgiuridica (id_session) {
	URL = "http://www.tinnova.it/alert_formag.asp?iduser="+id_session+"&idportal=6";
	features = ",width=380, height=290, top=300, left=350, scrollbar=0";
	winName = "";
	window.open(URL,winName,features);
}	

function ShowLayer(choose_div) {
	if(document.frm.PrivGroups.checked || document.frm.PrivAmminGroups.checked){
		if(choose_div == "numgruppi_portali"){
			document.getElementById("numGruppi").className='numGruppiv';
			document.getElementById("portali").className='portaliv';
			for(var i=0; i<document.frm.portali.length; i++)
				document.frm.portali[i].checked=false;
		}			
		if(choose_div == "portali"){
			document.getElementById("portali").className='portaliv';
			for(var i=0; i<document.frm.portali.length; i++)
				document.frm.portali[i].checked=true;
		}
	} else {
		//if(choose_div == "numgruppi_portali") {
			document.getElementById("numGruppi").className='numGruppih';
			document.getElementById("portali").className='portalih';
		//}
	}
}

function ChooseDate(val, xPos, yPos)
{
	var dt = new Array();
	source = val;
	if (""+source.length!="undefined")
	{
		if(""+val[0].tagName=="SELECT")
			dt[0] = val[0][val[0].selectedIndex].value;
		else
			dt[0] = val[0].value;
		if(""+val[1].tagName=="SELECT")
			dt[1] = val[1][val[1].selectedIndex].value;
		else
			dt[1] = val[1].value;
		if(""+val[2].tagName=="SELECT")
			dt[2] = val[2][val[2].selectedIndex].value;
		else
			dt[2] = val[2].value;
	}
	else
		dt = val.value.split('/');

	showCalendar(((""+dt[2]!="" && ""+dt[1]!="" && ""+dt[0]!="")?new Date(dt[2],dt[1]-1,dt[0]):today), xPos, yPos);
}
function check2form(){
	if(document.frm.idgruppoapp.checked==false)
	{
		if(""+document.frm.tipoallegato[0]!="undefined")
		{
			document.frm.tipoallegato[0].selected=true;
			document.frm.tipoallegato.disabled = true;
			document.frm.allegato[0].selected=true;
			document.frm.allegato.disabled = true;		
		}
		else
		{
			document.frm.tipoallegato.disabled = true;
			document.frm.allegato.disabled = true;		
		}
	}
	if(document.frm.idgruppoapp.checked==true)
	{
		//document.frm.tipoallegato[0].selected=false;
		document.frm.tipoallegato.disabled = false;
		document.frm.allegato.disabled = false;		
	}	
}

function checkform()
{
	var ret=true;
	/*if(!(ControlCheck(document.frm.utente) || ControlCheck(document.frm.idgruppoapp)))
	{
		ret=false;
		alert("E' necessario selezionare almeno un utente!");
	}*/
	if(""+document.frm.idgruppoapp!="undefined" && document.frm.idgruppoapp.checked==true)
	{
		if((document.frm.tipoallegato.value=="") || (document.frm.allegato.value=="")){
			ret=false;
			alert("Attenzione!\nDevi selezionare il Tipo comunicazione e la Disponibilità comunicazione");
		}	
	}
	return ret;
}

function Disconnect(ID)
{
	window.open("disconnectvc.asp?ID=" + ID,"Disconnect","width=10,height=10,top=0,left=0");
}

//per FT
function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { 
  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];}}
}

function MM_findObj(n, d) { 
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//

function setVideoMessageOk()
{
	window.frm.messageok.value="1";
}

function isIE() {
	return document.all;
}

function showsummary(object, e, text) {
	myLayer = document.getElementById(object);
	myLayer.innerHTML = text;

	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

    if (e != '') {
        if (isIE()) {
            x = e.clientX;
            y = e.clientY;
            browserX = document.body.offsetWidth - 25;
			x += document.body.scrollLeft;			// Adjust for scrolling on IE
    		y += document.body.scrollTop;
        }
        if (!isIE()) {
            x = e.pageX;
            y = e.pageY;
            browserX = window.innerWidth - 35;
        }
    }

	x1 = x + 20;		// Move out of mouse pointer
	y1 = y + 20;

	// Keep box from going off screen
	if (x1 + w > browserX)
		x1 = browserX - w;

    myLayer.style.left = parseInt(x1)+ "px";
    myLayer.style.top = parseInt(y1) + "px";
	myLayer.style.visibility = "visible";
}

function moveSummary(object, e) {

	myLayer = document.getElementById(object);
	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

    if (e != '') {
        if (isIE()) {
            x = e.clientX;
            y = e.clientY;
			browserX = document.body.offsetWidth -25;
			x += document.body.scrollLeft;
			y += document.body.scrollTop;
        }
        if (!isIE()) {
            x = e.pageX;
            y = e.pageY;
			browserX = window.innerWidth - 30;
        }
    }

	x1 = x + 20;	// Move out of mouse pointer
	y1 = y + 20;

	// Keep box from going off screen
	if (x1 + w > browserX)
		x1 = browserX - w;

    myLayer.style.left = parseInt(x1) + "px";
    myLayer.style.top = parseInt(y1) + "px";
}

function hideSummary(object) {
	myLayer = document.getElementById(object);
	myLayer.style.visibility = 'hidden';
}

function PopUp2(win)
{
	var w=600;
	var h=400;
	var scroll=1;
	var page="_blank";
	if(PopUp2.arguments.length>1)
		w=PopUp2.arguments[1];
	if(PopUp2.arguments.length>2)
		h=PopUp2.arguments[2];
	if(PopUp2.arguments.length>3)
		page=PopUp2.arguments[3];
	if(PopUp2.arguments.length>4)
		scroll=PopUp2.arguments[4];
	var l=(window.screen.width/2)-(w/2);
	var t=(window.screen.height/2)-(h/2);
	window.open(win,page,"width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ",scrollbars=" + scroll);
}