function clear(nomeForm) {
	jQuery("#" + nomeForm).find(':input').each(function() {
		if (this.type == 'password' || this.type == 'text') {
        	jQuery(this).val('');
        }
  	    if (this.type == 'checkbox' || this.type == 'radio') {
        	this.checked = false;
       	}
  	});
}

function disableForm(nomeForm) {	
	jQuery("#" + nomeForm).find(':input').each(function() {	
		if (this.type != 'textarea' && this.type != 'image') {
			jQuery("#"+nomeForm+" :input[name='"+this.name+"']").attr("disabled","disabled");		
			if (this.type == 'password' || this.type == 'text' || this.type == 'select-one') {
            	jQuery("#"+nomeForm+" :input[name='"+this.name+"']").css("background-color","#FEEAAA");
				jQuery("#"+nomeForm+" :input[name='"+this.name+"']").css("color","#000000");
				jQuery("#"+nomeForm+" :input[name='"+this.name+"']").css("border","1px solid #888888");               	
	       	}
		}	       				
  	});
}

function disableFormByStatoAnag(nomeForm, isAnagAttiva) {
	if (isAnagAttiva == 'false') {
		disableForm(nomeForm);
	}
	
	// se l'anagrafica e' attiva metto il calendario sui campi data
	if (isAnagAttiva == 'true') {
		jQuery("#" + nomeForm).find(':input[type=text]').each(function() {		
			if (this.id.indexOf("datepicker_icon") > -1) {
				datePicker(this.id);
			}		
		});
	}
}	

function impostaPrivacy(profilazione, marketing) {	
	var consensoProf = false;	
	if (profilazione == 'S') {			
		consensoProf = true;
	}
	var consensoMark = false;	
	if (marketing == 'S') {
		consensoMark = true;	
	}
	
	if (profilazione != '') {
		jQuery(':input[id="consensoProfilazioneSi"]').attr("checked", consensoProf);
		jQuery(':input[id="consensoProfilazioneNo"]').attr("checked", !consensoProf);
	}
	if (marketing != '') {
		jQuery(':input[id="consensoMarketingSi"]').attr("checked", consensoMark);
		jQuery(':input[id="consensoMarketingNo"]').attr("checked", !consensoMark);
	}
}

function fileRead(filename, mode) {
    var r = !window.XMLHttpRequest ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest;
    r.open(mode ? "PUT" : "GET", filename, false);
    r.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-1"); 
    if (r.overrideMimeType) {
	    r.overrideMimeType("application/x-www-form-urlencoded; charset=ISO-8859-1");  
	}
    r.send(mode ? mode : "");
    return r.responseText;
}

function putFileIntoTextArea(textFile, idTextArea) {
	/*jQuery.get(textFile, function(data){
  		jQuery('#' + idTextArea).val(data);
	});*/
	var text = fileRead(textFile);
	jQuery('#' + idTextArea).val(text);	
}
		
function execute(nomeForm, action) {
	jQuery('#' + nomeForm).attr("action", action);
	jQuery('#' + nomeForm).submit();
}

function change(nomeform, nomeCampo, valore, submit){
	jQuery("#" + nomeform + " :input[name='" + nomeCampo + "']").val(valore);
	if (submit != false){
		jQuery("#" + nomeform).submit();
	}
}

function impostaConsensi() {
	jQuery('#consensoProfilazioneSi').click(function() {
		if (jQuery('#consensoProfilazioneSi').is(':checked')) {			 
			jQuery('#consensoProfilazioneNo').attr("checked", false);
		}
	});
	
	jQuery('#consensoProfilazioneNo').click(function() {
		if (jQuery('#consensoProfilazioneNo').is(':checked')) {			 
			jQuery('#consensoProfilazioneSi').attr("checked", false);
		}
	});
	
	jQuery('#consensoMarketingSi').click(function() {
		if (jQuery('#consensoMarketingSi').is(':checked')) {			 
			jQuery('#consensoMarketingNo').attr("checked", false);
		}
	}); 
	
	jQuery('#consensoMarketingNo').click(function() {
		if (jQuery('#consensoMarketingNo').is(':checked')) {			 
			jQuery('#consensoMarketingSi').attr("checked", false);
		}
	}); 
}

function impostaLocalitaCapEProvincia(controller) {
		
	jQuery("#provincia").change(function() {
    	jQuery.getJSON("/" + controller + "/loadComuni", { provincia: jQuery("#provincia").val() }, function(j) {
	      	var options = '';
	      	for (var i = 0; i < j.length; i++) {
	        	options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
	      	}
	      	jQuery("#localita").html(options);
	      	jQuery("#localita").effect('highlight', {}, 1000);	      	
	      	jQuery.getJSON("/" + controller + "/loadCap", { provincia: jQuery("#provincia").val(), comune: jQuery("#localita").val() }, function(j) {
		      	var options = '';
		      	for (var i = 0; i < j.length; i++) {
		        	options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		      	}
		      	jQuery("#cap").html(options);
		      	jQuery("#cap").effect('highlight', {}, 1000);	      	
	    	})
    	})
  	});
  	
  	jQuery("#localita").change(function() {
    	jQuery.getJSON("/" + controller + "/loadCap", { provincia: jQuery("#provincia").val(), comune: jQuery("#localita").val() }, function(j) {
	      	var options = '';
	      	for (var i = 0; i < j.length; i++) {
	        	options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
	      	}
	      	jQuery("#cap").html(options);
	      	jQuery("#cap").effect('highlight', {}, 1000);
    	})
  	});
}

function datePicker(id) {
	if (id.indexOf("datepicker_icon") > -1) {
		jQuery("#" + id).datepicker({
			showOn: 'button', 
			buttonImage: '/mondadori-card/images/show-calendar.gif', 
			buttonImageOnly: true,
			changeMonth: true,
			changeYear: true,
			yearRange: '-100:+00'		
		});
	}			
}

/* script di lettura dati da xml per classifica LIBRI */
function loadClassificaLibri() {
	jQuery.ajax({
    	type: "GET",
		/* path dell'xml contenente la classifica */
        url: "/mondadori-card/statici/classifica/data_libri.xml",
        dataType: "xml",
        success: function(xml) {
			var jQueryid = 1; 
			jQuery(xml).find('product').each(function(){
				var id=jQueryid++;
				/* cicla la classifica dal 1° elemento fino al 5°, quando arriva al 6 si ferma. */
				if (id==6) return false;
				/* parametri letti dal file xml, solo quelli nel <li> vengono poi stampati */
				var img=jQuery(this).attr('img');
				var titolo=jQuery(this).attr('titolo');
				var autore=jQuery(this).attr('autore');
				var prezzo=jQuery(this).attr('prezzo');
				var editore=jQuery(this).attr('editore');
				var pagine=jQuery(this).attr('pagine');
				var isbn=jQuery(this).attr('isbn');
				var desc=jQuery(this).attr('desc');
				var url=jQuery(this).attr('link');
				jQuery('<div class="items" id="link_'+id+'"></div>').html('<li><a href="'+url+'"><div id="classifica_id">'+id+'.</div><div id="classifica_autore"><h2>'+autore+'</h2><h3>'+titolo+'</h3></div><div id="classifica_dettagli"><h2>'+prezzo+'</h2><h3>'+editore+'</h3></div><div id="classifica_icona"><img src="/mondadori-card/images/ico_classifica.gif" width="21" height="24" /></div></a></li>').appendTo('.page-wrap');	
			});
		}
	});
}
        
/* script di lettura dati da xml per classifica CD */
function loadClassificaCD() {
	jQuery.ajax({
		type: "GET",
		/* path dell'xml contenente la classifica */
        url: "/mondadori-card/statici/classifica/data_cd.xml",
        dataType: "xml",
        success: function(xml) {
			var jQueryidcd = 1; 
			jQuery(xml).find('product').each(function(){
				var idcd=jQueryidcd++;
				/* cicla la classifica dal 1° elemento fino al 5°, quando arriva al 6 si ferma. */
				if (idcd==6) return false;
				/* parametri letti dal file xml, solo quelli nel <li> vengono poi stampati */
				var imgcd=jQuery(this).attr('img');
				var titolocd=jQuery(this).attr('titolo');
				var artistacd=jQuery(this).attr('artista');
				var prezzocd=jQuery(this).attr('prezzo');
				var etichettacd=jQuery(this).attr('etichetta');
				var generecd=jQuery(this).attr('genere');
				var desccd=jQuery(this).attr('desc');
				var urlcd=jQuery(this).attr('link');				
				jQuery('<div class="items" id="link_'+idcd+'"></div>').html('<li><a href="'+urlcd+'"><div id="classifica_id">'+idcd+'.</div><div id="classifica_autore"><h2>'+artistacd+'</h2><h3>'+titolocd+'</h3></div><div id="classifica_dettagli"><h2>'+prezzocd+'</h2><h3>'+etichettacd+'</h3></div><div id="classifica_icona"><img src="/mondadori-card/images/ico_classifica.gif" width="21" height="24" /></div></a></li>').appendTo('.page-wrapcd');				
			});
		}
	});
}

/* script di lettura dati da xml per classifica DVD */
function loadClassificaDVD() {
		jQuery.ajax({
    	type: "GET",
		/* path dell'xml contenente la classifica */
        url: "/mondadori-card/statici/classifica/data_dvd.xml",
        dataType: "xml",
        success: function(xml) {
			var jQueryiddvd = 1; 
			jQuery(xml).find('product').each(function(){
				var iddvd=jQueryiddvd++;
				/* cicla la classifica dal 1° elemento fino al 5°, quando arriva al 6 si ferma. */
				if (iddvd==6) return false;
				/* parametri letti dal file xml, solo quelli nel <li> vengono poi stampati */
				var img=jQuery(this).attr('img');
				var titolodvd=jQuery(this).attr('titolo');
				var registadvd=jQuery(this).attr('regista');
				var prezzodvd=jQuery(this).attr('prezzo');
				var etichettadvd=jQuery(this).attr('etichetta');
				var generedvd=jQuery(this).attr('genere');
				var annodvd=jQuery(this).attr('anno');
				var duratadvd=jQuery(this).attr('durata');
				var descdvd=jQuery(this).attr('desc');
				var urldvd=jQuery(this).attr('link');				
				jQuery('<div class="items" id="link_'+iddvd+'"></div>').html('<li><a href="'+urldvd+'"><div id="classifica_id">'+iddvd+'.</div><div id="classifica_autore"><h2>'+registadvd+'</h2><h3>'+titolodvd+'</h3></div><div id="classifica_dettagli"><h2>'+prezzodvd+'</h2><h3>'+etichettadvd+'</h3></div><div id="classifica_icona"><img src="/mondadori-card/images/ico_classifica.gif" width="21" height="24" /></div></a></li>').appendTo('.page-wrapdvd');									
			});
		}
	});
}

function getTicker() {
	var text = fileRead('/mondadori-card/statici/ticker.txt')
	var html = '';
	var i = -1, a = text.split(/\s*\n\s*/);	
    while (a[++i]) {
     	html += '<li><h2>' + a[i] + '</h2></li>';
    }
    return html;
}

function getFile(nomeFile) {
	var html = '';
	if (nomeFile != null && nomeFile != '') {
		var text = fileRead(nomeFile)
		var i = -1, a = text.split(/\s*\n\s*/);	
	    while (a[++i]) {
	     	html += a[i];
	    }
	}
    return html;
}

function MM_changeProp(objId,x,theProp,theValue) { //v9.0
	var obj = null; with (document){ if (getElementById)
  	obj = getElementById(objId); }
  	if (obj) {
    	if (theValue == true || theValue == false)
      		eval("obj.style."+theProp+"="+theValue);
    	else eval("obj.style."+theProp+"='"+theValue+"'");
  	}
}

