var submitted = false;
var undefined;
bodyLoadFunctionName= undefined;
bodyUnloadFunctionName= undefined;

function onBodyLoad() {
	if(bodyLoadFunctionName) { 
		eval(bodyLoadFunctionName);
	}
}

function onBodyUnload() {
	if(bodyUnloadFunctionName) { 
		eval(bodyUnloadFunctionName);
	}
}

function controlla() {
	f = document.loginForm;
	if (submitted) {
		return false;
	}
	submitted = true;
	if ((f.username.value.length < 3) || (isEmpty(f.username)) || (!isAlpha(f.username))) {
		submitted = false;
		alert("Inserire uno Username valido.");
		f.username.focus();
		return false;
	}
	return true;
}

function resetta() {
	f = document.loginForm;
	f.reset();
}

function isAlpha(field)
{
  var filter=/^[\w\-\\^\[\]\(\)\.\!\=\*\+\#]*$/;
  return (field.value.match(filter)!=null);
}

function isEmpty(field)
{
  for (var i=0; i < field.value.length; i++)
  {
    if (field.value.substring(i, i+1) != " ") return false;
  }
  return true;
}
function isUsername(field)
{
  return !((isEmpty(field)) || (field.value.length < 3) || (!isAlpha(field)));
}
function isNumber(field)
{
  var filter=/^\d+$/;
  return filter.test(field.value);
}
function isDecimal(field)
{
  var filter=/^\d+\.\d+$/;
  return filter.test(field.value);
}
function isEuro(field)
{
  var filter=/^\d+\.\d{2}$/;
  return filter.test(field.value);
}
function isEmail(field)
{
  var errore=true;
  var filter=/^[A-Za-z][A-Za-z0-9_.\-]*@[A-Za-z0-9_\-]+\.[A-Za-z0-9_.\-]+[A-za-z]$/;
  if (field.value.length == 0 ) return true;
  if (! filter.test(field.value)) errore=false;
  return errore;
}

function popupIMG(imgurl,w,h,x,y)
{
    var cht=window.open("","_blank","width="+w+",height="+h+",resizable=no,scrollbars=no,location=no,menubar=no,status=no,toolbar=no");
    cht.document.open();
    cht.document.writeln("<HTML><HEAD><TITLE>S4Framework</TITLE><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></HEAD><BODY alink=\"Navy\" bottommargin=0 leftmargin=0 marginheight=0 marginwidth=0 rightmargin=0 topmargin=0 vlink=\"#000000\" text=\"#000000\" link=\"#000000\" bgcolor=\"#FFFFFF\"><a href=\"javascript:window.close()\"><img src=\""+imgurl+"\" width=\""+w+"\" height=\""+h+"\" title=\"\" border=\"0\"></a></BODY></HTML>");
    cht.document.close();
    if ((typeof x != "undefined") && (typeof y != "undefined"))
    {
        cht.moveTo(x,y);
    }
    cht.focus();
}

function popupHTML(url,w,h,x,y)
{
    var cht=window.open(url,"_blank","width="+w+",height="+h+",resizable=no,scrollbars=no,location=no,menubar=no,status=no,toolbar=no");
    if ((typeof x != "undefined") && (typeof y != "undefined"))
    {
        cht.moveTo(x,y);
    }
    cht.focus();
}

function openHelp() {
	h = document.getElementById("help");
	h.style.visibility = 'visible';
	h.style.display = 'inline';
	return true;
}
function closeHelp() {
	h = document.getElementById("help");
	h.style.visibility = 'hidden';
	h.style.display = 'none'
	return true;
}

function prevImg(url,w,h)	{
    prev = window.open("","_blank","width="+w+",height="+h+",resizable=no,scrollbars=no,location=no,menubar=no,status=no,toolbar=no");
    prev.document.open();
    prev.document.writeln("<html><head><title>Preview</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body bottommargin=0 leftmargin=0 marginheight=0 marginwidth=0 rightmargin=0 topmargin=0><a href=\"javascript:window.close()\"><img src=\""+url+"\" width=\""+w+"\" height=\""+h+"\" hspace=\"0\" vspace=\"0\" border=\"0\" title=\"\"></a></body></html>");
    prev.document.close();
}

