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 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/windows/maximize.gif';
      setCookie('status_' + aName, 'N', 30);
    } else {
      divobj.style.display = 'block';
      if (imgobj != null) imgobj.src = '/customizing/images/windows/minimize.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 js_AddCartItem(aName, aUrl, aDescription, aQty, aPrice) {
  document.forms['GlobalCartForm'].Article.value = aName;
  document.forms['GlobalCartForm'].ArticleUrl.value = aUrl;
  document.forms['GlobalCartForm'].Description.value = aDescription;
  document.forms['GlobalCartForm'].Quantity.value = aQty;
  document.forms['GlobalCartForm'].SinglePrice.value = aPrice;
  document.forms['GlobalCartForm'].submit();
}

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 Ajax_AddCartItem(aName, aUrl, aDescription, aQty, aPrice, aUserName) {
  if (confirm("Aggiungere codice al carrello? - Add selected code to cart?")) {
    var poststr = 'article=' + encodeURI(aName) +
                  '&ArticleURL=' + escape(encodeURI(aUrl)) +
                  '&Description=' + encodeURI(aDescription) +
                  '&Quantity=' + encodeURI(aQty) +
                  '&SinglePrice=' + encodeURI(aPrice) +
                  '&UserName=' + encodeURI(aUserName);
    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 checkform_Contacts_form (form) {
        if (form.instnome.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.instnome.focus();
		return false;
	}
          if (form.instcode.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.instcode.focus();
		return false;
	}  
	          if (form.instindirizzo.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.instindirizzo.focus();
		return false;
	}          if (form.insttel.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.insttel.focus();
		return false;
	}          if (form.instfax.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.instfax.focus();
		return false;
	}          if (form.instcap.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.instcap.focus();
		return false;
	}          if (form.instcitta.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.instcitta.focus();
		return false;
	}          if (form.instnazione.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.instnazione.focus();
		return false;
	}          if (form.instemail.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.instemail.focus();
		return false;
	}          if (form.codice.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.codice.focus();
		return false;
	}          if (form.serie.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.serie.focus();
		return false;
	}          if (form.modello.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.modello.focus();
		return false;
	}          if (form.data.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.data.focus();
		return false;
	}          if (form.fattura.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.fattura.focus();
		return false;
	}          if (form.cliente.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.cliente.focus();
		return false;
	}          if (form.clientenome.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.clientenome.focus();
		return false;
	}          if (form.clienteind.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.clienteind.focus();
		return false;
	}          if (form.clientecap.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.clientecap.focus();
		return false;
	}          if (form.clientecitta.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.clientecitta.focus();
		return false;
    }          if (form.clientenazione.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.clientenazione.focus();
		return false;
	}          if (form.clientetel.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.clientetel.focus();
		return false;
    }          if (form.clientefax.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.clientefax.focus();
		return false;
	}          if (form.clientemail.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.clientemail.focus();
        return false;
    }          if (form.serie.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.serie.focus();
		return false;
	}          if (form.serie.value == "") {
		alert( "Riempire i campi obbligatori - Fill the mandatory fields" );
		form.serie.focus();
		return false;
	}
if (!(form.privacy.checked)) {
      alert( "Attenzione! è necessario prestare il consenso al trattamento dei miei dati personali per procedere alla registrazione - You need to accept what stated at point (i) to successfully register" );
	   form.privacy.focus();
      return false;
        }
}

