/* $Id: general.js,v 1.8 2008/10/24 08:29:52 szymon Exp $ */

/**
 * Console object definition for all the browsers with no firebug plugin
 * @author chris
 */
if(document.all || !console) {
	var console =
	{
		log: function () {},
		debug: function () {},
		info: function () {},
		warn: function () {},
		error: function () {},
		assert: function () {},
		count: function () {},
		time: function () {},
		timeEnd: function () {},
		profile: function () {},
		profileEnd: function () {},
		trace: function () {},
		group: function () {},
		groupEnd: function () {},
		dir: function () {},
		dirxml: function () {}
	};
}

var UNDEF = 'undefined';
var OK = 'ok';
var ERROR = 'error';


var artcom = a =
{

	openPopUp: function(x, y, w, h, name, page) {
		//obejście błędu w IE7 - nie może być spacji w nazwie okna
		if ($.browser.msie)
		{
//			if ($.browser.version==7)
				name = name.replace(/[\s-]/g, "_");
//				name = name.replace(/ /g, "_");
//				name = name.replace(/-/g, "_");
		}

		var options = 'location=no, menubar=no, scrollbars=yes, status=yes, resizable=yes, dependent=yes, width='+ w +', height='+ h +', screenX='+ x+', screenY='+ y +', left='+ x+', top='+ y;
		var winPopUp = window.open( page, name, options);
		if (!winPopUp)
			alert('Okienko pomocnicze nie zostało otwarte z powodu blokady pop-up.')
		else
			winPopUp.focus();
		return winPopUp;
	},

	openPopUpFullLocation: function(x, y, w, h, name, page) {

		winPopUp = window.open(page,name, 'toolbar=yes,location=yes,menubar=no,scrollbars=yes,status=yes,resizable=yes,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
		if(!winPopUp)
			alert('Okienko pomocnicze nie zosta??o otwarte z powodu blokady pop-up.')
		else
			winPopUp.focus();
		return winPopUp;
	},

	openPopUpFull: function(x, y, w, h, name, page) {

		winPopUp = window.open(page,name, 'toolbar=yes,location=no,menubar=no,scrollbars=yes,status=yes,resizable=yes,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
		if(!winPopUp)
			alert('Okienko pomocnicze nie zosta??o otwarte z powodu blokady pop-up.')
		else
			winPopUp.focus();
		return winPopUp;
	},

	openPopUpNoStatus: function(x, y, w, h, name, page) {

		winPopUp = window.open(page,name, 'location=no,menubar=no,scrollbars=yes,status=no,resizable=yes,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
		if(!winPopUp)
			alert('Okienko pomocnicze nie zosta??o otwarte z powodu blokady pop-up.')
		else
			winPopUp.focus();
		return winPopUp;
	},

	openPopUpWithStatus: function(x, y, w, h, name, page) {

		winPopUp = window.open(page,name, 'location=no,menubar=no,scrollbars=no,status=yes,resizable=no,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
		if(!winPopUp)
			alert('Okienko pomocnicze nie zosta??o otwarte z powodu blokady pop-up.')
		else
			winPopUp.focus();
		return winPopUp;
	},

	openPopUpNoBars: function(x, y, w, h, name, page) {

		winPopUp = window.open(page,name, 'location=no,menubar=no,scrollbars=no,status=no,resizable=no,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
		if(!winPopUp)
			alert('Okienko pomocnicze nie zosta??o otwarte z powodu blokady pop-up.')
		else
			winPopUp.focus();
		return winPopUp;
	},


	closePopupRefreshOpener: function(msg) {		// TODO: specyficze (hierarchyList), przełożyć
		if (window.opener) {
	//		window.opener.alert('REFRESH');
			if (window.opener.hierarchyList && window.opener.hierarchyList.active == true) {
				window.opener.hierarchyList.refresh()
			} else
			if (window.opener.lookupList && window.opener.lookupList.active == true) {
				window.opener.lookupList.refresh()
			} else {
				window.opener.location.reload()
			}
		}
		setTimeout('closePopup(\''+ msg +'\')', 200);

	},


	closePopupAndRefresh: function(arrayOfObjects, msg, timeout) {
		if (window.opener) {
			var refreshed = false;
			if(arrayOfObjects) {
				for(i in arrayOfObjects) {
					iObject = arrayOfObjects[i];
					if (window.opener.iObject && window.opener.iObject.active == true) {
						window.opener.iObject.refresh()
						refreshed = true;
					}
				}
			}
			if(!refreshed) {
				window.opener.location.reload()
			}
		}
		if(timeout)
			setTimeout('closePopup(\''+ msg +'\')', timeout);
	},


	closePopup: function(msg) {
		if (msg != '') {
			alert(msg);
		}
		if (window.opener) {
			window.opener.focus();
		}
		window.close();
	},


	showImage: function (width, height, url, time) // Image-show pop-up to be automaticaly resized (sys/image/popup)
	{
		width += 7;
		height += 60;

		url = url.replace(/^\//, '');
		url = url.replace(/\//g, '|');

		winShowImage = this.openPopUpWithStatus(50, 50, width, height, 'showImageWindow', '/?q=sys/image/popup/' + url);
		winShowImage.resizeTo(width, height);
	},




	getInt: function(strVal) {
		strVal = strVal? strVal:'0';
		strVal = strVal.replace(/ /, '');
		strVal = strVal.replace(/,/, '.');
		return Math.round(parseFloat(strVal));
	},

	getFloat: function(strVal) {
		strVal = strVal? strVal:'0.00';
		strVal = strVal.replace(/ /, '');
		strVal = strVal.replace(/,/, '.');

		return Math.round(parseFloat(strVal*100))/100;
	},

	formatInt: function(val) {
		if(isNaN(val)) val = 0;
		return Math.round(val? val:0);
	},

	formatFloat: function(val) {

		if(isNaN(val)) val = 0.00;
		var numVal = Math.round((val? val:0) * 100);
		var strVal = '';

		if(numVal >= 100) strVal = String(Math.round(val * 100));
		else if(numVal >= 10) strVal = '0'+ String(Math.round(val * 100));
		else strVal = '00'+ String(Math.round(val * 100));

		var lastVal = strVal.substr(strVal.length-2, 2);
		var baseVal = strVal.substr(0, strVal.length-2);

		baseArray = [];
		while(baseVal.length > 3) {
 			baseArray[baseArray.length] = baseVal.substring(baseVal.length-3);
 			baseVal = baseVal.substring(0, baseVal.length-3);
		}

		var response = '';
		response += (!baseVal && !baseArrray? '0': baseVal);
		for(i=0; i<baseArray.length; i++) {
			response += (' '+ baseArray[i]);
		}
		response += (','+ lastVal);

		return response;

	}	// formatFloat


}	// artcom, a


ao =
{


	formatCurr: function (val, lang)
	{
		if(!lang) lang = 'pl';
		val = String(Math.round(val*100));

		switch(val.length)
		{
			case 1: val = '00' + val; break;
			case 2: val = '0' + val; break;
		}
		r = val.substring(0,val.length-2) +','+ val.substr(val.length-2);
		if(r.length > 6) {r = r.substring(0,val.length-5) +'.'+ r.substr(val.length-5);}
	//	else
	//		if(r.lenght > 7) {r = r.substring(0,val.length-9) +'.'+ r.substr(val.length-9);}
	//		else {r = r.substring(0,val.length-13) +'.'+ r.substr(val.length-13)}

		return r;
	}

}	// ao



af =
{
	setPanelHeader: function(panelID, htmlData)
	{
		$('#'+ panelID +' div.hd').html(htmlData);
	},
	setPanelBody: function(panelID, htmlData)
	{
		$('#'+ panelID +' div.bd').html(htmlData);
	},
	setPanelProcessBody: function(panelID)
	{
		$('#'+ panelID +' div.bd').html('<div class="loading-message"><span class="loading-normal" >Przetwarzanie danych ...</span></div>');
	},
	setPanelWaitingsBody: function(panelID)
	{
		$('#'+ panelID +' div.bd').html('<div class="loading-message"><span class="loading-normal" >Pobieranie danych ...</span></div>');
	},
	setPanelFooter: function(panelID, htmlData)
	{
		$('#'+ panelID +' div.ft').html(htmlData);
	},
	setPanelMask: function(panelID, opacityValue)
	{
		$('#'+ panelID +'_mask').css({opacity: opacityValue});
	}


} // af







