/*
	Javascript per OGame Commercial Helper - Modulo base
	by Keul - Ago 2006
*/

var OGCH_VERSION = "0.3";

var MAX_QUANTITY = "1000000000"

var isFloating = true;
var f = null;
var body = null;
var ifOpera = document.styleSheets?false:true;
var ifIE = (document.all?true:false)&&(!ifOpera); // Opera sucks... ha document.all ?!?!

var startDragX = -1;
var startDragY = -1;

mouseX = -1;
mouseY = -1;

// Per il movimento dell'interfaccia nella versione a schermo pieno
moving = false;
var movingTop = null;
var movingLeft = null;

var ERROR_FIELD_COLOR = "red";

var LIMIT_ERR_MESSAGE_BASE = "Il rapporto corrente $1 ha valore $2:1.<br/>Le regole impostate permettono un valore compreso tra $3:1 e $4:1.<br/><b>NB:</b> violare il regolamento OGame è passibile di ban!";
var TOOLTIP_BASE = "title=cssbody=[tooltipbody] cssheader=[tooltipheader] header=[$1] body=[$2] offsety=[-30] offsetx=[20] fade=[on] fadespeed=[0.08]";

var limitErrMessage = "";
var oldRappImgTitle = "";

var queryString = "";
var documentStyleSheets = [];
var logStore = "";

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function PageLoaded() {
	f = document.forms[0];
	body = document.getElementById('theBody');
	optPanel1 = document.getElementById("options1");
	optPanel2 = document.getElementById("options2");
	document.onmousemove = getMouseXY;
	document.onclick = checkClicks;
	body.style.marginTop = '0px';
	body.style.marginLeft = '0px';
		
	mModified = false;
	cModified = false;
	dModified = false;
	if (window.name!="commhelper") {
		isFloating = false;
		h = document.getElementById('dragging');
		h.title="Sposta la finestra";
		body.style.padding="0.5em";
		document.getElementById("dragging").ondragstart = "moveWin";
	}
	// Dati caricati da XML?
	if (minmaxCheck) {
		f['mval'].value = mStartVal;
		f['cval'].value = cStartVal;
		f['dval'].value = dStartVal;

		// Show image for info about XML loaded
		iminfo = document.getElementById("rapp-help-img");
		iminfo.style.visibility = "visible";
		setToolTip(iminfo,"Tabella rapporti caricata",TABLE_RAPP.replace("$1",mcBaseRate.toFixed(2)).replace("$2",mcMinRate.toFixed(2)).replace("$3",mcMaxRate.toFixed(2)).replace("$4",mdBaseRate.toFixed(2)).replace("$5",mdMinRate.toFixed(2)).replace("$6",mdMaxRate.toFixed(2)).replace("$7",cdBaseRate.toFixed(2)).replace("$8",cdMinRate.toFixed(2)).replace("$9",cdMaxRate.toFixed(2)));
	}

	// Cambio del titolo?
	if (customTitle) {
		document.getElementById("dragging").innerHTML = "OGCH - " + customTitle;
	}

	// *** Cambio dei CSS ***
	documentStyleSheets = document.getElementsByTagName("link");

	if (customBaseCSS!="") {
		//alert(document.styleSheets[0].href)
		if (customBaseCSS.indexOf("%2f")!=-1) customBaseCSS = unescape(customBaseCSS);
		cur = documentStyleSheets.item(0);
		cur.setAttribute("href",customBaseCSS);
	}

	if (customTooltipsCSS!="") {
		//alert(document.styleSheets[1].href)
		if (customTooltipsCSS.indexOf("%2f")!=-1) customTooltipsCSS = unescape(customTooltipsCSS);
		cur = documentStyleSheets.item(1);
		cur.setAttribute("href",customTooltipsCSS);
	}

	if (ifIE && customInternetExploderCSS!="") {
		//alert(document.styleSheets[3].href)
		if (customInternetExploderCSS.indexOf("%2f")!=-1) customInternetExploderCSS = unescape(customInternetExploderCSS);
		cur = documentStyleSheets.item(3);
		cur.setAttribute("href",customInternetExploderCSS);
	}

	if (customPrefsCSS!="") {
		if (customPrefsCSS.indexOf("%2f")!=-1) customPrefsCSS = unescape(customPrefsCSS);
		cur = document.createElement("link");
		cur.type = "text/css";
		cur.rel = "stylesheet";
		cur.href = customPrefsCSS;
		document.body.appendChild(cur);
	}

	// Controlla se ci sono link da caricare esternamente
	externalLinks()

	setStartValuesEncubranceSpace();
	setTargetValuesEncubranceSpace();
	
	checkRateLimits('m');
	checkRateLimits('c');
	checkRateLimits('d');
}

function initMove() {
	if (isFloating) return false;
	moving = true;
	startDragX = mouseX;
	startDragY = mouseY;
	movingTop = body.style.marginTop;
	movingLeft = body.style.marginLeft;
}

function resetMove() {
	if (isFloating) return false;
	moving = false;
}

function getMouseXY(event) {
	if (ifIE) { // grab the x-y pos if browser is IE
		mouseX = window.event.x+document.body.scrollLeft;
		mouseY = window.event.y+document.body.scrollTop;
	} else {  // grab the x-y pos if browser is NS
		mouseX = event.pageX;
		mouseY = event.pageY;
	}
	if (moving) moveWin();
	if (sclick==0 && mouseX-eval(body.style.marginLeft.replace("px",""))>269 && mouseX-eval(body.style.marginLeft.replace("px",""))<273 && mouseY-eval(body.style.marginTop.replace("px",""))>165 && mouseY-eval(body.style.marginTop.replace("px",""))<169) {
		window.status="???"
		secret = 1;
	}
	else if (sclick==1 && mouseX-eval(body.style.marginLeft.replace("px",""))>162 && mouseX-eval(body.style.marginLeft.replace("px",""))<168 && mouseY-eval(body.style.marginTop.replace("px",""))>189 && mouseY-eval(body.style.marginTop.replace("px",""))<195) {
		secret = 1;
	}	else {
		window.status="";
		secret = 0;
	}
	//window.status = (mouseX-eval(body.style.marginLeft.replace("px",""))) + " " + (mouseY-eval(body.style.marginTop.replace("px","")))
}

function testDragIn(elem) {
	if (isFloating) return false;
	elem.style.cursor = 'move';
	window.status='Sposta la finestra';
	return true;
}
function testDragOut(elem) {
	if (isFloating) return false;
	window.status='';
	return true;
}

function moveWin() {
	if (isFloating) return false;
	movingTop = parseInt(new String(movingTop).replace("px",""));
	movingLeft = parseInt(new String(movingLeft).replace("px",""));
	body.style.marginTop = movingTop + (mouseY-startDragY) + "px";
	body.style.marginLeft = movingLeft + (mouseX-startDragX) + "px";
	window.status = "Y:"+body.style.marginTop+" X:"+body.style.marginLeft;
}

/*
	Ottiene i parametri passati da URL
*/
function getQueryStringParam(key) {
	if (queryString=="") {
		queryString = window.location.search.replace("%2f","/");
		if (queryString!="") queryString=queryString.substring(1, queryString.length);
		else return null;
	}
	params = queryString.split("&");
	for (i=0;i<params.length;i++) {
		row = params[i].split("=");
		if (row[0]==key) return row[1];
	}
}

/*
	Per tutti i campi che devono essere numerici e maggiori di 0
*/
function checkNumberAndNonZero(field,descr,restoreTo) {
   if (isNaN(field.value) || field.value<=0) {
   	alert("Il campo \'"+descr+"\' deve essere un numero positivo.");
      field.value=restoreTo;
   	field.focus();
   }
}

/*
	Ottiene il formato dei valori con l'uso del . divisorio.
	http://www.mredkj.com/javascript/numberFormat.html
*/
function formatDottedStr(strval) {
	strval = strval.toString();
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(strval)) {
		strval = strval.replace(rgx, '$1' + '.' + '$2');
	}
	return strval;
}
/*
	Formatta il campo con i . divisori
*/
function formatDotted(field) {
	notDotted = field.value;
	field.value = formatDottedStr(notDotted);
}

function unDot(strval) {
	return strval.replace(/\./g,"");
}

/*
	Per tutti i campi che devono essere numerici, non negativi e in cui possono essere fatte operazioni
*/
function checkAndEvalNumber(field,descr,restoreTo) {
	field.value = unDot(field.value);
	try {
		if (field.value.trim()=="") field.value = 0;
		field.value = eval(field.value);
	} catch ( e ) {
		field.value = 'errore'
	} 
	if (isNaN(field.value) || field.value<0) {
		alert("Il campo \'"+descr+"\' deve essere un numero non minore di 0.");
		field.value=restoreTo;
		field.focus();
   }
	if (eval(field.value) > MAX_QUANTITY) {
		alert("Il campo \'"+descr+"\' deve essere un numero non superiore a "+formatDottedStr(MAX_QUANTITY)+".");
		field.value=MAX_QUANTITY;
		field.focus();
   }
}

function calculate() {
	if (!checkValues()) return;
	// Moltiplicatori
	var mval = eval(f['mval'].value);
	var cval = eval(f['cval'].value);
	var dval = eval(f['dval'].value);
	// Di partenza, da convertire
	var mp = eval(unDot(f['mp'].value));
	var cp = eval(unDot(f['cp'].value));
	var dp = eval(unDot(f['dp'].value));
	// Slot selezionati
	var selm = f['use'][1].checked;
	var selc = f['use'][2].checked;
	var seld = f['use'][3].checked;
	// ***
	// Converto tutto in metallo
	var molt = [1, mval/cval, mval/dval];
	var totValue = conversion(mp,cp,dp,mval,cval,dval);
	//var totValue = mp+cp*molt[1]+dp*molt[2];
	// In cosa voglio convertire
	// Slot da conteggiare (1-3)
	var diffQ = 0;
	var mc = 0;
	if (selm) {
		mc = eval(f['mc'].value);
		diffQ++;
	}
	var cc = 0;
	if (selc) {
		cc = eval(f['cc'].value);
		diffQ++;
	}
	var dc = 0;
	if (seld) {
		dc = eval(f['dc'].value);
		diffQ++;
	}
	// Calcolo della quantità totale di metallo tenendo presente possibili quantità già impostate
	for (i=1;i<f['use'].length;i++) {
		if (i==1) slotName="mc";
		else if (i==2) slotName="cc";
		else slotName="dc";
		diffVal = eval(f[slotName].value);
		//if (!f['use'][i].checked && diffVal>0) totValue-=diffVal*(molt[i-1]);
		if (diffVal>0) totValue-=diffVal*(molt[i-1]);
	}
	// Quantità di metallo da suddividere per ogni slot selezionato
	var qForSlot = totValue/diffQ;
	// Imposto le quantità convertite nelle aree selezionate
	if (selm) f['mc'].value = formatDottedStr(parseInt(eval(f['mc'].value) + qForSlot/molt[0]));
	if (selc) f['cc'].value = formatDottedStr(parseInt(eval(f['cc'].value) + qForSlot/molt[1]));
	if (seld) f['dc'].value = formatDottedStr(parseInt(eval(f['dc'].value) + qForSlot/molt[2]));
	doUnselectAll();
	setTargetValuesEncubranceSpace();
}

function checkValues() {
	// Controlli numerici
	var lmval, lcval, ldval, lmp, lcp, ldp, lmc, lcc, ldc;
	lmval = f['mval'].value; lcval = f['cval'].value; ldval = f['dval'].value;
	lmp = unDot(f['mp'].value); lcp = unDot(f['cp'].value); ldp = unDot(f['dp'].value);
	lmc = unDot(f['mc'].value); lcc = unDot(f['cc'].value); ldc = unDot(f['dc'].value);
	if (isNaN(lmval) || isNaN(lcval) || isNaN(ldval)) {
		alert("I rapporti tra le risorse devono essere espressi numericamente.");
		return false;
	}
	if (isNaN(lmp) || isNaN(lcp) || isNaN(ldp)) {
		alert(unDot("1.000.000.000"))
		alert("Le quantità di risorse da convertire devono essere espresse in numeri.");
		return false;
	}
	// Controllo i rapporti di conversione m > c > d
	if (eval(lmval)<eval(lcval)) {
		alert("Il valore del cristallo non può essere inferiore a quello del metallo.");
		return false;
	}
	if (eval(lcval)<eval(ldval)) {
		alert("Il valore del deuterio non può essere inferiore a quello del cristallo.");
		return false;
	}
	// Controllo se le quantità sono già convertite
	if (conversion(lmp,lcp,ldp,lmval,lcval,ldval)-conversion(lmc,lcc,ldc,lmval,lcval,ldval)<=1) {
		//alert("La conversione è già stata effettuata.\nLe quantità convertite equivalgono già quelle da convertire.");
		//return false;
	}
	if (conversion(lmp, lcp, ldp, lmval, lcval, ldval) < conversion(lmc, lcc, ldc, lmval, lcval, ldval)) {
		alert("Le quantità già convertite inserite sono maggiori di quelle di partenza.");
		return false;
	}
	// Controllo la selezione dei checkbox
	if (!f['use'][1].checked && !f['use'][2].checked && !f['use'][3].checked) {
		alert("Spuntare almeno una risorsa in cui convertire.");
		return false;
	}
	return true;
}

function doSelectAll() {
	for (i=0;i<f['use'].length;i++) f['use'][i].checked=true;
}

function doUnselectAll() {
	for (i=0;i<f['use'].length;i++) f['use'][i].checked=false;
}

function ChangeAll() {
	isMasterChecked = f['use'][0].checked;
	checkSit = 0; // 0 nessuno, 1 alcuni, 2 tutti
	checkcount=0;
	for (i=1;i<f['use'].length;i++)
		if (f['use'][i].checked) checkcount++;
	if (checkcount>0 && checkcount<f['use'].length-1) checkSit = 1;
	else if (checkcount>0 && checkcount==f['use'].length-1) checkSit = 2;
	
	if (!isMasterChecked && (checkSit==1 || checkSit==2)) doUnselectAll();
	else if (isMasterChecked && (checkSit==0 || checkSit==1)) doSelectAll();
}

function setModified(id) {
	if (id=='m' && f['mc']>0) mModified = true;
	else if (id=='c' && f['cc']>0) cModified = true;
	else if (id=='d' && f['dc']>0) dModified = true;
}

function resetAll() {
	mModified = false;
	cModified = false;
	dModified = false;
	return true;
}

/*
	Effettua la conversione delle quantità dei materiali inseriti.
	m - Quantità di metallo base.
	c - Quantità di cristallo base.
	d - Quantità di deuterio base.
	valM - Valore del metallo in rapporto (M:c:d).
	valC - Valore del cristallo in rapporto (m:C:d).
	valD - Valore del deuterio in rapporto (m:c:D).
*/
function conversion(m,c,d,valM,valC,valD) {
	m = eval(m);c = eval(c);d = eval(d);valM = eval(valM);valC = eval(valC);valD = eval(valD)
	return parseInt(m+c*(valM/valC)+d*(valM/valD));
}

/*
	Set an advanced tooltip to "element", with a title and a message.
*/
function setToolTip(element,title,message) {
	element.setAttribute("title",TOOLTIP_BASE.replace("$1",title).replace("$2",message));
	element.hasbox = null;
}

function setStartValuesEncubranceSpace() {
	var lmp = eval(unDot(f.mp.value)); var lcp = eval(unDot(f.cp.value)); var ldp = eval(unDot(f.dp.value)); 
	startValForLightCargo = (lmp+lcp+ldp)/5000;
	startValForHeavyCargo = (lmp+lcp+ldp)/25000;

	// Miglior trasporto
	startValForBestCargoOrig = (lmp+lcp+ldp);
	startValForBestCargo1 = parseInt(startValForBestCargoOrig/25000);
	leftCargo = startValForBestCargoOrig % 25000;
	startValForBestCargo2 = leftCargo/5000;

	// Controllo numeri reali
	if (startValForLightCargo!=parseInt(startValForLightCargo)) startValForLightCargo = parseInt(startValForLightCargo)+1;
	if (startValForHeavyCargo!=parseInt(startValForHeavyCargo)) startValForHeavyCargo = parseInt(startValForHeavyCargo)+1;
	if (startValForBestCargo2!=parseInt(startValForBestCargo2)) startValForBestCargo2 = parseInt(startValForBestCargo2)+1;

	setToolTip(document.getElementById("pimg"),"Trasporti necessari","Al trasporto di queste risorse serviranno:<br/>$1 Carghi leggeri<br/>oppure<br/>$2 Carghi pesanti<br/>al meglio<br/>$3 Carghi pesanti e $4 leggeri".replace("$1",startValForLightCargo).replace("$2",startValForHeavyCargo).replace("$3",startValForBestCargo1).replace("$4",startValForBestCargo2));
}
function setTargetValuesEncubranceSpace() {
	var lmc = eval(unDot(f.mc.value)); var lcc = eval(unDot(f.cc.value)); var ldc = eval(unDot(f.dc.value)); 
	endValForLightCargo = (lmc+lcc+ldc)/5000;
	endValForHeavyCargo = (lmc+lcc+ldc)/25000;

	// Miglior trasporto
	endValForBestCargoOrig = (lmc+lcc+ldc);
	endValForBestCargo1 = parseInt(endValForBestCargoOrig/25000);
	leftCargo = endValForBestCargoOrig % 25000;
	endValForBestCargo2 = leftCargo/5000;

	// Controllo numeri reali
	if (endValForLightCargo!=parseInt(endValForLightCargo)) endValForLightCargo = parseInt(endValForLightCargo)+1;
	if (endValForHeavyCargo!=parseInt(endValForHeavyCargo)) endValForHeavyCargo = parseInt(endValForHeavyCargo)+1;
	if (endValForBestCargo2!=parseInt(endValForBestCargo2)) endValForBestCargo2 = parseInt(endValForBestCargo2)+1;

	setToolTip(document.getElementById("aimg"),"Trasporti necessari","Al trasporto di queste risorse serviranno:<br/>$1 Carghi leggeri<br/>oppure<br/>$2 Carghi pesanti<br/>al meglio<br/>$3 Carghi pesanti e $4 leggeri".replace("$1",endValForLightCargo).replace("$2",endValForHeavyCargo).replace("$3",endValForBestCargo1).replace("$4",endValForBestCargo2));
}

function checkRateLimits(type) {
	if (!minmaxCheck) return;
	limitErr = false;
	limitErrMessage = "";

		// mc
		if (f['mval'].value/f['cval'].value>mcMinRate || f['mval'].value/f['cval'].value<mcMaxRate) {
			f['mval'].style.backgroundColor = ERROR_FIELD_COLOR;
			f['cval'].style.backgroundColor = ERROR_FIELD_COLOR;
			limitErr = true;
			if (limitErrMessage=="") {
				limitErrMessage = LIMIT_ERR_MESSAGE_BASE.replace("$1","Metallo-Cristallo").replace("$2",f['mval'].value/f['cval'].value).replace("$3",mcMaxRate).replace("$4",mcMinRate);
				document.getElementById("rapp-help-img").src = "images/error_icon.gif";
				setToolTip(document.getElementById("rapp-help-img"),"Violazione dei limiti impostati",limitErrMessage);
			}
		}
		// md
		else if (f['mval'].value/f['dval'].value>mdMinRate || f['mval'].value/f['dval'].value<mdMaxRate) {
			f['mval'].style.backgroundColor = ERROR_FIELD_COLOR;
			f['dval'].style.backgroundColor = ERROR_FIELD_COLOR;
			limitErr = true;
			if (limitErrMessage=="") {
				limitErrMessage = LIMIT_ERR_MESSAGE_BASE.replace("$1","Metallo-Deuterio").replace("$2",f['mval'].value/f['dval'].value).replace("$3",mdMaxRate).replace("$4",mdMinRate);
				document.getElementById("rapp-help-img").src = "images/error_icon.gif";
				setToolTip(document.getElementById("rapp-help-img"),"Violazione dei limiti impostati",limitErrMessage);
			}
		}
		else f['mval'].style.backgroundColor = "";

		// cm
		if (f['mval'].value/f['cval'].value>mcMinRate || f['mval'].value/f['cval'].value<mcMaxRate) {
			f['mval'].style.backgroundColor = ERROR_FIELD_COLOR;
			f['cval'].style.backgroundColor = ERROR_FIELD_COLOR;
			limitErr = true;
			if (limitErrMessage=="") {
				limitErrMessage = LIMIT_ERR_MESSAGE_BASE.replace("$1","Metallo-Cristallo").replace("$2",f['mval'].value/f['cval'].value).replace("$3",mcMaxRate).replace("$4",mcMinRate);
				document.getElementById("rapp-help-img").src = "images/error_icon.gif";
				setToolTip(document.getElementById("rapp-help-img"),"Violazione dei limiti impostati",limitErrMessage);
			}
		}
		// cd
		else if (f['cval'].value/f['dval'].value>cdMinRate || f['cval'].value/f['dval'].value<cdMaxRate) {
			f['cval'].style.backgroundColor = ERROR_FIELD_COLOR;
			f['dval'].style.backgroundColor = ERROR_FIELD_COLOR;
			if (limitErrMessage=="") {
				limitErrMessage = LIMIT_ERR_MESSAGE_BASE.replace("$1","Cristallo-Deuterio").replace("$2",f['cval'].value/f['dval'].value).replace("$3",cdMaxRate).replace("$4",cdMinRate);
				document.getElementById("rapp-help-img").src = "images/error_icon.gif";
				setToolTip(document.getElementById("rapp-help-img"),"Violazione dei limiti impostati",limitErrMessage);
			}
		}
		else f['cval'].style.backgroundColor = "";

		// dm
		if (f['mval'].value/f['dval'].value>mdMinRate || f['mval'].value/f['dval'].value<mdMaxRate) {
			f['dval'].style.backgroundColor = ERROR_FIELD_COLOR;
			f['mval'].style.backgroundColor = ERROR_FIELD_COLOR;
			if (limitErrMessage=="") {
				limitErrMessage = LIMIT_ERR_MESSAGE_BASE.replace("$1","Metallo-Deuterio").replace("$2",f['mval'].value/f['dval'].value).replace("$3",mdMaxRate).replace("$4",mdMinRate);
				document.getElementById("rapp-help-img").src = "images/error_icon.gif";
				setToolTip(document.getElementById("rapp-help-img"),"Violazione dei limiti impostati",limitErrMessage);
			}
		}
		// dc
		else if (f['cval'].value/f['dval'].value>cdMinRate || f['cval'].value/f['dval'].value<cdMaxRate) {
			f['dval'].style.backgroundColor = ERROR_FIELD_COLOR;
			f['cval'].style.backgroundColor = ERROR_FIELD_COLOR;
			if (limitErrMessage=="") {
				limitErrMessage = LIMIT_ERR_MESSAGE_BASE.replace("$1","Cristallo-Deuterio").replace("$2",f['cval'].value/f['dval'].value).replace("$3",cdMaxRate).replace("$4",cdMinRate);
				document.getElementById("rapp-help-img").src = "images/error_icon.gif";
				setToolTip(document.getElementById("rapp-help-img"),"Violazione dei limiti impostati",limitErrMessage);
			}
		}
		else f['dval'].style.backgroundColor = "";

		// no errors?
		if (!limitErr) {
			// Show image for info about XML loaded
			iminfo = document.getElementById("rapp-help-img");
			setToolTip(iminfo,"Tabella rapporti caricata",TABLE_RAPP.replace("$1",mcBaseRate.toFixed(2)).replace("$2",mcMinRate.toFixed(2)).replace("$3",mcMaxRate.toFixed(2)).replace("$4",mdBaseRate.toFixed(2)).replace("$5",mdMinRate.toFixed(2)).replace("$6",mdMaxRate.toFixed(2)).replace("$7",cdBaseRate.toFixed(2)).replace("$8",cdMinRate.toFixed(2)).replace("$9",cdMaxRate.toFixed(2)));
			iminfo.src = "images/info.gif";
		}
}

/*
	Visualizza il pannello delle opzioni
*/
function trigOptionsPanel(opt) {
	if (!opt || opt==0) {
		optPanel1.style.display='none';
		optPanel2.style.display='none';
		body.style.display='block';
	}
	else if (opt==1) {
		optPanel1.style.marginTop = body.style.marginTop;
		optPanel1.style.marginLeft = body.style.marginLeft;
		body.style.display='none';
		optPanel2.style.display='none';
		initOptionsPane();
		optPanel1.style.display='block';
	}
	else if (opt==2) {
		optPanel2.style.marginTop = body.style.marginTop;
		optPanel2.style.marginLeft = body.style.marginLeft;
		optPanel1.style.display='none';
		optPanel2.style.display='block';
	}
}

function initOptionsPane() {
	setToolTip(document.getElementById('log-help-img'),"Log delle operazioni",logStore.replace("\n","<br/>"));
	optText = document.getElementById("opt-text");
	optText.innerHTML = "";
	if (getQueryStringParam("options")!=null) {
		optText.innerHTML += "Data del file "+opt.fileDate+"<br/>";
		if (opt.creator && opt.mail)
			optText.innerHTML += "Creato da <a href=\"mailto:"+opt.mail+"\">"+opt.creator+"</a><br/>";
		else if (opt.creator)
			optText.innerHTML += "Creato da "+opt.creator+"<br/>";
		if (opt.comment) optText.innerHTML += "<a title=\"title=cssbody=[tooltipbody] cssheader=[tooltipheader] header=[Commento dell'autore] body=["+opt.comment+"] offsety=[-30]\">Note</a><br/>";
		if (opt.www) optText.innerHTML += "<a href=\""+opt.www+"\">URL di riferimento</a><br/>";

		if (opt.cssBase) optText.innerHTML += "Nuovo CSS principale presente<br/>";
		if (opt.cssIE) optText.innerHTML += "Nuovo CSS per Internet Explorer presente<br/>";
		if (opt.cssToolTips) optText.innerHTML += "Nuovo CSS per tooltips presente<br/>";
		if (opt.cssCustom) optText.innerHTML += "CSS personlizzato specificato<br/>";

		if (opt.UseComm) optText.innerHTML += "XML esterno per le regole commerciali<br/>";
	}
	else {
		optText.innerHTML = "Non è stato caricato nessun file di configurazione esterno.";
	}

	optText = document.getElementById("comm-text");
	optText.innerHTML = "";
	if (minmaxCheck) {
		optText.innerHTML += "Data del file "+comm.fileDate+"<br/>";
		optText.innerHTML += "Data delle regole "+comm.ruleDate+"<br/>";

		if (comm.creator && comm.mail)
			optText.innerHTML += "Creato da <a href=\"mailto:"+comm.mail+"\">"+comm.creator+"</a><br/>";
		else if (comm.creator)
			optText.innerHTML += "Creato da "+comm.creator+"<br/>";
		if (comm.comment) optText.innerHTML += "<a title=\"title=cssbody=[tooltipbody] cssheader=[tooltipheader] header=[Commento dell'autore] body=["+comm.comment+"] offsety=[-30] fade=[on] fadespeed=[0.08]\">Note</a><br/>";

	}
	else {
		optText.innerHTML = "Non è stato caricato nessun sorgente XML con le regole commerciali.<br/>"+
									"OGCH sta usando le impostazioni di default ma il controllo sui tassi di scambio viene disabilitato.";
	}
}

/*
	Moltiplica il campo per 1000
*/
function mulK(id) {
	var field = $(id);
	var val = eval(unDot(field.value));
	if (val*1000<=MAX_QUANTITY)
		field.value = eval(unDot(field.value))*1000;
		formatDotted(field);
}

/*
	Reset del form
*/
function resetForm() {
	f['mval'].value = mStartVal;
	f['cval'].value = cStartVal;
	f['dval'].value = dStartVal;
	f['mval'].style.backgroundColor = "";
	f['cval'].style.backgroundColor = "";
	f['dval'].style.backgroundColor = "";
	f['mp'].value = 0;
	f['mc'].value = 0;
	f['cp'].value = 0;
	f['cc'].value = 0;
	f['dp'].value = 0;
	f['dc'].value = 0;
}

/*
	Log delle operazioni
*/
function log(st) {
	logStore = logStore + st + "\n";
}