if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', cmxform, false );

function cmxform(){
  // Hide forms
  $( 'form.cmxform' ).hide().end();
  
  // Processing
  $( 'form.cmxform' ).find( 'li/label' ).not( '.nocmx' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = null;
    this.appendChild( labelSpan );
  } ).end();
  
  // Show forms
  $( 'form.cmxform' ).show().end();
}



//function to check empty fields

function isEmpty(strfield1, strfield2, strfield3, strfield4, strfield5, strfield6) {

strfield1 = document.forms[0].nome.value 
strfield2 = document.forms[0].cognome.value
strfield3 = document.forms[0].indirizzo.value
strfield4 = document.forms[0].citta.value
strfield5 = document.forms[0].provincia.value
strfield6 = document.forms[0].cap.value

    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
    {
    alert("Perfavore inserire un nome!")
	document.forms.catalogo.nome.focus();
    return false;
    }

    if (strfield2 == "" || strfield2 == null || !isNaN(strfield2) || strfield2.charAt(0) == ' ')
    {
    alert("Perfavore inserite un cognome!")
	document.forms.catalogo.cognome.focus();
    return false;
    }
    
	if (strfield3 == "" || strfield3 == null || !isNaN(strfield3) || strfield3.charAt(0) == ' ')
    	{
    alert("Perfavore inserire un indirizzo!")
	document.forms.catalogo.indirizzo.focus();	
    return false;
    }
	
    if (strfield4 == "" || strfield4 == null || !isNaN(strfield4) || strfield4.charAt(0) == ' ')
    {
    alert("Perfavore insirire una citta'!")
	document.forms.catalogo.citta.focus();
    return false;
    }
	
	if (strfield5 == "" || strfield5 == null || !isNaN(strfield5) || strfield5.charAt(0) == ' ')
    {
    alert("Perfavore insirire una provincia!")
	document.forms.catalogo.provincia.focus();
    return false;    }
		
	
	if (strfield6 == "" || strfield6 == null || strfield6.charAt(0) == ' ')
    {
    alert("Perfavore inserire il CAP!")
	document.forms.catalogo.cap.focus();
    return false;
    }
	
	
	return true;
}


//function that performs all functions, defined in the onsubmit event handler

function check(form){
if (isEmpty(form.nome)){
  if (isEmpty(form.cognome)){
   	 if (isEmpty(form.indirizzo)){
	   	 if (isEmpty(form.citta)){	
		 	 if (isEmpty(form.provincia)){	
	 		 	 if (isEmpty(form.cap)){	
		  return true;
				 }
			}
		 }
	 }
   }
}
return false;
}