/******************************************************************************
* odfClientRuntime.js
*******************************************************************************
Runtime client pour les controles
*******************************************************************************
*                                                                             *
* Copyright 2000-2002								                          *
*                                                                             *
******************************************************************************/
function formatCurrency(currency, simple)
{
	var langPrefix = lang.substr(0, 2);
	if(simple != true && langPrefix == "en") simple = true;
	var sign ="";
	if(currency < 0) {
		currency = -currency;
		sign = "-";
	}
	var integer = Math.floor(currency);
	var full = "" + integer;
	// NB : A cause des arrondis, on ne va pas factoriser l'expression mathematique en ecrivant : 100 * (currency - integer). Ex : 8.43
	var decimal = "" + Math.floor((100 * currency) - (100 * integer));	
	if(decimal.length == 1) decimal = "0"+decimal;
	var res = null;
	var pos = full.length;
	while(pos > 3) {
		block = full.substr(pos - 3, 3);
		if(res == null) {
			res = block;
		} else {
			if(simple) {
				res = block+","+res;
			} else {
				res = block+"\240"+res;
			}
		}
		pos -= 3;
	}
	if(pos > 0) {
		block = full.substr(0, pos);
		if(res == null) {
			res = block;
		} else {
			if(simple) {
				res = block+","+res;
			} else {
				res = block+"\240"+res;
			}
		}
	}
	if(simple) {
		res += "."+decimal;
	} else {
		res += ","+decimal;
	}
	return sign+res;
}

function formatTimestamp(timestamp, format)
{
	switch(format) {
	case "hours":
		return objDateUtils.getStringDate(timestamp, "G:i:s");
	case "time":
		return objDateUtils.getStringDate(timestamp, "d/m/Y G:i:s");
	case "date":
	default:
		return objDateUtils.getStringDate(timestamp, "d/m/Y");
	}
}

function showModalWindow(url, name, width, height, arguments)
{
	var leftPos = (screen.availWidth - width) / 2;
	var topPos = (screen.availHeight - height) / 2;
	if(false && document.all) {
		width = parseInt(width, 10);
		height = parseInt(height, 10);
		width += 8;
		height += 29;
		var options = 'resizable=yes;scroll=no;edge=sunken;status=no;dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;dialogLeft=' + leftPos + 'px;dialogTop=' + topPos + "px;";
		//consoleDump("window.showModalDialog(\"" + url + "\", arguments, \"" + options +"\")");
		window.showModalDialog(url, arguments, options);
	} else {
		var options = 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
		var win = window.open(url, name, options);
		if (win==null) {
			alert(objThesaurus.translate("odfCheckPopupBlocker"));
		} else {
			win.focus();
		}
	}
}

function opennewwindow(linkElement, options, target)
{
	var href = linkElement.href;
	if(href == null || href == "") return false;
	var win = window.open(href, target, options);
	return false;
}

function tabClick(a)
{
	var srcLi = a.parentNode;
	var ul = srcLi.parentNode;
	for(var i=0;i < ul.childNodes.length;i++) {
		var li = ul.childNodes.item(i);
		if(li.nodeName != "LI") continue;
		var id = li.id;
		var tabBody = document.getElementById("tab" + id);
		if(li.tagName != "LI" || tabBody == null) {
			alert("no li " + li.tagName + " " + id);
			continue;
		}
		if(li == srcLi) {
			tabBody.className = "tabBodySelected";
			li.className = "tabButtonSelected";
		} else {
			tabBody.className = "tabBody";
			li.className = "tabButton";
		}
	}
	return false;
}
