function validate(frm) {
	return validateEmptyField(frm) && validateFormClient(frm)
}
function validateEmptyField(frm) {
	var nElem = frm.elements.length;		
	for(i=0;i<nElem;i++) {
		if (frm.elements[i].type != 'hidden' && 
				frm.elements[i].value.length == 0 && 
				!frm.elements[i].disabled && 
				frm.elements[i].id.indexOf('formatblock_') < 0 &&
				frm.elements[i].id.indexOf('fontname_') < 0 && 
				frm.elements[i].id.indexOf('fontsize_') < 0) {
			alert('Compilare tutti i campi della form');
			frm.elements[i].focus();
			return false;
		}
	}
	return true;
}

function validateFormClient(frm) {
	var errors = validateChar(frm.telefono,"0123456789/ ");
	if (frm.provincia.selectedIndex == 0) {
		if (errors != '')
				errors += '\n\n';
		errors +="Selezionare la provincia di residenza";
	}
	if (frm.email.value.indexOf('@') < 0) {
		if (errors != '')
				errors += '\n\n';
		errors +="Indirizzo E-Mail non valido";
	}

	if (errors != '') {
		alert(errors);
		return false;
	}
	else
		frm.submit();
}

function validateChar(obj,validi) {
	var str = obj.value;
	for( i = 0; i < str.length; i++ ) {
		if( validi.indexOf( str.charAt(i) ) == -1 ) {
			return obj.name + " contiene un carattere non valido `" +
				str.charAt(i) + "'.\nI caratteri validi sono " + validi +"\n";
		}
		else
			return "";
	}
	return "";
}

function loadCombo() {

}

function PopUp(url, width, height)
{
   //alert(url);
	if (width == '') {	
		width=400;//300;
	}
	if (height == '') {
		height=450;//250;
	}
	
	var chasm = screen.availWidth;
	var mount = screen.availHeight;
	var w = width;
	var h = height;
//putItThere = window.open(url,,'width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5));


	return window.open(url,"",'dependent=yes,width='+width+',height='+height+',menubar=no,scrollbars=no,titlebar=no,status=no,left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5));
	
   	//return window.showModalDialog(url,"",'dialogHeight:'+height+'px;dialogWidth:'+width+'px;status:no;center:yes;resizable:no;help:no;scroll:no');
}

function ordina(campo,verso) {
	document.forms[0].campo_ordinamento.value = campo;
	document.forms[0].verso.value = verso;
	document.forms[0].submit();
}