if (window.JScriptPage==null)
    JScriptPage=new Object();

JScriptPage.elementsToEventName=new Array();
JScriptPage.elementsToEventInstruction=new Array();
JScriptPage.eventInstructionsToFunctionCaller=new Array();

JScriptPage.attachJSEvent=function(context,element,eventToAttach,instruction,parameter,eventKey)
{
    if (element.eventsAttached==null)
        element.eventsAttached=new Array();
    if (eventKey==null || element.eventsAttached[eventKey]==null)
    {
        if (this.elementsToEventName[element]==null)
            this.elementsToEventName[element]=new Array();
        this.elementsToEventName[element][this.elementsToEventName[element].length]=eventToAttach;
            
        if (this.elementsToEventInstruction[element]==null)
            this.elementsToEventInstruction[element]=new Array();
        
        if (this.elementsToEventInstruction[element][eventToAttach]==null)
            this.elementsToEventInstruction[element][eventToAttach]=new Array()
            
        this.elementsToEventInstruction[element][eventToAttach][this.elementsToEventInstruction[element].length]=instruction;
        
        if (element.attachEvent)
        {
            var functionCaller=function(){instruction.call(context,window.event,parameter)};
            
            if (this.eventInstructionsToFunctionCaller[instruction]==null)
                this.eventInstructionsToFunctionCaller[instruction]=new Array();
                
            this.eventInstructionsToFunctionCaller[instruction][this.eventInstructionsToFunctionCaller.length]=functionCaller;
            
            element.attachEvent(eventToAttach,functionCaller);
        }
        else if (element.addEventListener)
        {
            if (this.eventInstructionsToFunctionCaller[instruction]==null)
                this.eventInstructionsToFunctionCaller[instruction]=new Array();
            this.eventInstructionsToFunctionCaller[instruction][this.eventInstructionsToFunctionCaller.length]=instruction;  
            element.addEventListener(eventToAttach,instruction);
        }
        if (eventKey!=null)
            element.eventsAttached[eventKey]=true;
    }
};
JScriptPage.detachJSEvent=function(element,eventToDetach,instruction)
{
    if (instruction!=null)
    {
        for (var i=0;i<this.eventInstructionsToFunctionCaller[instruction].length;i++)
            element.detachEvent(eventToDetach, this.eventInstructionsToFunctionCaller[instruction][i]);
    }
    else if (this.elementsToEventInstruction[element]!=null && this.elementsToEventInstruction[element][eventToDetach]!=null)
    {
        for (var j=0;j<this.elementsToEventInstruction[element][eventToDetach].length;j++)
            JScriptPage.detachJSEvent(element,eventToDetach,this.elementsToEventInstruction[element][eventToDetach][j]);
    }
    
};
JScriptPage.detachAllJSEvent=function(element)
{
    if (this.elementsToEventName[element]!=null)
        for (var i=0;i<this.elementsToEventName[element].length;i++)
        {
            var eventToDetach=this.elementsToEventName[element][i];
            for (var j=0;j<this.elementsToEventInstruction[element][eventToDetach].length;j++)
                JScriptPage.detachJSEvent(element,eventToDetach,this.elementsToEventInstruction[element][eventToDetach][j]);
        }
};
JScriptPage.textBoxToTextBox=function(textBox1,textBox2)
{
    var f=function(e)
    {
        if (textBox1.value.length==textBox1.maxLength)
        {                    
            textBox2.focus();
        }
    }
    this.attachJSEvent(textBox1,textBox1,'onkeyup',f);
};
JScriptPage.addJSFile=function(path)
{
    var script=document.createElement('script');
    script['type']='text/javascript';
    script.src=path;
    document.getElementsByTagName('head')[0].appendChild(script);
};
JScriptPage.replaceCharBy=function(texto,textToFind,textToReplace)
{
     var res=texto;
    if (textToFind!=textToReplace)
    {
        while (res.indexOf(textToFind)!=-1)
            res=res.replace(textToFind,textToReplace); 
    }
    return res;
};
JScriptPage.centerX=function()
{
    var scrollXT=0;
    var clientWidth=0;
    if (typeof(window.pageYOffset) == 'number') { 
        scrollXT = window.pageXOffset; 
    } 
    else if (document.body && document.documentElement && document.documentElement.scrollTop) { 
        scrollXT = document.body.scrollLeft;
    }
    else if (document.body && typeof(document.body.scrollTop) == 'number') { 
        scrollXT = document.body.scrollLeft; 
    } 
    if (document.body.clientHeight){
        clientWidth=document.body.clientWidth;
    }
    else if (window.innerHeight){
        clientWidth=window.innerWidth;
    }
    return (scrollXT)+clientWidth/2;
}
JScriptPage.centerY=function()
{
    var scrollYT=0;
    var clientHeight=0;
    if (typeof(window.pageYOffset) == 'number') { 
        scrollYT = window.pageYOffset; 
    } 
    else if (document.body && document.documentElement && document.documentElement.scrollTop) { 
        scrollYT = document.documentElement.scrollTop; 
    }
    else if (document.body && typeof(document.body.scrollTop) == 'number') { 
        scrollYT = document.body.scrollTop; 
    } 
    if (document.body.clientHeight){
        clientHeight=document.body.clientHeight;
    }
    else if (window.innerHeight){
        clientHeight=window.innerHeight;
    }
    return (scrollYT)+clientHeight/2;
}
JScriptPage.clientBottom=function()
{
    var scrollYT=0;
    var clientHeight=0;
    if (typeof(window.pageYOffset) == 'number') { 
        scrollYT = window.pageYOffset; 
    } 
    else if (document.body && document.documentElement && document.documentElement.scrollTop) { 
        scrollYT = document.documentElement.scrollTop; 
    }
    else if (document.body && typeof(document.body.scrollTop) == 'number') { 
        scrollYT = document.body.scrollTop; 
    } 
    if (document.body.clientHeight){
        clientHeight=document.body.clientHeight;
    }
    else if (window.innerHeight){
        clientHeight=window.innerHeight;
    }
    return (scrollYT)+clientHeight;
}
JScriptPage.clientRight=function()
{
    var scrollXT=0;
    var clientWidth=0;
    if (typeof(window.pageYOffset) == 'number') { 
        scrollXT = window.pageXOffset; 
    } 
    else if (document.body && document.documentElement && document.documentElement.scrollTop) { 
        scrollXT = document.body.scrollLeft;
    }
    else if (document.body && typeof(document.body.scrollTop) == 'number') { 
        scrollXT = document.body.scrollLeft; 
    } 
    if (document.body.clientHeight){
        clientWidth=document.body.clientWidth;
    }
    else if (window.innerHeight){
        clientWidth=window.innerWidth;
    }
    return (scrollXT)+clientWidth;
}
JScriptPage.clientLeft=function()
{
    var scrollXT=0;
    if (typeof(window.pageYOffset) == 'number') { 
        scrollXT = window.pageXOffset; 
    } 
    else if (document.body && document.documentElement && document.documentElement.scrollTop) { 
        scrollXT = document.body.scrollLeft;
    }
    else if (document.body && typeof(document.body.scrollTop) == 'number') { 
        scrollXT = document.body.scrollLeft; 
    } 
    return (scrollXT);
}
JScriptPage.clientTop=function()
{
    var scrollYT=0;
    if (typeof(window.pageYOffset) == 'number') { 
        scrollYT = window.pageYOffset; 
    } 
    else if (document.body && document.documentElement && document.documentElement.scrollTop) { 
        scrollYT = document.documentElement.scrollTop; 
    }
    else if (document.body && typeof(document.body.scrollTop) == 'number') { 
        scrollYT = document.body.scrollTop; 
    } 
    return (scrollYT);
}
JScriptPage.setMaxHeight=function(control,value)
{
    this.attachJSEvent(this,window,'onload',function(){this.checkMaxHeight(control,value);});
    control.style.height=value+'px';
    control.style.overflowY='auto';
    
    var thisTmp=this;
    var f=function(){
        thisTmp.checkMaxHeight(control,value);
    }
    setTimeout(f,10);
    
}
JScriptPage.checkMaxHeight=function(control,value)
{
    control.style.height=0;
    if (control.offsetHeight>value)
        control.style.height=value; 
}
JScriptPage.getFormatedNumberValue=function(number)
{
    number=this.replaceCharBy(number,this.SepMiles,'');
    number=this.replaceCharBy(number,this.SepDec,'.');
    number=number/1;
    return number;
}