//cerca classi
function getElementsByClassName(classname){
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = document.all?document.all:document.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}
//for form

function createnode(arc){
	newimg=document.createElement('span');
	newimg.className="controllo-form";
	newimg.innerHTML='<em>Campo Necessario</em>';
	arc.appendChild(newimg);	
}
function controllo(gg){
	err=0;
	chan=getElementsByClassName("obbligatorio");
	for(z=1;z<=chan.length;z++){
		node=chan[z-1];
		node.className="";
	}
  	reqfields=document.getElementById('required').value.split(',');
	for(i=0;i<reqfields.length;i++){
		f=document.getElementById(reqfields[i]);
		if(f.value==""){
			f.className="obbligatorio";
			err++;
		}
	}
	if(err>0){
		location.href="#"+gg.getAttribute('id');
		return false;	
	}
}
function associa(){
	var els = document.all?document.all:document.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++){
		asc=els[i];
		//alert(asc.TagName);
		if(asc.getAttribute('class')=="cform"){
			asc.onsubmit= function () {return controllo(this);}	
		}
	}
}
//end for form
