
// String

String.format = function() {
    if( arguments.length == 0 )
        return null;
    var str = arguments[0];
    for(var i=1;i<arguments.length;i++)
    {
        var re = new RegExp('\\{' + (i-1) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.LTrim = function()
{
    return this.replace(/(^\s*)/g, "");
}

String.prototype.Rtrim = function()
{  
    return this.replace(/(\s*$)/g, "");
}

// Number

Number.prototype.NaN0=function(){return isNaN(this)?0:this;}

// Position

function getPos_insideDiv(objRef,sProp,divName) { // Ex: ( imgobj, 'Left', 'composable_pieces')

	var iPos = 0;

	while (objRef!=null) {

    iPos += objRef["offset" + sProp]; // Ex: [offsetLeft], [offsetTop]
		objRef = objRef.offsetParent;
	}

// xx - returned wrong position onMouseover, so subtract with the div scroll height:
	return iPos - document.getElementById('composable_pieces')["scroll"+sProp];

}


function getPos(objRef,sProp) {

	var iPos = 0;

	while (objRef!=null) {
		iPos+=objRef["offset" + sProp]; // Ex: [offsetLeft], [offsetTop]
		objRef = objRef.offsetParent;
	}
	return iPos;
}


function getPosition(e){
	var left = 0;
	var top  = 0;
	while (e.offsetParent){
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
		e     = e.offsetParent;
	}


	left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
	top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);

	return {x:left, y:top};

}


