function isEmailAddr(s)
{ 
  var result = false;
  var theStr = new String(s);
  var index = theStr.indexOf("@");

  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function ds_all(bool)
{
	//alert ("select");
	var i=0;
	var l=document.forms[0].selection.length;
	if (l!=undefined){
	for (i=0;i<l;i++)
	{
		//alert(document.forms[0].selection[i].checked);
		document.forms[0].selection[i].checked=bool;
	}
	}else{
		document.forms[0].selection.checked=bool;
	}
}

function scan(id,v)
{ 
  i=0;
  obj=document.getElementById(id);
  while ((obj.options.length>i)&&(v!=obj.options[i++].value));
  if (v==obj.options[i-1].value){obj.selectedIndex=i-1}
}


function changeUrl(frame,url,s)
{
if (frame!=""){add=frame+".";}else{add="";}
setTimeout(add+"location.href='"+url+"'",s*1000);
}

function changeAtt(id,att,newstr)
{
	try {
	obj=document.getElementById(id);
	obj.setAttribute(att,newstr);
	}catch(e){}
}

function changeAtt2(fr,id,att,newstr)
{
	eval('obj=top.'+fr+'.document.getElementById(id)');
	obj.setAttribute(att,newstr);
}

function changePhase(newstr)
{
	obj=top.header.document.getElementById('phases');
	obj.setAttribute('src',newstr);
}

function getSelectedValue(id)
{
select=document.getElementById(id);
var v=select.options[select.selectedIndex].value;
return v
}

function getValue(id)
{
obj=document.getElementById(id);
return parseFloat(obj.value);
}

function splitAddress(s)
{
address = s.split('**');
}

function hideObj(id)
{
obj=document.getElementById(id);
iSeeIt=false;
return obj.parentNode.removeChild(obj);
}

function showObj(id_p,obj)
{
obj_p=document.getElementById(id_p);
obj_p.appendChild(obj);
iSeeIt=true;
}

function resetList(id,n)
{
obj=document.getElementById(id);
obj.selectedIndex=n;
}

function isTheOnly(id,n)
{
obj=document.getElementById(id);
if (obj.options.length==3)
{
obj.selectedIndex=2;
return true;
}else{
resetList(id,n);
return false;
}
}

function setDisabled(id,n)
{
obj=document.getElementById(id);
obj.disabled=n;
}

function emptySelect(id_select)
{
obj=document.getElementById(id_select);
while ((obj.hasChildNodes())&&(obj.lastChild.value!='0'))obj.removeChild(obj.lastChild);
}

function addOption(id_select,s,v)
{
obj=document.getElementById(id_select);
newOption=document.createElement('OPTION');
obj.appendChild(newOption);
newOption.value=v;
newOption.innerHTML=s;
}

function noTwice(r)
{
var i;
var k=0; //i scandisce il vettore, k indica l'ultimo diverso
for (i=0;i<r.length;i++)
{
if (r[i]!=r[i+1]){r[++k]=r[i+1]}
}
return k
}

function checkList(id)
{
obj=document.getElementById(id);
return obj.options[obj.selectedIndex].value!="0"
}

function stringToFloat(num,precision)
{
  var a = new Array();
  num=num.toString();
  a=num.split(".");
  if (a.length==2){
    //alert(a[1].length);
    //if (a[1].length>1)
    //{
      dec=a[1].substr(0,precision);
  	  arr=a[1].substr(precision,1);
	  if (arr>=5){dec=parseInt(dec)+1}
	  return a[0] + '.' + dec;
    //}
  }  
  return a[0];
}