function loading(divname)
{
	var span = document.getElementById(divname);

	var img = document.createElement('img');
	img.src = 'http://admin.abc.sm/img/load.gif';

	span.appendChild(img);
}

function include_js(file,id) {
	var html_doc = document.getElementsByTagName('head')[0];
	
	if(document.getElementById(id)){
		html_doc.removeChild(document.getElementById(id))
	}
	
	js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('defer','defer');
	js.setAttribute('src', file);
	js.setAttribute('id', id);
	html_doc.appendChild(js);
	if(html_doc){
		return true;
	}else{
		return false;
	}
}

function setquerystring(form) {
   
   var querystring = '';
   var numberElement = form.elements.length;

	for(var i=0; i < numberElement; i++){
		if(i<(numberElement-1)){ 
		   querystring+= form.elements[i].name+"="+encodeURIComponent(form.elements[i].value)+"&";
		}else{
			querystring+= form.elements[i].name+"="+encodeURIComponent(form.elements[i].value);
		}
	}
	
	return querystring;
   
}

function submitFormRichInfo(el)
{
	
	var errors = '';
	if(el.nome.value == '')
	{
		errors += 'Il nome è obbligatorio!\r\n';
	}
	if(el.cognome.value == '')
	{
		errors += 'Il cognome è obbligatorio!\r\n';
	}
	if(el.email.value == '')
	{
		errors += 'Indirizzo Email obbligatorio!\r\n';
	}
	
	if(errors != '')
	{
		errors = 'Attenzione, alcuni campi non sono stati compilati correttamente!\r\n' + errors
		alert(errors);
		return false;
	}
	
	
	loading('loader_send');

	var querystring = setquerystring(el);
	var url = '/wbs.php?'+querystring;

	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	window.document.body.appendChild(jsel);

	return false;
}


