function FindObject( oName, oFrame, oDoc ) {
  if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
  if( oDoc[oName] ) { return oDoc[oName]; } if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
  if( oDoc.getElementById && oDoc.getElementById(oName) ) { return oDoc.getElementById(oName); }
  for( var x = 0; x < oDoc.forms.length; x++ ) { if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
  for( var x = 0; x < oDoc.anchors.length; x++ ) { if( oDoc.anchors[x].name == oName ) { return oDoc.anchors[x]; } }
  for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
    var theOb = MWJ_findObj( oName, null, oDoc.layers[x].document ); if( theOb ) { return theOb; } }
  if( !oFrame && window[oName] ) { return window[oName]; } if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
  for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
    var theOb = MWJ_findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
  return null;
}

function setCookie(name, value, expires, path, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function SetElementVisibility(aName, aStatus) {
  var obj = FindObject(aName);
  if (obj) {
    if (aStatus) {
//      obj.style.display = 'block';
      obj.style.display = '';
    } else {
      obj.style.display = 'none';
    }
  }
}

function ToggleDiv(aName) {
  divobj = FindObject('div_' + aName);
  imgobj = FindObject('img_' + aName);
  if (divobj != null) {
    if (divobj.style.display != 'none') {
      divobj.style.display = 'none';
      if (imgobj != null) imgobj.src = '/customizing/images/ec/varie/plus.gif';
      setCookie('status_' + aName, 'N', 30);
    } else {
      divobj.style.display = 'block';
      if (imgobj != null) imgobj.src = '/customizing/images/ec/varie/minus.gif';
      setCookie('status_' + aName, 'Y', 30);
    }
  }
}

function saveAbsolutePagePosition(aName) {
  var db = (document.body) ? 1 : 0;
  var scroll = (window.scrollTo) ? 1 : 0;
  if (scroll) {
    var x = (db) ? document.body.scrollLeft : pageXOffset;
    var y = (db) ? document.body.scrollTop : pageYOffset;
    setCookie('xy_'+aName, x + '_' + y, 0);
  }
}

function loadAbsolutePagePosition(aName) {
  var db = (document.body) ? 1 : 0;
  var scroll = (window.scrollTo) ? 1 : 0;
  if (scroll) {
    var xy = getCookie('xy_'+aName);
    if (xy) {
      var ar = xy.split('_');
      if (ar.length == 2) {
        scrollTo(parseInt(ar[0]), parseInt(ar[1]));
      }
    }
  }
}

function AddTextToField(aField, aContainer, aText) {
  var edt = FindObject(aField, aContainer);
  if (edt) {
    edt.value = edt.value + aText;
  }
}

function ValidEmailAddress(EmailAddr) {
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   	if (Filtro.test(EmailAddr))
      	return true;
   	else {
      	alert('Indirizzo "' + EmailAddr + '" non valido');
      	return false;
    }
}

function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function Trim( value ) {
	return LTrim(RTrim(value));
}

function Ajax_AddCartItem(aName, aQty) {
    var xmlhttp = null;

    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else  {
        if (window.ActiveXObject) {
            xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
        }
    }

    var poststr = 'article=' + encodeURI(aName) + '&Quantity=' + encodeURI(aQty);

    if (xmlhttp != null) {
        xmlhttp.open('POST', '/admin/_artuportal_addcart.asp', true);
        xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        xmlhttp.setRequestHeader('Content-length', poststr.length);
        xmlhttp.setRequestHeader('Connection', 'close');
        xmlhttp.onreadystatechange=function() {
          if (xmlhttp.status != 200) {
              alert("artuportal_addcart.asp status code: " + xmlhttp.status);
          }
          if (xmlhttp.readyState==4) {
            if (xmlhttp.status==200) {
              strRes = xmlhttp.responseText;
//              alert(strRes);
              window.location.replace(strRes);
            }
          }
        }
        xmlhttp.send(poststr);
    }
}

var Ajax_cart_xmlhttp = null;

function Ajax_cart_state_changed() {
  var divobj;
  if (Ajax_cart_xmlhttp != null) {
    if (Ajax_cart_xmlhttp.readyState==4) {
      if (Ajax_cart_xmlhttp.status==200) {
        divobj = FindObject('cart_items_counter_span');
        if (divobj != null) {
          divobj.innerHTML = Ajax_cart_xmlhttp.responseText;
        }
      }
    }
  }
}

function old_Ajax_AddCartItem(aName, aUrl, aDescription, aQty, aPrice, aUserName, aBackUrl) {
    var poststr = 'article=' + encodeURI(aName) +
                  '&ArticleURL=' + escape(encodeURI(aUrl)) +
                  '&Description=' + encodeURI(aDescription) +
                  '&Quantity=' + encodeURI(aQty) +
                  '&SinglePrice=' + encodeURI(aPrice) +
                  '&UserName=' + encodeURI(aUserName) +
                  '&BackUrl=' + encodeURI(aBackUrl);
    if (Ajax_cart_xmlhttp == null) {
        if (window.XMLHttpRequest) {
            Ajax_cart_xmlhttp = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            Ajax_cart_xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
        }
    }
    if (Ajax_cart_xmlhttp != null) {
        Ajax_cart_xmlhttp.open('POST', '/admin/_addcart.asp', true);
        Ajax_cart_xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        Ajax_cart_xmlhttp.setRequestHeader('Content-length', poststr.length);
        Ajax_cart_xmlhttp.setRequestHeader('Connection', 'close');
        Ajax_cart_xmlhttp.onreadystatechange = Ajax_cart_state_changed;
        Ajax_cart_xmlhttp.send(poststr);
    }
}

function ccAjax_ComboQueryDefault(aComboName, aSql, aCommandline, aDefault) {
  var i,
      xmlhttp = null,
      poststr,
      comboobj,
      strRes,
      arrValori,
      opt = null,
      dbgarea = null;

  comboobj = FindObject(aComboName);
  dbgarea = FindObject('mydebug');

  if (comboobj != null) {
    if(comboobj.options) {
      comboobj.options.length = 0;

      if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
      }

      if (xmlhttp != null) {
        poststr = 'sql=' + encodeURI(aSql);
        if (aCommandline != '') {
          poststr = poststr + '&' + encodeURI(aCommandline);
        }
        xmlhttp.open('POST', '/admin/ajaxcombo.asp', true);
        xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        xmlhttp.setRequestHeader('Content-length', poststr.length);
        xmlhttp.setRequestHeader('Connection', 'close');
        xmlhttp.onreadystatechange=function() {
          if (xmlhttp.readyState==4) {
            if (xmlhttp.status==200) {
              strRes = xmlhttp.responseText;
              if (dbgarea != null) {
                dbgarea.value = dbgarea.value + strRes
              }
              arrValori = strRes.split("|");
              if (arrValori.length > 1) {
                for (i=0; i<arrValori.length; i+=2 ) {
                  opt = new Option();
                  opt.value = arrValori[i];
                  opt.text = arrValori[i+1];
                  if ((opt.value == aDefault) && (aDefault != "")) {
                      opt.selected = true;
                  }
                  comboobj.options[comboobj.options.length] = opt;
                }
              }
            }
          }
        }
        xmlhttp.send(poststr);
      }
    }
  }
}

function ccAjax_ComboQuery(aComboName, aSql, aCommandline) {
    ccAjax_ComboQueryDefault(aComboName, aSql, aCommandline, "");
}
function checkform_Contacts_form (form) {
	if (form.nome.value == "") {
		alert( "Inserire il proprio nome" );
		form.nome.focus();
		return false;
	}
    if (form.email.value == "") {
		alert( "Inserire un indirizzo e-mail valido" );
		form.email.focus();
		return false;
	}
}

