var codFiscale = Class.create();
codFiscale.prototype = {
	initialize: function() {
		
	},
	calculate: function() {
		var url="codFis/ajaxcf.php";
		var pars="action=cf";
		pars+="&n="+$('nome').value;
		pars+="&c="+$('cognome').value;
		pars+="&s="+$('sesso').options[$('sesso').selectedIndex].value;
		pars+="&g="+$('giorno').options[$('giorno').selectedIndex].value;
		pars+="&m="+$('mese').options[$('mese').selectedIndex].value;
		pars+="&a="+$('anno').value;
		pars+="&l="+$('cittaNascita').value;
		pars+="&p="+$('provinciaNascita').options[$('provinciaNascita').selectedIndex].value;
		var myAjax=new Ajax.Request(
			url,
			{
				method: 'post',
				parameters: pars,
				onComplete: function(transport) {
					//var cf=eval('(' + originalRequest.responseText + ')');
					var cf=transport.responseText.evalJSON();
					//console.log(cf.val);
					if (cf.ok) {
						$('cf').value=cf.val;
						$('cf_err').firstChild.nodeValue=" ";
					} else {
						//alert($('cf_err'))
						$('cf_err').firstChild.nodeValue=cf.val;
					}
				}
			}		
		);
	},
	toggle:function(country) {
		if(country=="IT") {
			$('cfis_div').show();
			//new Effect.BlindDown($('cfis_div'));
		} else {
			$('cfis_div').hide();
			//new Effect.BlindUp($('cfis_div'));
		}
	}
};
var codfis=new codFiscale();

var speseSpedizione=Class.create();
speseSpedizione.prototype = {
	initialize:function() {
	},
	calculate:function(select,country,qty,tot,c_fis,country1) {
		var url="codFis/ajaxcf.php";
		var pars="action=ss";
		var iva=0;
		if (country1=="IT") {
			iva=21;
		}		//alert(select+","+country+","+qty+","+tot+","+c_fis)
		if (c_fis) {
			if(country=="IT") {
				$('cfis_div').show();
				//new Effect.BlindDown($('cfis_div'));
			} else {
				$('cfis_div').hide();
				//new Effect.BlindUp($('cfis_div'));
			}
		}
		if (select=='nazione2' && $('nazione2').selectedIndex==0) {
			if ($('nazione').options) {
				country=$('nazione').options[$('nazione').selectedIndex].value;
			} else {
				country=$('nazione').value;
			}
		}
		if ((select=='nazione2')||(select=='nazione' && $('nazione2').selectedIndex==0)) {
			var myAjax=new Ajax.Request(
				url,
				{
					method: 'post',
					parameters: {
						action:"ss",
						country:country,
						qty:qty,
						t:tot,
						v:iva,
						nocache:new Date().getTime()
					},
					onComplete: function(transport) {
						//var cf=eval('(' + originalRequest.responseText + ')');
						var totals=transport.responseText.evalJSON();
						//console.log(cf.val);
						$('s_rate').update(totals.s_r);
						$('tot').update(totals.t);
					}
				}		
			);
		}
	}
};
var spese=new speseSpedizione();
