// ---------------------------------- STAZIONE EDITORIALE E ARTICOLI ---------------------------------------------

  function openWin(url, name, scrollbar, w, h) {
    popupWin = window.open(url, name, 'resizable=1,scrollbars=' + scrollbar + ',width=' + w + ',height=' + h + '');
    // focus window (only for Navigator >= 3.0)
    if ( (navigator.appName != "Microsoft Internet Explorer") && (navigator.appVersion.substring(0,1) == "3") )
    popupWin.focus();
  }

  // Aggiunge la pagina ai preferiti
  function addbookmark(pagina,titolo){
    window.external.AddFavorite(pagina,titolo);
  }

  // Fa del sito la home page di default
  function principale(modulo) {
    if (isIE4){
      modulo.style.behavior='url(#default#homepage)';
      modulo.setHomePage("http://www.donnamoderna.com/");
    }
  }

  // stampa...
  function stampa() {
    self.print();
  }

  // per photogallery
  function doLoadSecNextPage(s, max) {
   // the timeout value should be the same as in the "refresh" meta-tag
   // max is the number of pages
    var tempo;
    tempo = 1000 * s;
    //setTimeout("refresh(" + max + ")", tempo);
    setTimeout("refreshNextPage(" + max + ")", tempo);

  }

  // refresh automatico per gallery
  function refreshNextPage(max) {
     var count = 0;
                                          var base = "";
                                          var temp = window.location.href;
                                          var u = temp.slice(-6,-5);
                                          var a = temp.slice(-5,-4);
                                          var d = temp.slice(-7,-6);
                                          var f = temp.slice(-2,-1);
                                          if (u != '_') {
                                                  if (d != '_')  //sono alla prima pagina
                                                  {
                                                  if (f != 'i') {
                                                  count = 2;
                                                  base = temp.slice(0,-4) + '_' + count;
                                                  }
                                  else {
                                                  count = 2;
                                  base = temp.slice(0,-16) + '_' + count;
                                                  }
                                                  }
                                                  else  {
                                                          // sono a pagina 11
                                                  u = temp.slice(-7,-6);
                                                  a = temp.slice(-6,-4)
                                                  count = (Number(a) + 1);
                                                  if (max >= count) {
                                                  base = temp.slice(0,-7) + '_' + count;
                                                  }
                                                  else {
                                                  base = temp.slice(0,-7)
                                                  }
                                                          }
                                          }
                                                  else  {
                                                  count = temp.slice(-6,-4);
                                                  count = (Number(a) + 1);
                                                  if (max >= count) {
                                                  base = temp.slice(0,-6) + '_' + count;
                                                  }
                                                  else {
                                                  base = temp.slice(0,-6)
                                                  }
                                                  }
                                          window.location.href = base + '.art';
  }

  function chiudi(){

      window.close() ;

  }

  // Javascript per la verifica di form //
  function verifica(form) {
    if (form.globale.value == "") {
      alert("scrivi una marca o un modello");
      return false;
    }
  }



  // Javascript per ora internet //
  function orainternet(BrowserTime) {
    var thisT;
    var thisM;
    var thisS;
    var iT;
    thisT = BrowserTime.getHours();
    thisM = BrowserTime.getMinutes();
    thisS = BrowserTime.getSeconds();
    iT = (thisT*3600 + thisM*60 +thisS)*10/864;
    return iT;
  }

  //---------------------------------------SONDAGGI----------------------------------------------------------------
  function vota() {
    var risp='risp_'+document.sondaggio.domanda.value;
    var id='';
    var nr=document.sondaggio.numrisp.value;
    for(var i=0; i<nr; i++){
      if(document.sondaggio.risp_1[i].checked){
        id= risp+'='+document.sondaggio.risp_1[i].value + '&';
      }
    }
    openWin('/sondaggi/43?'+ id +'idCategoria='+ document.sondaggio.idCategoria.value +'&idServizio='+ document.sondaggio.idServizio.value +'&idScheda='+ document.sondaggio.idScheda.value,'','yes',720,580);
  }

  function votaspalla() {
    var risp='risp_'+document.sondaggiospalla.domanda.value;
    var id='';
    var nr=document.sondaggiospalla.numrisp.value;
    for(var i=0; i<nr; i++){
            if(document.sondaggiospalla.risp_1[i].checked){
               id= risp+'='+document.sondaggiospalla.risp_1[i].value + '&';
            }
    }
    openWin('/sondaggi/43?'+ id +'idCategoria='+ document.sondaggiospalla.idCategoria.value +'&idServizio='+ document.sondaggiospalla.idServizio.value +'&idScheda='+ document.sondaggiospalla.idScheda.value,'','yes',800,620);
  }


  //--------------------------------- ricette-----------------------------------------------
  function popUpStampa(pPage) {
    var winOpts = 'resizable=no,scrollbars=yes,width=618,height=460'; popUpWinStampa = window.open(pPage,'popStampa',winOpts);
  }

  function popUpOggettoRicetta(pPage) {
    var winOpts = 'resizable=no,scrollbars=yes,width=440,height=490'; popUpWinStampa = window.open(pPage,'popStampa',winOpts);
  }

  function popUpImmaginiRicetta(pPage) {
    var winOpts = 'resizable=no,scrollbars=yes,width=625,height=625'; popUpWinStampa = window.open(pPage,'popStampa',winOpts);
  }

  function printit(){
      window.print() ;
  }

  function elencoPiatti() {
    document.ricerca_ricette.action="/app/ricette/Ricette/inizializzaRicerca";
    document.ricerca_ricette.submit();
    return true;
  }

  function elencoRegioni() {
    document.ricerca_ricette.action="/app/ricette/Ricette/inizializzaRicerca";
    document.ricerca_ricette.submit();
  }


  //--------------------------------- cartoline -----------------------------------------------
  function vaiFronte() {
    document.cartolina.action="/cartoline/fronte";
    document.cartolina.submit();
  }

  function vaiRetro() {
    document.cartolina.action="/cartoline/retro";
    document.cartolina.submit();
  }

  function apriAnteprima(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
  }

  function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
      field.value = field.value.substring(0, maxlimit);
  }

  function MM_findObj(n, d) { //v4.0
    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_validateForm() { //v4.0
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) {
      test=args[i+2]; val=MM_findObj(args[i]);
      if (val) {
        nm=val.name;
        if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) {
            p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' non è un email valido.\n';
          }
          else if (test!='R') {
              if (isNaN(val)) errors+='- '+nm+' deve contenere un numero.\n';
              if (test.indexOf('inRange') != -1){
                p=test.indexOf(':');
                min=test.substring(8,p); max=test.substring(p+1);
                if (val<min || max<val) errors+='- '+nm+' deve contenere un numero compreso nei valori da '+min+' fino a '+max+'.\n';
              }
          }
        }
        else if (test.charAt(0) == 'R') errors += '- '+nm+' è un campo obbligatorio.\n';
      }
    }
    if (errors) alert('Si sono verificati i seguenti errori:\n'+errors);
    document.MM_returnValue = (errors == '');
  }


  /* bacheca */
  function createRequestObject() {
    var FORM_DATA;
    var separator;
    var query;
    var keypairs;
    var numKP;
    var i;
    var keyName;
    var keyValue;

    FORM_DATA = new Object();
    separator = ',';
    query = '' + this.location;
    query = query.substring((query.indexOf('?')) + 1);
    if (query.length < 1) { return false; }  // Perhaps we got some bad data?

    keypairs = new Object();

    numKP = 1;

    while (query.indexOf('&') > -1) {
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
      keypairs[numKP] = query.substring(0,query.indexOf('&'));
      query = query.substring((query.indexOf('&')) + 1);
      numKP++;
    }

    keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.

    for (i in keypairs) {
      keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
        // Left of '=' is name.
      keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
        // Right of '=' is value.
      while (keyValue.indexOf('+') > -1) {
        keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
      }

      keyValue = unescape(keyValue);
        // Unescape non-alphanumerics

      if (FORM_DATA[keyName]) {
        FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
          // Object already exists, it is probably a multi-select input,
          // and we need to generate a separator-delimited string
          // by appending to what we already have stored.
      }
      else {
        FORM_DATA[keyName] = keyValue;
          // Normal case: name gets value.
      }
    }
    return FORM_DATA;
  }


  function trimString(inString) {
      var outString;
      var startPos;
      var endPos;
      var ch;

      // where do we start?
      startPos = 0;
      ch = inString.charAt(startPos);
      while ((ch == " ") || (ch == "\b") || (ch == "\f") || (ch == "\n") || (ch == "\r") || (ch == "\n")) {
        startPos++;
        ch = inString.charAt(startPos);
      }

      // where do we end?
      endPos = inString.length - 1;
      ch = inString.charAt(endPos);
      while ((ch == " ") || (ch == "\b") || (ch == "\f") || (ch == "\n") || (ch == "\r") || (ch == "\n")) {
        endPos--;
        ch = inString.charAt(endPos);
      }

      // get the string
      outString = inString.substring(startPos, endPos + 1);

      return outString;
  }


  function verifica(moderato) {
    if (trimString(document.invio.titolo.value).length==0) {
      alert("inserire il titolo dell'inserzione");
      return false;
    }
    if (trimString(document.invio.testo.value).length==0) {
      alert("inserire il testo dell'inserzione");
      return false;
    }
    if (trimString(document.invio.testo.value).length>3000) {
      alert("il testo dell'inserzione è troppo lungo(max. 3000 caratteri)");
      return false;
    }
    if (!validateEmail(trimString(document.invio.email.value))) {
      alert("l'email manca o non è corretto");
      return false;
    }
    document.invio.email.value = trimString(document.invio.email.value);
    document.invio.titolo.value = trimString(document.invio.titolo.value);
    document.invio.testo.value = trimString(document.invio.testo.value);
    closeRemote();
    return true;
  }

  function validateEmail(inString) {
    var alfaNum;
    var startPos;
    var ch;
    var ch;
    var up;
    var pp;
    var dom;

    ch = inString.lastIndexOf('@');
    dom = inString.substring(ch+1);
    pp = dom.indexOf('.');
    up = dom.lastIndexOf('.');

    if ((inString.length < 6) || (ch < 1) || (pp < 1) || (up > dom.length - 3) ||(up < dom.length - 7))
      return false;

    startPos = 0;

    alfaNum = "!*|,;:<>()[]{}@&$#%?"; // caratteri vietati nel dominio

    while (startPos < dom.length) {
      ch = dom.charAt(startPos);
      if (alfaNum.indexOf(ch) >= 0) {
        return false;
      }
      startPos++;
    }
    return true;
  }

  function validateField(inString, lung) {
      var s = trimString(inString);

      if (s.length < 1)
        return false;

      if (s.length > lung)
        return false;

      return true;
  }


  function closeRemote() {
    timer = setTimeout('window.close();', 10);
  }


  function verificaModCanc(flag) {
    if (document.invio.pagina.value == "") {
        document.invio.pagina.value="1";
    }

    if (trimString(document.invio.titolo.value).length==0) {
      alert("inserire il titolo dell'inserzione");
      return false;
    }

    if (trimString(document.invio.testo.value).length==0) {
      alert("inserire il testo dell'inserzione");
      return false;
    }

    if (trimString(document.invio.testo.value).length>3000) {
      alert("il testo dell' inserzione è troppo lungo(max. 3000 caratteri)");
      return false;
    }

    if(flag=="C") {
      var ret = confirm("Sicuro di voler cancellare l'inserzione?");
      if (ret==false)
      return false;
    }

    closeRemote();

    return true;
  }


  function verificaModCancAmm(flag) {
    if (trimString(document.invio.nick.value).length==0) {
      alert("inserire nickname");
      return false;
    }

    if (!validateEmail(trimString(document.invio.email.value))) {
      alert("l'email manca o non è corretto");
      return false;
    }

    if (trimString(document.invio.titolo.value).length==0) {
      alert("inserire il titolo dell'inserzione");
      return false;
    }

    if (trimString(document.invio.testo.value).length==0) {
      alert("inserire il testo dell'inserzione");
      return false;
    }

    if (trimString(document.invio.testo.value).length>3000) {
      alert("il testo dell' inserzione è troppo lungo(max. 3000 caratteri)");
      return false;
    }
    document.invio.nick.value = trimString(document.invio.nick.value);
    document.invio.email.value = trimString(document.invio.email.value);
    document.invio.prInter.value = trimString(document.invio.prInter.value);
    document.invio.titolo.value = trimString(document.invio.titolo.value);
    document.invio.testo.value = trimString(document.invio.testo.value);
    document.invio.oper.value = flag;
    document.invio.action = "/bacheca/mcinserzione_am";
    document.invio.submit();
    closeRemote();
  }


  function verificaRispondiInser() {
     if (!validateEmail(trimString(document.invio.email.value))) {
      alert("l'email del mittente manca o non è corretto");
      return false;
    }

    if (trimString(document.invio.testo.value).length==1) {
      alert("inserire il testo del messaggio");
      return false;
    }

    if (trimString(document.invio.testo.value).length>3000) {
      alert("il testo del messaggio è troppo lungo(max. 3000 caratteri)");
      return false;
    }
    document.invio.email.value = trimString(document.invio.email.value);
    document.invio.testo.value = trimString(document.invio.testo.value);
    return true;
  }


  function apriPopup_NomeCognome(position, pagina) {
    var riga= position -(pagina-1)*8 -1;
    var sParams = "";
    if (document.invio.canali.length >1){
      document.invio.canali.value=document.invio.canali[riga].value;
      document.invio.provincia.value=document.invio.provincia[riga].value;
      document.invio.titolo.value=document.invio.titolo[riga].value;
      document.invio.nickname.value=document.invio.nickname[riga].value;
      document.invio.cdForum.value=document.invio.cdForum[riga].value;
      document.invio.cdIntervento.value=document.invio.cdIntervento[riga].value;
      document.invio.ricerca.value=document.invio.ricerca[riga].value;
    }

     sParams += "cdIntervento=" + document.invio.cdIntervento.value;
     sParams += "&cdForum=" + document.invio.cdForum.value;
     sParams += "&cdNickName=" + document.invio.nickname.value;
     sParams += "&canali=" + document.invio.canali.value;
     sParams += "&titolo=" + document.invio.titolo.value;
     sParams += "&provincia=" + document.invio.provincia.value;
     sParams += "&ricerca=" + document.invio.ricerca.value;
     var pPage = '/bacheca/rispondi_inserzione_nome_cognome?' + sParams;
     var winOpts = 'resizable=no,scrollbars=yes,width=500,height=600';
     window.open(pPage,'',winOpts);
  }


  function cancellaInserzione(url) {
    var ret = confirm("Sicuro di voler cancellare l'inserzione?");

    if(ret==true){
      document.invio.action=url;
      document.invio.submit();
    }
  }


  function verificaModifica() {
    if (document.invio.titolo=="") {
      alert("inserire il titolo dell'inserzione");
      return false;
    }

    if (document.invio.testo=="") {
      alert("inserire il testo dell'inserzione");
      return false;
    }

    if (document.invio.testo.length>3000) {
      alert("il testo dell' inserzione è troppo lungo(max. 3000 caratteri)");
      return false;
    }
    closeRemote();
    return true;
  }


  function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
  }


  function getUrlPerLivello(url,livello){
    var pos = 0;
    var i;
    if (url.charAt(0)=='/') url = url.substring(1);
    var sezioni = url.split("/");
    var newurl = "";
    for (i=0; (i <= eval(livello)) && (sezioni[i]!=null) && (sezioni[i]!="index.hp"); i++){
      newurl = newurl + "/" + sezioni[i] ;
    }
    newurl = newurl + "/index.hp";
    return newurl;
  }


  function addLink(name,url,style){
    document.write("<a class=\""+style+"\" href=\""+url+"\">"+name+"</a>");
  }


  //This script detects the following:
  //Flash
  //Windows Media Player
  //Java
  //Shockwave
  //RealPlayer
  //QuickTime
  //Acrobat Reader
  //SVG Viewer
  var agt=navigator.userAgent.toLowerCase();

  var ie  = (agt.indexOf("msie") != -1);

  var ns  = (navigator.appName.indexOf("Netscape") != -1);

  var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));

  var mac = (agt.indexOf("mac")!=-1);


  if (ie && win) {
    pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader");
  }

  if (ns || !win) {
    nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
    pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
  }

  function detectIE(ClassID,name) {
    result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return '';
  }

  function detectNS(ClassID,name) {
    n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n;
  }

  pluginlist += navigator.javaEnabled() ? "Java," : "";
  if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);


  function positionit(){
    //define universal reference to "staticcontent"
    var crossobj=document.all? document.all.staticcontent : document.getElementById("staticcontent")
    //define reference to the body object in IE
    var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
    //define universal dsoc left point
    var dsocleft=document.all? iebody.scrollLeft : pageXOffset
    //define universal dsoc top point
    var dsoctop=document.all? iebody.scrollTop : pageYOffset
    //if the user is using IE 4+ or Firefox/ NS6+
    if (document.all||document.getElementById) {
      crossobj.style.left=783+"px"
      crossobj.style.top=dsoctop+5+"px"
    }
  }
