
//LA FUNZIONE VA RICHIAMATA NEL TAG form IN QUESTO MODO:
//<form name="modulo" action="sendmail.asp" method="post" onsubmit="return controllo('modulo', 'nome,email,msg'); return false;">
//INDICANDO NELL' onsubmit= IL NOME DEL FORM STESSO E IL NOME DEI CAMPI DA CONTROLLARE SEPARATI DA VIRGOLA


function controllo(formnome, arr) {
	// Controllo dei campi form (text-textarea-radio-select-checkbox)
	 
	var col_array = arr.split(",");

	var part_num=0;
	
	while (part_num < col_array.length)
	{
		var nomecampo = col_array[part_num];
		//
		var tipocampo = document.forms[formnome].elements[nomecampo].type; 
				
// ############################################################

			// Campo testo
			if (tipocampo ==  'text' || tipocampo == 'password') {
			
				// Se campo testo email
				var valorecampo = document.forms[formnome].elements[nomecampo].value;
				//alert(valorecampo.length);
				if (nomecampo.indexOf("email") != -1 && (valorecampo.indexOf("@") == -1 || valorecampo.indexOf(".") == -1 || valorecampo < 8)) {
					alert('Formato email non valido');
					return false;
				
				} else {
					// Se campo testo non email
					if (!valorecampo) {
						if (nomecampo == 'foto') {
							alert('Devi caricare almeno una tua foto per continuare');
						} else {
							alert('Compila il campo ' + nomecampo);
						}
						return false;
					}
				}
						
			}
		

// ############################################################
				
		// Campo textarea
		else if (tipocampo ==  'textarea') {
				
				// Se campo textarea
				var valorecampo = document.forms[formnome].elements[nomecampo].value;
				if (!valorecampo) {
					alert('Compila il campo ' + nomecampo);
					return false;
				}
		
		}

// ############################################################
		
		// Campo checkbox
		else if (tipocampo ==  'checkbox') {
				
				// Se campo checkbox
				var valorecampo = document.forms[formnome].elements[nomecampo].checked;
				if (!valorecampo) {
					alert('Il Campo "' + nomecampo + '" deve essere obbligatoriamente selezionato per continuare');
					return false;
				}
						
		}

	
// ############################################################
		
		// Campo select
		else if (tipocampo ==  'select-one') {
			var valorecampo = document.forms[formnome].elements[nomecampo].value;
			if(!valorecampo){
				alert('Compila il campo ' + nomecampo);
				return false;
			}		
		}

// ############################################################
		
		// Campo radio
		//else {
		//	var valorecampo = document.modulo.sesso.value;
		//	if (!valorecampo) {
		//		alert('Campo ' + nomecampo + ' non selezionato');
		//	}
		
		//}

// ############################################################		


		part_num+=1;
	}
}

function acc_legge() {
	// Controllo accettazione leggi

	var consenso1 = document.forms['modulo'].elements['consenso1'].checked;
	var consenso2 = document.forms['modulo'].elements['consenso2'].checked;
	
	if (!consenso1) {
		alert('Per continuare devi autorizzare la pubblicazione delle foto selezionando la casella accanto al testo');
		return false;
	}
	if (!consenso2) {
		alert('Per continuare devi autorizzare la legge sul trattamento dei dati personali selezionando la casella accanto al testo');
		return false;
	}
}


function show(name, action)
		{
			element = document.getElementById(name);
			if(action=="1")
				element.style.display = "block";
			else if(action=="2")
				element.style.display = "none";
		}

	

function roll(mode,nome,over)
{
	if(mode=="over")
	{
		imgOver="imgg/"+nome+"_over.gif";
		document[nome].src=imgOver;
	}

	if(mode=="out")
	{
		imgOut="imgg/"+nome+".gif";
		document[nome].src=imgOut;
	}
}

function replace(id,page,stato)
{
	//if (stato=='none')
	//{
	if (stato=='block')
	{
		document.getElementById('collezione').innerHTML = '<a href="#" onclick="replaceIframe(\'main\', \'catalogo.asp\', \'none\'); return false;" title="Guarda il catalogo della Collezione Rossella Carrara Spring/Summer 2010"><img src="imgg/ss_2010.gif" alt="Rossella Carrara" /></a>';
		 document.getElementById('menu_main').style.display = 'none';
		 document.getElementById("enonsolo").style.display='block';
	}	else	{
		 document.getElementById('collezione').innerHTML = '';
		 document.getElementById('menu_main').style.display = 'block';
		 document.getElementById("enonsolo").style.display='none';
		 
	}
	
	document.getElementById(id).innerHTML = '<p style=\"text-align: center; margin: 50px 0px 50px 0px;\"><img src=\"imgg/ajax-loader.gif\"\ /></p>';
	$.ajax({
	url: page,
	cache: 'true',
	success: function(data) {
		$('#' + id).html(data);
	}
	}); 

}

function callExternalInterface() {
	thisMovie("externalInterfaceExample").goHome();
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	}
	else {
		return document[movieName];
	}
} 

function cambiosfondo(img)
{			
	document.getElementById("body_page").style.backgroundImage="url('img/"+img+"')";
	setCookie('sfondo', img, 10);
}

function setCookie(name, value, expiredays, path, domain, secure) {
    var expires = new Date();
    expires.setDate( expires.getDate() + expiredays );
    var cookieString = name + "=" +escape(value) +
       ( (expires) ? ";expires=" + expires.toGMTString() : "") +
       ( (path) ? ";path=" + path : "") +        
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
}
function getCookie( name ) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return(null);
   if (start == -1) return(null);
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
  
   return(unescape(document.cookie.substring(len,end)) );
}
