function validEmail (t)
{
  if (t.value == "")
  {
    //alert("Occorre riempire il campo EMAIL")
    return false;
    t.focus ();
    t.select();
  }
  else if (t.value.indexOf('@', 0)== -1 || t.value.indexOf('.', 0)== -1)
  {
    //alert("L'indirizzo EMAIL non è valido");
    return false;
    t.focus ();
    t.select();
  }
  return true;
}

function submitenter(myfield,e)
{
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
}

function getCheckedValue(radioObj) 
{
  if(!radioObj) return "";
  var radioLength = radioObj.length;
  if(radioLength == undefined)
    if(radioObj.checked)
      return radioObj.value;
    else
      return "";
  for(var i = 0; i < radioLength; i++) {
    if(radioObj[i].checked) {
      return radioObj[i].value;
    }
  }
  return "";
}

function autofitIframe (id)
{
  if (parent.window.frames[id]!=null && parent.window.frames[id].document.body!=null)
  {
    if (!window.opera && !document.mimeType && document.all && document.getElementById)
      parent.document.getElementById(id).style.height = parent.window.frames[id].document.body.offsetHeight + "px";
    else if(document.getElementById)
      parent.document.getElementById(id).style.height=parent.window.frames[id].document.body.scrollHeight + "px";
  }
}

function offri1(idAsta, offerta1, offerta2, offerta3, offerta4, offerta5)
{
  if (idAsta!=null && (offerta1!=null || offerta2!=null || offerta3!=null || offerta4!=null || offerta5!=null))
  {
    var t = 'idAsta=' + idAsta; // + '&offerta1=' + offerta1 + '&offerta2=' + offerta2 + '&offerta3=' + offerta3 + '&offerta4=' + offerta4 + '&offerta5=' + offerta5 + '&'; 
    for (var i = 1; i<=5; i++)
      if (eval('offerta' + i)!='') t = t + '&offerta' + i +'=' + eval('offerta' + i)
    t = t + '&';
    //alert (t);
    caricaValore('actions.jsp?action=offri1&' + t);
  }
}

function offriSfida (idSfida, offerta1, offerta2, offerta3, offerta4, offerta5)
{
  if (idSfida!=null && (offerta1!=null || offerta2!=null || offerta3!=null || offerta4!=null || offerta5!=null))
  {
    var t = 'idSfida=' + idSfida; 
    for (var i = 1; i<=5; i++)
      if (eval('offerta' + i)!='') t = t + '&offerta' + i +'=' + eval('offerta' + i)
    t = t + '&';
    //alert (t);
    caricaValore('actionssfide.jsp?action=offriSfida&' + t);
  }
}

function offri2(idAsta, da, a)
{
  if (idAsta!=null && da!=null && a!=null)
  {
    var t = 'idAsta=' + idAsta + '&da=' + da + '&a=' + a + '&'; 
    caricaValore('actions.jsp?action=offri2&' + t);
  }
}

function IsNumeric(sText)
{
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;

  for (i = 0; i < sText.length && IsNumber == true; i++) 
  { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) IsNumber = false;
  }
  return IsNumber;
}


function formatta(num,dec) { 
    dec= (dec)?dec:2; // default: due decimali 
    ee = Math.pow(10,dec); 
    nn = Math.floor(num*ee); 
    vv = ""; // default per 0 
    if(nn>0) { 
        vv = String(nn/ee); 
        vv = String (Math.round((parseFloat(num)*ee))/ee); 
        vv += (vv.indexOf(".")>=0)?"":"."; 
        while (vv.indexOf(".")>vv.length-dec-1) { vv += "0" } 
    }
    
    return vv; 
} 

function pop (src, w, h) 
{
  if (w==null) w=300;
  if (h==null) h=400;
  $('mainDiv').style.display = 'block';
  $('mainDiv').style.height = document.body.scrollHeight;
  $('popup').style.display = 'block';
  $('popup').style.width = w;
  $('popup').style.height = h;
  $('popup').style.position = 'absolute';
  $('popup').style.top = 90;
  $('popup').style.background = '#fff';
  $('popup').style.left = (document.body.offsetWidth - w -20)/2;
  $('popup').style.visibility = 'visible';  
  $('popupframe').src = src;
  
  $('chiudipopup').style.visibility = 'visible';  
  $('chiudipopup').style.display = 'block';
  $('chiudipopup').style.left = parseInt ($('popup').style.left) + parseInt ($('popup').style.width) - parseInt($('chiudipopup').style.width);
  $('chiudipopup').style.top = parseInt($('popup').style.top) - parseInt($('chiudipopup').style.height);
  
  $('popup').style.top = parseInt (document.body.scrollTop) + 53;

  $('chiudipopup').style.top = parseInt (document.body.scrollTop) + 33;
}

function wait () 
{
  if ($('mainDiv')!=null)
  {
    $('mainDiv').style.display = 'block';
    $('mainDiv').style.height = document.body.scrollHeight;
    $('wait').style.width = 50;
    $('wait').style.height = 50;
    $('wait').style.position = 'absolute';
    $('wait').style.top = 200;
    $('wait').style.border = 'none';
    //$('wait').style.background = 'url("immagini/busy3.gif")';
    $('wait').style.visibility = 'visible';
    $('wait').style.left = (document.body.offsetWidth - parseInt($('wait').style.width) -20)/2;
    $('wait').style.top = (document.body.offsetHeight - parseInt($('wait').style.height) -20)/2;

    $('wait').style.top = parseInt (document.body.scrollTop) + 250;
  }
}

function hide () {
  if ($('mainDiv')!=null)
  {
    $('mainDiv').style.display='none';
    $('popup').style.visibility='hidden';
    $('popup').style.display = 'none';
    $('wait').style.visibility='hidden';
    $('chiudipopup').style.visibility='hidden';
    $('chiudipopup').style.display = 'none';
    $('popup').innerHTML = '<iframe name="popupframe" id="popupframe" scrolling ="no" width="100%" height="100%" frameborder="no"></iframe>';
  }
}

function menu (t)
{
	parent.window.location.href=t;
}


// imposta il cookie sNome = sValore
// per la durata di 10 secondi
function setCookie(sNome, sValore) 
{
  var dtOggi = new Date();
  var dtExpires = new Date();
  dtExpires.setTime (dtOggi.getTime() + 10000);
  document.cookie = sNome + "=" + escape(sValore) +
    "; expires=" + dtExpires.toGMTString();
}

// rimuove un cookie
function delCookie(sNome) 
{
  setCookie(sNome, "");
}

function goto (p)
{
  parent.window.location.href=p;
}

function addBookmark (title, url)
{
  if (document.all)
    window.external.AddFavorite(url, title);
  else if (window.sidebar)
    window.sidebar.addPanel(title, url, "");
}

function getToolTip (t, testo, w, h)
{
  var _d = document.getElementById ('_' + t.name);
  var __d = document.getElementById ('__' + t.name);
  _d.innerHTML = 
    '<table heght="' + h + '" border="0" cellpadding="0" cellspacing="0">' +
      '<tr height="1"><td></td><td colspan="4" bgcolor="#64b34a"></td></tr>' +
      '<tr width="13" height="4"><td valign="top"><img src="immagini/triangolo.png"></td>' + 
        '<td bgcolor="#64b34a"></td>' + 
        '<td bgcolor="#d2dcc4"></td>' + 
        '<td width="200" bgcolor="#d2dcc4" rowspan="2">' + testo + '</td>' + 
        '<td bgcolor="#d2dcc4"></td>' + 
        '<td bgcolor="#64b34a"></td></tr>' +
      '<tr height"400">' +
        '<td></td>' +
        '<td width="8" bgcolor="#64b34a"></td>' +
        '<td width="6" bgcolor="#d2dcc4"></td>' + 
        '<td width="6" bgcolor="#d2dcc4"></td>' + 
        '<td width="1" bgcolor="#64b34a"></td>' +
      '</tr>' +
      '<tr height="4"><td></td><td bgcolor="#64b34a"></td><td colspan="3" bgcolor="#d2dcc4"></td><td bgcolor="#64b34a"></td></tr>' +
      '<tr height="1"><td></td><td colspan="4" bgcolor="#64b34a"></td></tr>' +
    '</table>';
  //alert (_d.style.top);
  //'<table width="100%" height="100%"><tr><td style="font-size:13;" valign="top">' + testo + '</td></tr></table>';
  _d.style.width=w;
  __d.style.width=w;
  _d.style.height=h;
  __d.style.height=h;
}
function clearToolTip (t)
{
  var _d = document.getElementById ('_' + t.name);
  _d.innerHTML = '';
  var __d = document.getElementById ('__' + t.name);
  _d.style.width=0;
  __d.style.width=0;
  _d.style.height=0;
  __d.style.height=0;
}

function hideBanner1()
{
  if ($('bannermegafono'))
    $('bannermegafono').style.visibility='hidden';
}