
var W3CDOM = (document.getElementsByTagName && document.createElement && document.getElementById);

function contattiOggetto() {
  if (document.getElementById("fmRad1")) {
    
    function oggettoAttivo() {
      document.getElementById("fmOggetto").disabled = '';
      document.getElementById("fmOggetto").style.backgroundColor = '#F3F3F2';
    }
    function oggettoDisattivo() {
      document.getElementById("fmOggetto").disabled = 'disabled';
      document.getElementById("fmOggetto").style.backgroundColor = '#E5E1D6';
    }
    document.getElementById("fmRad2").onclick = oggettoAttivo;
    document.getElementById("fmRad1").onclick = oggettoDisattivo;
    oggettoDisattivo();
  }
}

function validate() {
	validForm = true;
	firstError = null;
	errorstring = '';
	var x = document.forms[1].elements;
	for (var i=0;i<x.length;i++) {
		if (!x[i].value && x[i].className.indexOf('required') != -1)
			writeError(x[i],'Il campo e\' necessario');
	}
	if (!(x['fmEmail'].value.indexOf('@') > 1) || !(x['fmEmail'].value.indexOf('.') > 2))
		writeError(x['fmEmail'],'Indirizzo email non valido');
  if (x['fmCheck'].checked != true)
    writeError(x['fmCheck'],'Controlla l\'informativa sulla privacy');
	if (!W3CDOM && errorstring != '')
		alert(errorstring);
	if (firstError)
		firstError.focus();
	return validForm;
}

function writeError(obj,message) {
	validForm = false;
	if (obj.hasError) return;
	if (W3CDOM) {
		obj.className += ' error';
		obj.onchange = removeError;
		var sp = document.createElement('div');
		sp.className = 'error';
		sp.appendChild(document.createTextNode(message));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else {
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	if (!firstError)
		firstError = obj;
}

function removeError() {
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}


