jQuery.fn.highlightFade = function(settings) {
	var o = (settings && settings.constructor == String) ? {start: settings} : settings || {};
	var d = jQuery.highlightFade.defaults;
	var i = o['interval'] || d['interval'];
	var a = o['attr'] || d['attr'];
	var ts = {
		'linear': function(s,e,t,c) { return parseInt(s+(c/t)*(e-s)); },
		'sinusoidal': function(s,e,t,c) { return parseInt(s+Math.sin(((c/t)*90)*(Math.PI/180))*(e-s)); },
		'exponential': function(s,e,t,c) { return parseInt(s+(Math.pow(c/t,2))*(e-s)); }
	};
	var t = (o['iterator'] && o['iterator'].constructor == Function) ? o['iterator'] : ts[o['iterator']] || ts[d['iterator']] || ts['linear'];
	if (d['iterator'] && d['iterator'].constructor == Function) t = d['iterator'];
	return this.each(function() {
		if (!this.highlighting) this.highlighting = {};
		var e = (this.highlighting[a]) ? this.highlighting[a].end : jQuery.highlightFade.getBaseValue(this,a) || [255,255,255];
		var c = jQuery.highlightFade.getRGB(o['start'] || o['colour'] || o['color'] || d['start'] || [255,255,128]);
		var s = jQuery.speed(o['speed'] || d['speed']);
		var r = o['final'] || (this.highlighting[a] && this.highlighting[a].orig) ? this.highlighting[a].orig : jQuery.curCSS(this,a);
		if (o['end'] || d['end']) r = jQuery.highlightFade.asRGBString(e = jQuery.highlightFade.getRGB(o['end'] || d['end']));
		if (typeof o['final'] != 'undefined') r = o['final'];
		if (this.highlighting[a] && this.highlighting[a].timer) window.clearInterval(this.highlighting[a].timer);
		this.highlighting[a] = { steps: ((s.duration) / i), interval: i, currentStep: 0, start: c, end: e, orig: r, attr: a };
		jQuery.highlightFade(this,a,o['complete'],t);
	});
};

jQuery.highlightFade = function(e,a,o,t) {
	e.highlighting[a].timer = window.setInterval(function() { 
		var newR = t(e.highlighting[a].start[0],e.highlighting[a].end[0],e.highlighting[a].steps,e.highlighting[a].currentStep);
		var newG = t(e.highlighting[a].start[1],e.highlighting[a].end[1],e.highlighting[a].steps,e.highlighting[a].currentStep);
		var newB = t(e.highlighting[a].start[2],e.highlighting[a].end[2],e.highlighting[a].steps,e.highlighting[a].currentStep);
		jQuery(e).css(a,jQuery.highlightFade.asRGBString([newR,newG,newB]));
		if (e.highlighting[a].currentStep++ >= e.highlighting[a].steps) {
			jQuery(e).css(a,e.highlighting[a].orig || '');
			window.clearInterval(e.highlighting[a].timer);
			e.highlighting[a] = null;
			if (o && o.constructor == Function) o.call(e);
		}
	},e.highlighting[a].interval);
};

jQuery.highlightFade.defaults = {
	start: [255,255,255],
	interval: 50,
	speed: 500,
	attr: 'backgroundColor'
};

jQuery.highlightFade.getRGB = function(c,d) {
	var result;
	if (c && c.constructor == Array && c.length == 3) return c;
	if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))
		return [parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];
	else if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))
		return [parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];
	else if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))
		return [parseInt("0x" + result[1]),parseInt("0x" + result[2]),parseInt("0x" + result[3])];
	else if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))
		return [parseInt("0x"+ result[1] + result[1]),parseInt("0x" + result[2] + result[2]),parseInt("0x" + result[3] + result[3])];
	else
		return jQuery.highlightFade.checkColorName(c) || d || null;
};

jQuery.highlightFade.asRGBString = function(a) {
	return "rgb(" + a.join(",") + ")";
};

jQuery.highlightFade.getBaseValue = function(e,a,b) {
	var s, t;
	b = b || false;
	t = a = a || jQuery.highlightFade.defaults['attr'];
	do {
		s = jQuery(e).css(t || 'backgroundColor');
		if ((s  != '' && s != 'transparent') || (e.tagName.toLowerCase() == "body") || (!b && e.highlighting && e.highlighting[a] && e.highlighting[a].end)) break; 
		t = false;
	} while (e = e.parentNode);
	if (!b && e.highlighting && e.highlighting[a] && e.highlighting[a].end) s = e.highlighting[a].end;
	if (s == undefined || s == '' || s == 'transparent') s = [255,255,255];
	return jQuery.highlightFade.getRGB(s);
};

jQuery.highlightFade.checkColorName = function(c) {
	if (!c) return null;
	switch(c.replace(/^\s*|\s*$/g,'').toLowerCase()) {
		case 'aqua': return [0,255,255];
		case 'black': return [0,0,0];
		case 'blue': return [0,0,255];
		case 'fuchsia': return [255,0,255];
		case 'gray': return [128,128,128];
		case 'green': return [0,128,0];
		case 'lime': return [0,255,0];
		case 'maroon': return [128,0,0];
		case 'navy': return [0,0,128];
		case 'olive': return [128,128,0];
		case 'purple': return [128,0,128];
		case 'red': return [255,0,0];
		case 'silver': return [192,192,192];
		case 'teal': return [0,128,128];
		case 'white': return [255,255,255];
		case 'yellow': return [255,255,0];
	}
};

window.onload = function(){
	BoxMax = 0;

}

function newAjax() {
	var xmlHttp;
	try
	{
		// Firefox, Opera e Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (exc)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (exc)
		{
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (exc)
			{
				alert("Il tuo browser non supporta AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

function addFormField() {
	BoxMax++;
	document.prenotazione.boxmax.value = BoxMax;
	var id = document.getElementById("id").value;
	$("#divTxt").append("<div id='row" + id + "' class=\"gray-box\"><p>Numero di persone: <input type=\"text\" size=\"5\" name=\"persone" + id + "\" id=\"personerow" + id + "\" /></p>    <p>Tipo di biglietto: <select name=\"biglietto" + id + "\" id=\"biglietto\"><option value=\"Intero Villa del Principe + Mostra (12€)\">Intero Villa del Principe + Mostra (12€)</option><option value=\"Ridotto  Villa del Principe + Mostra (9€)\">Ridotto Villa del Principe + Mostra (9€)</option><option value=\"Scuole (7€)\">Scuole (7€)</option></select></p>	<p><a href='javascript:void(0);' onClick='removeFormField(\"row" + id + "\");'> - Rimuovi gruppo</a></p>	</div>");
		
	$("#row" + id).highlightFade({
	speed:1000
	});
		
	id = (id - 1) + 2;
	document.getElementById("id").value = id;
}
function addFormFieldAcquario() {
	BoxMax++;
	document.prenotazione.boxmax.value = BoxMax;
	var id = document.getElementById("id").value;
	$("#divTxt").append("<div id='row" + id + "' class=\"gray-box\"><p>Numero di persone: <input type=\"text\" size=\"5\" name=\"persone" + id + "\" id=\"personerow" + id + "\" /></p>    <p>Tipo di biglietto: <select name=\"biglietto" + id + "\" id=\"biglietto\"><option value=\"Intero Palazzo del Principe (9€)\">Intero Palazzo del Principe (9€)</option><option value=\"Ridotto Palazzo del Principe (7€)\">Ridotto Palazzo del Principe (7€)</option><option value=\"Intero Palazzo del Principe + Acquario di Genova (20€)\" selected=\"selected\">Intero Palazzo del Principe + Acquario di Genova (20€)</option><option value=\"Ridotto Palazzo del Principe + Acquario di Genova (13€)\">Ridotto Palazzo del Principe + Acquario di Genova (13€)</option><option value=\"Intero Palazzo del Principe + Galata Museo del Mare (12€)\">Intero Palazzo del Principe + Galata Museo del Mare (12€)</option><option value=\"Ridotto Palazzo del Principe + Galata Museo del Mare (8€)\">Ridotto Palazzo del Principe + Galata Museo del Mare (8€)</option></select></p>	<p><a href='javascript:void(0);' onClick='removeFormField(\"row" + id + "\");'> - Rimuovi gruppo</a></p>	</div>");
		
	$("#row" + id).highlightFade({
	speed:1000
	});
		
	id = (id - 1) + 2;
	document.getElementById("id").value = id;
}

function removeFormField(id) {
	document.getElementById("persone"+id).value="";
	$("#"+id).slideUp(300);
	$("#"+id).remove(1000);
}

function sendEmail(valori) {
	$("#messaggio").html('<p style="font-size:15px; font-style:italic;" class="gold"><em>La tua prenotazione &egrave; stata inoltrata correttamente.</em></p><p>Riceverai una conferma entro un giorno lavorativo.<br /><strong>Grazie per la collaborazione.</strong></p>');
	$("#prenotazione-lettera").animate({ 
        top: -500
    }, 500 );
	$("#box-prenotazione-lettera").fadeOut(500);
	$("#prenotazione-lettera").fadeOut(500);
	
	var ajax = newAjax();
	var url = "http://www.dopart.it/genova/it/wp-content/themes/doria-pdp/sendEmail.php?";
 	ajax.open("GET", url+valori, true);
	ajax.send(null);
}
