function AlertMustRegister() {
    alert("To proceed you must be registered.\n\nRegistered users login.");
  return false;
}

function roundTo(value, decimalpositions) {
    var i = value * Math.pow(10, decimalpositions);
    i = Math.round(i);
    return i / Math.pow(10, decimalpositions);
} 

function MyParseOff(value) {

    value = value.replace(",", ".");

    if (!isNaN(value)) {
        if (value.indexOf(".") == -1) {
            value = roundTo(parseInt(value, 10) / 100, 2);
            
        }
        else {
            value = parseFloat(value);
            value = roundTo(value, 2);
        }
    }
    
    else {
        value = 0;
    }
    
    return value;
}

function MyFormatNumber(value) {

    var StrValue = new String(value);
    
    if (StrValue.indexOf(".") == -1) {
        StrValue = StrValue + ".00";
    }

    return StrValue;
}

function AlertOffertaS(idField, costoOfferta, offGratis)
{ 
  Offerta = MyParseOff(document.getElementById(idField).value);
  
  if (offGratis == 0) {
      LbCostoOfferta = "The cost of the information package is $costoofferta$ credits.";  // "Il costo del pacchetto informazioni sarà di $costoofferta$ crediti.";
      LbCostoOfferta = LbCostoOfferta.replace("$costoofferta$", costoOfferta);
  }

  else {
      LbCostoOfferta = "FREE information package.";  // "Pacchetto informazioni GRATUITO!";
  }
  
  LbCostoOfferta 
  if (Offerta > 0) {
      Offerta = MyFormatNumber(Offerta);
      document.getElementById(idField).value = Offerta;

      tmpStr = "You want to bid $offerta$ € for the selected auction ?";  // "Vuoi offrire $offerta$ € per l'asta selezionata ?";
      tmpStr = tmpStr.replace("$offerta$", Offerta);
      
      return confirm(tmpStr + "\n\n" + LbCostoOfferta);
   }
   else
   {
       alert("Insert a number above zero,\nexpressed in euro cents."); 
       // ("Inserire un numero corretto, maggiore di zero,\nespresso in centesimi di euro.");
   }
  
  return false;
}

function AlertOffertaM(idFieldDa, idFieldA, costoOfferta, offGratis) { 
  OffertaDa = MyParseOff(document.getElementById(idFieldDa).value);
  OffertaA = MyParseOff(document.getElementById(idFieldA).value);

  if (OffertaDa > 0 && OffertaA > 0)
   { if (OffertaDa >= OffertaA) {

       OffertaDa = MyFormatNumber(OffertaDa);
       OffertaA = MyFormatNumber(OffertaA);
       document.getElementById(idFieldDa).value = OffertaDa;
       document.getElementById(idFieldA).value = OffertaA;

       tmpStr = "The first value in the bid range($offertada$) must be lower than the second ($offertaa$)";  // "Il primo valore del range dell'offerta ($offertada$) deve essere minore del secondo valore ($offertaa$)";
       tmpStr = tmpStr.replace("$offertada$", OffertaDa)
       tmpStr = tmpStr.replace("$offertaa$", OffertaA)
       alert(tmpStr);
       
       return false;
   }

   NumOff = (Math.round(OffertaA * 100)) - (Math.round(OffertaDa * 100)) + 1;
   NumOff = parseInt(NumOff);

   // alert(OffertaA * 100 + " - " + OffertaDa * 100 + " - " + NumOff);

   if (offGratis > NumOff) { offGratis = NumOff; }
   
   OffertaDa = MyFormatNumber(OffertaDa);
   OffertaA = MyFormatNumber(OffertaA);
   document.getElementById(idFieldDa).value = OffertaDa;
   document.getElementById(idFieldA).value = OffertaA;

   LbCostoOfferta = "1 credit";
   if (costoOfferta > 1) { LbCostoOfferta = costoOfferta + " credits"; }
   TotCrediti = (NumOff - offGratis) * costoOfferta;

   Msg = "You want to bid from $offertada$ € to $offertaa$ € for the selected auction ?\n\n";  // "Vuoi offrire da " + OffertaDa + " € a " + OffertaA + " € per l'asta selezionata ?\n\n"
   Msg = Msg.replace("$offertada$", OffertaDa)
   Msg = Msg.replace("$offertaa$", OffertaA)

   Msg += "Bid number: " + NumOff + "\n"; // "Numero di offerte: "

   if (offGratis > 0) {
       Msg += "Gift bid: " + offGratis + "\n\n";

       if (TotCrediti > 0) {
           Msg += "Bid debited: " + (NumOff - offGratis) + "\n";
           Msg += "Single package cost: " + LbCostoOfferta + "\n";
           Msg += "Total cost: " + TotCrediti + " crediti.";
       }
       else {
           Msg += "FREE information package."; // "Pacchetto informazioni GRATUITO!"
       }
   }
   else {
       Msg += "Single package cost: " + LbCostoOfferta + "\n";
       Msg += "Total cost: " + TotCrediti + " credits.";
   }
   
   
   return confirm(Msg);
}

else {
    alert("Insert numbers above zero,\nexpressed in euro cents.");  // "Inserire numeri corretti, maggiori di zero,<br>espressi in centesimi di euro."
}

return false;
}
  

/* ------------------------------------------------------------------------------ */

function VisDetOfferte(ele) {
    document.getElementById('det' + ele).style.display = 'block';
    document.getElementById('butOpenDet' + ele).style.display = 'none';
    document.getElementById('butCloseDet' + ele).style.display = 'block';
}
  
function UnVisDetOfferte (ele) {
    document.getElementById('det' + ele).style.display = 'none';
    document.getElementById('butOpenDet' + ele).style.display = 'block';
    document.getElementById('butCloseDet' + ele).style.display = 'none';
}
   


/**
 * Simple encryption to hide email addresses from crawlers in webpages.
 * This code is Free Software provided under an MIT License.
 * Written by Diego Doval: bnaeQ0bvPXOnZQYgaZqp1ZQO
 * http://www.dynamicobjects.com/d2r/
 */

var key = "BAD4@.56CEGFHIJKLVWdfTUhijXYZbacemngMNOPQRSopqrstuvz018923klwxy7";
var base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@.0123456789";

function generateMailLink(encoded, linkText)
{
  if (linkText == "")
    {linkText = decode(encoded); }
  document.write("<a hr"+"ef=\"ma"+"ilto"+":"+decode(encoded)+"\">"+linkText+"</"+"a>");
}

function decode(str)
{ return codec(key, base, str);
}

function codec(from, to, str)
{ var codedResult = "";
  for (i = 0; i < str.length; i++) {
    current = str.charAt(i);
    idx = from.indexOf(current);
    nextVal = (idx == -1) ? current : to.charAt(idx);
    codedResult += nextVal;
  }
  return codedResult;
}

// -------------------------------------- Xml Req 4 Logintime
function TimerOnPage() {
    updateTimerOP();
    timerOnPageID = setInterval('updateTimerOP()', 300000); // 5 minuti
}

var req;
function updateTimerOP() {
    var url = "/Ascx/LoginTime.aspx";
    req = false;

    // chiamata per XMLHttpRequest native object
    if (window.XMLHttpRequest) {
        try { req = new XMLHttpRequest(); }
        catch (e) { req = false; }
    }
    // chiamata per versione IE/Windows ActiveX 
    else
        if (window.ActiveXObject) {
        try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) { req = false; }
        }
    }

    if (req) {
        req.onreadystatechange = processResponseTimerOP;
        req.open("GET", url, true);
        req.send("");
    }
}

function processResponseTimerOP() {   // only if req shows "loaded"
    if (req.readyState == 4) {   // only if "OK"
        if (req.status == 200) {
            if (req.responseText == "0") {  // document.location.href = "/login.aspx";  
                // Nothing !
            }
            else {
                if (document.getElementById("TempoTrascorso") != null)
                { document.getElementById("TempoTrascorso").innerHTML = "&nbsp;Time on line: " + req.responseText; }
                else { // alert (req.responseText); 
                }
            }
        }
    }

}

