
Number.prototype.isiToLocaleString = function () {
return this.toLocaleString().split(",")[0].split(".")[0];
}

Boolean.prototype.isiToInteger = function (){
return (this==true?1:0);
};
Boolean.prototype.isiToString = function (){
return (this==true?"1":"0");
};

String.prototype.isiToBoolean = function (){
myRE = new RegExp("^(true|1|-1|vrai|oui)$", "i");
return (this.match(myRE)?true:false);
};

function PixToInt(s) {
return parseInt(s);
}

function IntToPix(s) {
return s + "px";
}



function aContainsB ( a, b) {
if (!a) return false;
if (!b) return false;
if (!a.length) return false;

var _finded = false;
var _last = a.length;
var i = 0;
while ( !_finded && i < _last) {
_finded = (a[i++] == b);
}

return _finded;
}


function iwsFifo() {
this._array = new Array();

this.put = function ( v) {
this._array.unshift ( v);
}

this.empty = function () {
return (this._array.length <= 0);
}

this.get = function () {
return this._array.pop();
}
}

function iws_PadLeft( iLen, iValue) {
var sValue = iValue.toString();
var nbZero = iLen-sValue.length;
var sRes="";
for ( var i=0 ; i < nbZero ; ++i) {
sRes += "0";
}

sRes += sValue;

return sRes;
}

function iws_StrReplace(expr,a,b) {
var i=0
while (i!=-1) {
i=expr.indexOf(a,i);
if (i>=0) {
expr=expr.substring(0,i)+b+expr.substring(i+a.length);
i+=b.length;
}
}
return expr
}



function iws_ResizeImg(oImg, iMaxWidth,iMaxHeight){
var iRatioX = 1;
var iRatioY = 1;
var bZoomX = false;
var bZoomY = false;
var iNewWidth;
var iNewHeight;
var iZoomRatio;

if (oImg.width>iMaxWidth){
iRatioX = iMaxWidth/oImg.width;
bZoomX = true;
}
if (oImg.height>iMaxHeight){
bZoomY = true;
iRatioY = iMaxHeight/oImg.height;
}
if (bZoomX || bZoomY){
if (iRatioX<iRatioY){
iNewWidth = iMaxWidth;
iNewHeight = parseInt(iRatioX*oImg.height);
}else{
iNewWidth = parseInt(iRatioY*oImg.width);
iNewHeight = iMaxHeight;
}
oImg.style.width  = iNewWidth + "px";
oImg.style.height = iNewHeight + "px";
}else{
oImg.style.width  = "";
oImg.style.height = "";
}
}


function debugTime(bOn,bReport){
this.iCallOrder = 0;
this.bDebugTime = bOn;
this.bReport    = bReport;
this.timeBegin  = new Object();
this.timeEnd  = new Object();
this.iTimeBegin = null;
this.iTimeEnd   = null;
}
debugTime.prototype = {
Reset : function(){
if (!this.bDebugTime) return;
this.dBegin  = new Date();
this.iCallOrder = 0;
this.timeBegin  = new Object();
this.timeEnd  = new Object();
this.iTimeBegin = this.dBegin.getTime();
},

Begin : function(sFn){
var sClass;
var chrono;
var iTotalTime;
if (!this.bDebugTime) return;
if (sFn.split('.').length>1){
sClass = sFn.split('.')[0];
sFn    = sFn.split('.')[1];
}else{
sClass = "window";
}
if (!this.timeBegin[sClass]){
this.timeBegin[sClass]  = new Object();
this.timeEnd[sClass]    = new Object();
}
if (!this.timeBegin[sClass][sFn]){
this.timeBegin[sClass][sFn] = [];
this.timeEnd[sClass][sFn]   = [];
}
this.iCallOrder++;
chrono = (new Date()).getTime();
this.timeBegin[sClass][sFn].push(chrono);
},

End : function(sFn){

var sClass;
if (!this.bDebugTime) return;
chrono = (new Date()).getTime();

if (sFn.split('.').length>1){
sClass = sFn.split('.')[0];
sFn    = sFn.split('.')[1];
}else{
sClass = "window";
}
try{
this.timeEnd[sClass][sFn].push(chrono);
}catch(e){
window.status=sClass +"."+sFn
}
},

Show : function(){
if (!this.bDebugTime) return;

this.dEnd  = new Date();
this.iTimeEnd = this.dEnd.getTime();
var iTotalTime = this.iTimeEnd - this.iTimeBegin;

if (this.bReport){
var aReport=[];
var sFnReport;
var iFnTime;
var iFnCalls =0;
var iFnTotalLength;
var iTotalCalls;
var iPercentTime =0;

aReport.push("<TABLE border=\"1\">");
aReport.push(" <CAPTION>" + new Date() + "</CAPTION>");
aReport.push(" <TR>");
aReport.push("  <TH>Class</TH>");
aReport.push("  <TH>Function</TH>");
aReport.push("  <TH>Nb Call</TH>");
aReport.push("  <TH>Total Time (ms)</TH>");
aReport.push("  <TH>Duration (ms)</TH>");
aReport.push("  <TH>AVG Time (ms)</TH>");
aReport.push("  <TH>% total time<br>(" + iTotalTime + "ms)<br>"
+ this.dBegin.getMinutes() +":"+ this.dBegin.getSeconds() +":"+ this.dBegin.getMilliseconds() + "<br>"
+ this.dEnd.getMinutes() +":"+ this.dEnd.getSeconds() +":"+ this.dEnd.getMilliseconds() + "<br></TH>")
aReport.push(" </TR>");

for (var sClass in this.timeBegin){


for (var fn in this.timeBegin[sClass]){

iFnTime  = 0;
iFnCalls = this.timeBegin[sClass][fn].length;
iTotalCalls +=iFnCalls;

for (var i=0; i<iFnCalls; i++){
try{
iFnTime = iFnTime + parseInt(this.timeEnd[sClass][fn][i]-this.timeBegin[sClass][fn][i]);
}
catch(e){iFnTime = Number.NaN}
}

iPercentTime = (100*parseFloat(iFnTime/iTotalTime))
iPercentTime = Math.round(100*parseFloat(iPercentTime))/100
aReport.push(" <TR>")
aReport.push("  <TD>" + sClass  + "</TD>");
aReport.push("  <TD>" + fn   + "</TD>");
aReport.push("  <TD>" + iFnCalls+ "</TD>");
aReport.push("  <TD>" + iFnTime + "</TD>");
aReport.push("  <TD>" + iFnTime + "</TD>");
aReport.push("  <TD>" + Math.round(iFnTime/iFnCalls) + "</TD>");
aReport.push("  <TD>" + iPercentTime + "%</TD>");
aReport.push(" </TR>")

}
}
aReport.push("</TABLE>");

if(this.Infos){
try{
this.Infos.close();
}catch(e){}
}
this.Infos = window.open('about:blank', '_blank', 'width=1024,height=800,resizable=1,scrollbars=1');
this.Infos.document.body.innerHTML = aReport.join('\n');
}else{
alert(iTotalTime);
}
}
}


