function conferma ()
  {
	var agree = confirm ("Confirm operation ?");
	if (agree) { return true; }
	else { return false; }
  }



function popup (page, name, w, h)
  {
	var param = 'resizable=yes,scrollbars=no,width=' + w + ',height=' + h;
	window.open (page, name, param);
  }



function caratteridata (string)
  {
	var Chars = "0123456789/";
	if (!string) { return true; }
	for (var i = 0; i < string.length; i++)
	  {
		if (Chars.indexOf(string.charAt(i)) == -1)
		  { return false; }
	  }
	return true;
  }



function stringapulita (string)
  {
	var Chars = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var Nuova = "";
	for (var i = 0; i < string.length; i++)
	  {
		if (Chars.indexOf(string.charAt(i)) == -1)
		  { Nuova = Nuova; } // non aggiungo il carattere
		  else { Nuova = Nuova + string.charAt(i); }
	  }
	return Nuova;
  }



function datavalida (data)
  {
	// attenzione: la data è sempre nel formato mm/dd/yyyy
	var err = "";
	if (!caratteridata (data)) { err = err + '\nNot numerical characters used'; }
	 else {
			var arr = data.split ('/');
			var m = arr [0];
			var d = arr [1];
			var y = arr [2];
			var lim;

			if (d != '') { d = d - 0; } else { err = err + '\nDay: not numeric'; d = 0; }
			if (m != '') { m = m - 0; } else { err = err + '\nMonth: not numeric'; m = 0; }
			if (y != '') { y = y - 0; } else { err = err + '\nYear: not numeric'; y = 0; }

			if (isNaN (d) || isNaN (m) || isNaN (y)) { err = err + '\nDate: not numeric'; }
			if ((m > 12) || (m < 1)) { err = err + '\nMonth: not known'; }
			if (m == 2)
			  { lim = 28;
				if (y % 4 == 0) { lim = lim + 1; }
			  } else { lim = 31;
					   if ((m == 4) || (m == 6) || (m == 9) || (m == 11)) { lim = lim - 1; }
					 }
			if (d < 1) { err = err + '\nDay: not known'; }
			if (d > lim) { err = err + '\nDay: not known'; }

			if (y < 100) { y = 2000 + y; }
		  }

	if (err == "") { return true; } else { return false; }
  }

// metodo generico per cercare un elemento in un array - Javascript
Array.prototype.exists = function (o) {
	for (var i = 0; i < this.length; i++)
	  if (this [i] === o)
		return true; // trovato, esco
	  return false; // non trovato, esco alla fine dell'array
	}






function CheckAutent ()
  {
	var msg = "";
	if (document.autent.login.value == "") { msg = msg + "\n - Login: empty"; }
	if (document.autent.pwd.value == "") { msg = msg + "\n - Password: empty"; }
	if (msg == "")
	  { return true; }
	  else { alert ("There are some errors:\n" + msg + "\n\nPlease correct the listed errors before submit information again"); return false; }
  }



function CheckRemPass ()
  {
	var msg = "";
	if (document.rempas.email.value == "") { msg = msg + "\n - Email: empty"; }
	if (msg == "")
	  { return true; }
	  else { alert ("There are some errors:\n" + msg + "\n\nPlease correct the listed errors before submit information again"); return false; }
  }



function CheckNewPass ()
  {
	var msg = "";
	if (document.newpas.login.value == "") { msg = msg + "\n - Login: empty"; }
	if (document.newpas.pwd.value == "") { msg = msg + "\n - Password: empty"; }
	if (msg == "")
	  { return true; }
	  else { alert ("There are some errors:\n" + msg + "\n\nPlease correct the listed errors before submit information again"); return false; }
  }



function CheckContactUs ()
  {
	var msg = "";
	if (document.FormContactUs.company.value == "") { msg = msg + "\n - Company name: empty"; }
	if (document.FormContactUs.name.value == "") { msg = msg + "\n - Your name: empty"; }
	if (document.FormContactUs.email.value == "") { msg = msg + "\n - Email: empty"; }
			else if (!(document.FormContactUs.email.value.indexOf(".") > 0 && document.FormContactUs.email.value.indexOf("@") > 0))
					{ msg = msg + "\n - Email: not correct"; }
	if (msg == "")
	  { return true; }
	  else { alert ("There are some errors:\n" + msg + "\n\nPlease correct the listed errors before submit information again"); return false; }
  }
