// JavaScript Document

/*Imposta il background in funzione della risoluzione del video*/
var risoluzione = screen.width;
	if (risoluzione<1280){
		document.write("<link rel='stylesheet' href='stili/ris_1024.css' type='text/css'>");
	} else {
		document.write("<link rel='stylesheet' href='stili/ris_1280.css' type='text/css'>");
	}

/*Pulisce i campi con onFocus e segnala campo attivo*/
function selezionaCampo(id,pulisci){
	var campo = id;
	var clear = pulisci;
	if (!document.getElementById) return;
	
	selDiv = document.getElementById(id);
	selDiv.style.backgroundColor = "#FFFFCC";
	
	if (clear != "noClear"){
		document.getElementById(campo).value = '';	
	}

}
function deselezionaCampo(id){
	var campo = id;
	desDiv = document.getElementById(id);
	desDiv.style.backgroundColor = "#ffffff";
}

/*immagine gallery*/
function makeVisible(modulo,immagine,titolo) {
	document.getElementById('view').innerHTML = '<img src="img/img_'+modulo+'/'+immagine+'" alt="Anteprima immagine" />';
	document.getElementById('view_text').innerHTML = titolo;
}

/*Controllo tipo di campo nei form che poi richiama le libreria AJAX mandando le informazioni*/
function checkInput (rFld, msgField, rUrl, rPar) {
	if (document.getElementById(rFld)) {
		htmlReplace(msgField, '<img src="../img/ajax/loader.gif" style=\"vertical-align:middle\" /> Controllo in corso...', 1);
		var iFld = document.getElementById(rFld);
		var iValue = iFld.value;
		iValue = myEscape(iValue);
		rPar = rPar + '&campo=' + rFld + '&valore=' + iValue;
		// questa e' la chiamata al php su server
		rqs(msgField, rUrl, rPar, 1);
	}
	return;
}

function check_registrazione(myForm){
		document.getElementById('controllo_form').innerHTML = "Inizio validazione campi";
		var str;
		var err = 6;

		iFld = 'Ragione_Sociale'; iFldOut = 'Ragione_Sociale_out';
		checkInput (iFld, iFldOut, 'formcheck.php', 'tipo=');
		str = document.getElementById(iFldOut).innerHTML
		if (!str.match(/error/gi)) { err = err - 1; }

		iFld = 'Nome_referente'; iFldOut = 'Nome_referente_out';
		checkInput (iFld, iFldOut, 'formcheck.php', 'tipo=name');
		str = document.getElementById(iFldOut).innerHTML
		if (!str.match(/error/gi)) { err = err - 1; }

		iFld = 'Telefono'; iFldOut = 'Telefono_out';
		checkInput (iFld, iFldOut, 'formcheck.php', 'tipo=tel');
		str = document.getElementById(iFldOut).innerHTML
		if (!str.match(/error/gi)) { err = err - 1; }

		iFld = 'Mail'; iFldOut = 'Mail_out';
		checkInput (iFld, iFldOut, 'formcheck.php', 'tipo=mail');
		str = document.getElementById(iFldOut).innerHTML
		if (!str.match(/error/gi)) { err = err - 1; }

		iFld = 'Username'; iFldOut = 'Username_out';
		checkInput (iFld, iFldOut, 'formcheck.php', 'tipo=user');
		str = document.getElementById(iFldOut).innerHTML
		if (!str.match(/error/gi)) { err = err - 1; }

		if (document.getElementById('Password').value == document.getElementById('Conferma_Password').value) {
			iFld = 'Password'; iFldOut = 'Password_out';
			checkInput (iFld, iFldOut, 'formcheck.php', 'tipo=login');
			str = document.getElementById(iFldOut).innerHTML
			if (!str.match(/error/gi)) { err = err - 1; }
		}
		else { document.getElementById('Conferma_Password_out').innerHTML = 'Password e conferma password non coincidono'; }
		
		if (err) {
			document.getElementById('controllo_form').innerHTML = "Sono presenti degli errori";
		}
		else {
			var thisForm = document.getElementById(myForm);
			thisForm.submit();
		}

		return;
}