function controllo(theForm){

	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
	var flag = true;

	if (theForm.nome_studio.value == ""){
		alert("Inserire il NOME dello STUDIO.");
		theForm.nome_studio.focus();
		return false;
	}
	
	if (theForm.indirizzo.value == ""){
		alert("Inserire l'INDIRIZZO dello STUDIO.");
		theForm.indirizzo.focus();
		return false;
	}
	
	if (theForm.regione.value == 0){
		alert("Seleziona una regione");
		theForm.regione.focus();
		return false;
	}

	if (theForm.provincia.value == 0){
		alert("Seleziona una provincia");
		theForm.provincia.focus();
		return false;
	}

	if (theForm.citta.value == 0){
		alert("Seleziona una cittą");
		theForm.citta.focus();
		return false;
	}

	if (theForm.email.value == ""){
		alert("Inserire l'indirizzo E-MAIL.");
		theForm.email.focus();
		return false;
	}

	if (theForm.email.value.length > 0 ){
		for (i = 0;  i < theForm.email.value.length;  i++){
			ch = theForm.email.value.charAt(i);
			for (j = 0;  j < checkOK.length;  j++){
				if (ch == checkOK.charAt(j)){
					flag = true;
					break;
				}else{
					flag = false;
				}
			}
		}
	
		if (flag == true){
			for (i = 0;  i < theForm.email.value.length;  i++){
				if (theForm.email.value.charAt(i) == '@'){
					flag = true;
					break;
				}else {
					flag = false;
				}
			}
		}
		
		if (flag == true){
			for (i = 0;  i < theForm.email.value.length;  i++){
				if (theForm.email.value.charAt(i) == '.'){
					flag = true;
					break;
				}else{
					flag = false;
				}
			}
		}
		
		if (flag == false){
			alert('E-mail non inserita correttamente!!!');
			theForm.email.focus();
			return false;
		}
	}
	
	/*
	 * controllo user e pwd
	 */
	/*
	if (theForm.user.value == ""){
		alert("Inserire lo USERNAME.");
		theForm.user.focus();
		return false;
	}
	
	if (theForm.user.value.length < 6 ){
		alert("Lo USERNAME deve essere lungo almeno 6 caratteri.");
		theForm.user.focus();
		return false;
	}

	if (theForm.pwd.value == ""){
		alert("Inserire la PASSWORD.");
		theForm.pwd.focus();
		return false;
	}
	
	if (theForm.pwd.value.length < 6 ){
		alert("La PASSWORD deve essere lunga almeno 6 caratteri.");
		theForm.pwd.focus();
		return false;
	}

	if (theForm.conf_pwd.value == ""){
		alert("Inserire la PASSWORD di verifica.");
		theForm.conf_pwd.focus();
		return false;
	}
	
	if (theForm.conf_pwd.value.length < 6 ){
		alert("La PASSWORD di verifica deve essere lunga almeno 6 caratteri.");
		theForm.conf_pwd.focus();
		return false;
	}

	if (theForm.user.value == theForm.pwd.value ){
		alert("USERNAME e PASSWORD deve essere diverse. Si prega di modificarli.");
		theForm.user.focus();
		return false;
	}

	if (theForm.conf_pwd.value != theForm.pwd.value ){
		alert("Le PASSWORD non coincidono. Si prega di reinserirle.");
		theForm.pwd.value = "";
		theForm.conf_pwd.value = "";
		theForm.pwd.focus();
		return false;
	}
	*/
}

function slide_media(str){
	searchWin = window.open(str,'popup','scrollbars=yes,resizable=no,width=500,height=600,status=no,location=no,toolbar=no');
}

function controllo_ricerca(theForm){
	if (theForm.campo.value=="nome_studio"){
		if (theForm.value_campo.value==""){
			alert("INSERIRE ALMENO LE INIZIALI DELLO STUDIO PER LA RICERCA");
			theForm.value_campo.focus();
			return (false);
		}
	}else{
		if (theForm.value_campo.options.value==0){
			alert("SELEZIONARE ALMENO UN VALORE PER LA RICERCA");
			theForm.value_campo.focus();
			return (false);
		}
	}
}

/************************/
/********* AJAX *********/
/************************/

var xmlHttp = false;
var isBusy = false;
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

/*
ho definito l'oggetto xmlHttp in cima al file
*/
if (browser=="Internet Explorer"){
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			xmlHttp = false;
		}
	}
}else{
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
	}
}

/*
	------------------------------------------------
	DALLE PROVINCE AI COMUNI
	------------------------------------------------
*/
function prov_to_comuni(id_prov,s_url){
	
	if ((id_prov == null) || (id_prov == "") || (id_prov == 0) ) return;
	
	var url = s_url+"getData.asp?opt=prov_to_comuni&id_prov="+id_prov;

	if (isBusy){
		xmlHttp.onreadystatechange = null; // no go in IE
		xmlHttp.abort();
	}
	
	// Open a connection to the server
	xmlHttp.open("GET", url, true);
	
	isBusy = true;

	// Setup a function for the server to run when it's done
	xmlHttp.onreadystatechange = scrivi_comuni;

	// Send the request
	xmlHttp.send(null);

}

function scrivi_comuni(){
	if (xmlHttp.readyState != 4){
		return;
	}else if (xmlHttp.readyState == 4){
		isBusy = false;
		
		var obj = document.getElementById("citta");
		obj.options.length = 0;
		obj.options[0] = new Option('Seleziona...',0);
		var response = xmlHttp.responseText;
		//alert(response);
		eval(response);
	}
}
