﻿//////////////////////////////////////////////////////////////////////////
//TIME
//////////////////////////////////////////////////////////////////////////
var g_StartDate;
var g_CurrentDate;
var g_TimerArray = new Array;
var g_TimerId = 0;
//////////////////////////////////////////////////////////////////////////
//CLASS CTimer
//////////////////////////////////////////////////////////////////////////
function CTimer()
{
    this.m_NumberRepeate = 1;
    this.m_RepeateCount = 0;
    this.m_Interval=0;
    this.m_StartTime = new Date();
    this.m_TimerId = g_TimerId;
    g_TimerId++;
    
    var time= new Date();
    hours= time.getHours();
    mins= time.getMinutes();
    secs= time.getSeconds();
    
    etime=hours*3600+mins*60+secs;
    
    this.m_NextOnTime = etime;
    this.m_Interval = 2; 
    this.m_NextOnTime += this.m_Interval; 
}
//////////////////////////////////////////////////////////////////////////
CTimer.prototype.OnTime = function() 
{
    this.m_RepeateCount++;
    if( this.m_RepeateCount < this.m_NumberRepeate )
    {
        this.m_NextOnTime += this.m_Interval; 
    }
    AddWindow('http://dev.utopiapolis.eu/index.php?PAGE=3&RENDER_MODE=WINDOW');
}
//////////////////////////////////////////////////////////////////////////
CTimer.prototype.TestTimer = function( TestTime ) 
{
    if( this.m_RepeateCount < this.m_NumberRepeate )
    {
        if( TestTime >= this.m_NextOnTime )
        {
            this.OnTime();
        }
    }
}
//////////////////////////////////////////////////////////////////////////
CTimer.prototype.GetDebugInfo = function( ) 
{
    debug_info='<div class="DebugConsol_Sucess">';
    debug_info+='<ul class="DebugConsol_Message">';
    debug_info+='<li>Timer Id:'+this.m_TimerId+'</li>';
    debug_info+='<li>Start time:'+this.m_StartTime+' Interval:'+this.m_Interval+' Next occurence:'+this.m_NextOnTime+'</li>';
    debug_info+='<li>Number repeat:'+this.m_NumberRepeate+' Actual reapeat coun:'+this.m_RepeateCount+'</li>';
    debug_info+='</ul>';
    debug_info+='</div>';
    return debug_info;
}



//////////////////////////////////////////////////////////////////////////
function display()
{
    rtime=etime-ctime;
    if (rtime>60)
    {
        m=parseInt(rtime/60);
    }
    else
    {
        m=0;
    }
    s=parseInt(rtime-m*60);
    if(s<10)
    {
        s="0"+s;
    }

    window.status+="Time Remaining :  "+m+":"+s;
    
}

//////////////////////////////////////////////////////////////////////////
function InitTime()
{
    g_StartDate = new Date();
    //g_TimerArray.push( new CTimer() ); 
    
    var time= new Date();
    hours= time.getHours();
    mins= time.getMinutes();
    secs= time.getSeconds();
    
    etime=hours*3600+mins*60+secs;
    etime+=30;  //You can change the value of 1200 according to how much time you wish to set the timer. Where 1200 is time in secs (1200 = 20 mins * 60 secs/min). Max time is 60 mins (3600secs)
    
    Update();
}
//////////////////////////////////////////////////////////////////////////
function Update()
{
    var time= new Date();
    g_CurrentDate = new Date();
    hours= time.getHours();
    mins= time.getMinutes();
    secs= time.getSeconds();
    current_time=hours*3600+mins*60+secs
    
    for( var index = 0; index < g_TimerArray.length ; index++ )
    {
        g_TimerArray[ index ].TestTimer( current_time );
    }

    document.getElementById('Debug_Consol_Message_Count_Time').innerHTML=g_TimerArray.length;
    document.getElementById('DEBUG_TIME_INFO').innerHTML="";
    document.getElementById('DEBUG_TIME_INFO').innerHTML+="Start time :"+g_StartDate.toLocaleString()+"<br/>";
    document.getElementById('DEBUG_TIME_INFO').innerHTML+="Current time :"+g_CurrentDate.toLocaleString()+"<br/>";
    document.getElementById('DEBUG_TIME_INFO').innerHTML+="Timer list:<br/>";

    for( var index = 0; index < g_TimerArray.length ; index++ )
    {
        document.getElementById('DEBUG_TIME_INFO').innerHTML+=g_TimerArray[ index ].GetDebugInfo();
    }

    //display();
    
    window.setTimeout("Update()",1000);
}
//////////////////////////////////////////////////////////////////////////
//DEBUG
//////////////////////////////////////////////////////////////////////////
function Debug_CloseConsol()
{
    document.getElementById("DebugConsol").style.visibility = "hidden";
}
//////////////////////////////////////////////////////////////////////////
function Debug_ShowConsol()
{
    document.getElementById("DebugConsol").style.visibility = "visible";
}
//////////////////////////////////////////////////////////////////////////
function Debug_Consol_Select(Selected)
{
    document.getElementById("DebugConsol_Content_All_Messages").style.display = "none";
    document.getElementById("DebugConsol_Content_Warning_Messages").style.display = "none";
    document.getElementById("DebugConsol_Content_Error_Messages").style.display = "none";
    document.getElementById("DebugConsol_Content_Session_Messages").style.display = "none";
    document.getElementById("DebugConsol_Content_DataBase_Messages").style.display = "none";
    document.getElementById("DebugConsol_Content_Media_Messages").style.display = "none";
    document.getElementById("DebugConsol_Content_Mouse_Messages").style.display = "none";
    document.getElementById("DebugConsol_Content_Time_Messages").style.display = "none";
    document.getElementById("DebugConsol_Content_" + Selected + "_Messages").style.display = "block";
    
    document.getElementById("DebugConsol_Menu_All").style.background = "#DDE";
    document.getElementById("DebugConsol_Menu_Warning").style.background = "#DDE";
    document.getElementById("DebugConsol_Menu_Error").style.background = "#DDE";
    document.getElementById("DebugConsol_Menu_Session").style.background = "#DDE";
    document.getElementById("DebugConsol_Menu_DataBase").style.background = "#DDE";
    document.getElementById("DebugConsol_Menu_Media").style.background = "#DDE";
    document.getElementById("DebugConsol_Menu_Mouse").style.background = "#DDE";
    document.getElementById("DebugConsol_Menu_Time").style.background = "#DDE";
    
    document.getElementById("DebugConsol_Menu_All").style.borderBottom = "none";
    document.getElementById("DebugConsol_Menu_Warning").style.borderBottom = "none";
    document.getElementById("DebugConsol_Menu_Error").style.borderBottom = "none";
    document.getElementById("DebugConsol_Menu_Session").style.borderBottom = "none";
    document.getElementById("DebugConsol_Menu_DataBase").style.borderBottom = "none";
    document.getElementById("DebugConsol_Menu_Media").style.borderBottom = "none";
    document.getElementById("DebugConsol_Menu_Mouse").style.borderBottom = "none";
    document.getElementById("DebugConsol_Menu_Time").style.borderBottom = "none";
    
    document.getElementById("DebugConsol_Menu_"+Selected).style.background = "white";
    document.getElementById("DebugConsol_Menu_"+Selected).style.borderBottom = "1px solid white";
}
//////////////////////////////////////////////////////////////////////////
//VAR 
//////////////////////////////////////////////////////////////////////////
var g_IdWindow = 0;
var g_ZIndex = 1000;
var g_DragMouseClickPositionX=0;
var g_DragMouseClickPositionY=0;

var g_IsDragObject=false;
var g_IdDragObject="";

var g_MouseMoveFunctionArray = new Array;
var g_MouseUpFunctionArray = new Array;
var g_MouseDownFunctionArray = new Array;

var g_MouseInformation = new CMouseInformation();
//////////////////////////////////////////////////////////////////////////
//FUNCTION AFFECTATION 
//////////////////////////////////////////////////////////////////////////
document.onload = InitJavascriptHandler;
document.onmousemove = OnMouseMoveHandler;
document.onmousedown = OnMouseDownHandler;
document.onmouseup = OnMouseUpHandler;
//////////////////////////////////////////////////////////////////////////
//HANDLER
//////////////////////////////////////////////////////////////////////////
function InitJavascriptHandler()
{
    //alert('Init javascript');
    InitTime();
    AddMouseMoveFunction( TraceStatusBar );
    g_DragMouseClickPositionX = 0;
    g_DragMouseClickPositionY = 0;
    
}
//////////////////////////////////////////////////////////////////////////
function OnMouseDownHandler( e )
{
    g_MouseInformation.MouseDown( e );
    g_MouseInformation.UpdateDebugInfo();
}
//////////////////////////////////////////////////////////////////////////
function OnMouseUpHandler( e )
{
    g_MouseInformation.MouseUp( e );
    g_MouseInformation.UpdateDebugInfo();
    g_IsDragObject = false;
    resise_win =false;
}
//////////////////////////////////////////////////////////////////////////
function OnMouseMoveHandler( e )
{
    g_MouseInformation.UpdatePosition( e );
    //g_MouseInformation.UpdateDebugInfo();
    for( index = 0 ; index < g_MouseMoveFunctionArray.length ; index++ )
    {
        g_MouseMoveFunctionArray[ index ]();
    }
    
    if( g_IsDragObject )
    {
        MoveObjectTo( g_IdDragObject ,
         g_MouseInformation.GetMousePosition().GetX() - g_DragMouseClickPositionX ,
         g_MouseInformation.GetMousePosition().GetY() - g_DragMouseClickPositionY);
    }
    
    if( resise_win )
    {
        ResizeWindow ( cur_id_win );
    }

}
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//COMMON
//////////////////////////////////////////////////////////////////////////
function RemovePxFromStyle( string_px)
{
    var no_px = String( string_px );
    no_px = no_px.replace(/px,*\)*/g,"");
    return no_px; 
}
//////////////////////////////////////////////////////////////////////////
function SetTextStatusBar( Text )
{
    window.status = Text;
}
//////////////////////////////////////////////////////////////////////////
function GetTextStatusBar( )
{
    return window.status;
}
//////////////////////////////////////////////////////////////////////////
function AddMouseMoveFunction( Function )
{
    g_MouseMoveFunctionArray.push( Function );
}
//////////////////////////////////////////////////////////////////////////
function StopDragObject( IdObject )
{
    g_IdDragObject = "";
    g_IsDragObject = false;
    g_DragMouseClickPositionX = 0;
    g_DragMouseClickPositionY = 0;
}
//////////////////////////////////////////////////////////////////////////
function StartDragObject( IdObject )
{
    g_IdDragObject = IdObject;
    g_IsDragObject = true;
    
    var object_left = String(IdObject.style.left);
    object_left = object_left.replace(/px,*\)*/g,"");
   
    var object_top = String(IdObject.style.top);
    object_top = object_top.replace(/px,*\)*/g,"");
    
    g_DragMouseClickPositionX = g_MouseInformation.GetMousePosition().GetX() - object_left;
    g_DragMouseClickPositionY = g_MouseInformation.GetMousePosition().GetY() - object_top;

}
//////////////////////////////////////////////////////////////////////////
function MoveObjectTo( IdObject , PositionX , PositionY )
{
    IdObject.style.top = PositionY+'px';
    IdObject.style.left = PositionX+'px';
    IdObject.style.position="absolute";
    SetTextStatusBar( "Move Object to X:"+PositionX + "Y:" + PositionY+" ->>"+g_DragMouseClickPositionX+":"+g_DragMouseClickPositionY );
}
//////////////////////////////////////////////////////////////////////////
function TraceStatusBar()
{
    SetTextStatusBar( g_MouseInformation.GetMousePosition().GetX() + ":" + g_MouseInformation.GetMousePosition().GetY()+" ->>"+g_MouseMoveFunctionArray.length );
}
//////////////////////////////////////////////////////////////////////////
//CLASS CVector2D
//////////////////////////////////////////////////////////////////////////
function CVector2D()
{
    this.m_X=0;
    this.m_Y=0;
}
//////////////////////////////////////////////////////////////////////////
CVector2D.prototype.GetX = function() 
{
    return this.m_X;
}
//////////////////////////////////////////////////////////////////////////
CVector2D.prototype.GetY = function()
{
    return this.m_Y;
}
//////////////////////////////////////////////////////////////////////////
function AddVector( VectorA , VectorB )
{
    var return_vector = new CVector2D();
    return_vector.m_X = VectorA.m_X + VectorB.m_X;
    return_vector.m_Y = VectorA.m_Y + VectorB.m_Y;
    return return_vector;
}
//////////////////////////////////////////////////////////////////////////
//CLASS CMouseInformation
//////////////////////////////////////////////////////////////////////////
function CMouseInformation()
{
    this.m_Position = new CVector2D();
    this.m_LeftClickPosition = new CVector2D();
    this.m_RightClickPosition = new CVector2D();
    this.m_MiddleClickPosition = new CVector2D();
    this.m_LeftButtonState=false;
    this.m_RighButtonState=false;
    this.m_MiddleButtonState=false;
    
}
//////////////////////////////////////////////////////////////////////////
CMouseInformation.prototype.UpdateDebugInfo = function ( )
{
    document.getElementById('DEBUG_MOUSE_INFO').innerHTML="";
    document.getElementById('DEBUG_MOUSE_INFO').innerHTML+="Position X:"+this.m_Position.m_X+" Y:"+this.m_Position.m_Y+"<br>";
    document.getElementById('DEBUG_MOUSE_INFO').innerHTML+="Left click position X:"+this.m_LeftClickPosition.m_X+" Y:"+this.m_LeftClickPosition.m_Y+"<br>";
    document.getElementById('DEBUG_MOUSE_INFO').innerHTML+="Right click position X:"+this.m_RightClickPosition.m_X+" Y:"+this.m_RightClickPosition.m_Y+"<br>";
    document.getElementById('DEBUG_MOUSE_INFO').innerHTML+="Middle click position X:"+this.m_MiddleClickPosition.m_X+" Y:"+this.m_MiddleClickPosition.m_Y+"<br>";
    
    if( this.m_LeftButtonState && document.getElementById("DEBUG_MOUSE_INFO_BUTTON_LEFT")!= null)
    {
        document.getElementById("DEBUG_MOUSE_INFO_BUTTON_LEFT").style.visibility = "visible";
    }else
    {
        document.getElementById("DEBUG_MOUSE_INFO_BUTTON_LEFT").style.visibility = "hidden";
    }
    
    if( this.m_MiddleButtonState )
    {
        document.getElementById("DEBUG_MOUSE_INFO_BUTTON_MIDDLE").style.visibility = "visible";
    }else
    {
        document.getElementById("DEBUG_MOUSE_INFO_BUTTON_MIDDLE").style.visibility = "hidden";
    }
    
    if( this.m_RightButtonState )
    {
        document.getElementById("DEBUG_MOUSE_INFO_BUTTON_RIGHT").style.visibility = "visible";
    }else
    {
        document.getElementById("DEBUG_MOUSE_INFO_BUTTON_RIGHT").style.visibility = "hidden";
    }
}


//////////////////////////////////////////////////////////////////////////
CMouseInformation.prototype.GetMousePosition = function ( )
{
    return this.m_Position;
}
//////////////////////////////////////////////////////////////////////////
CMouseInformation.prototype.SetMousePosition = function ( PositionX , PositionY )
{
    this.m_Position.m_X = PositionX;
    this.m_Position.m_Y = PositionY;
}
//////////////////////////////////////////////////////////////////////////
CMouseInformation.prototype.UpdatePosition = function ( e )
{
    this.m_Position.m_X = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
    this.m_Position.m_Y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
}
//////////////////////////////////////////////////////////////////////////
CMouseInformation.prototype.MouseUp = function ( e )
{
    this.UpdatePosition( e );
    if (!e)
    { 
        var e = window.event;
    }

    if (e.which == null)/* IE case */
    {
       
       button_pressed = (e.button < 2) ? "LEFT" :
                 ((e.button == 4) ? "MIDDLE" : "RIGHT");
    }else/* All others */
    {
       
       button_pressed = (e.which < 2) ? "LEFT" :
                 ((e.which == 2) ? "MIDDLE" : "RIGHT");
     }
     
    //alert(button_pressed ); 
    switch( button_pressed )
    {
        case "LEFT":
            this.m_LeftButtonState = false;
            this.m_LeftClickPosition.m_X = this.m_Position.m_X;
            this.m_LeftClickPosition.m_Y = this.m_Position.m_Y;
            break;
        case "MIDDLE":
            this.m_MiddleButtonState = false;
            this.m_MiddleClickPosition.m_X = this.m_Position.m_X;
            this.m_MiddleClickPosition.m_Y = this.m_Position.m_Y;
            break;
        case "RIGHT":
            this.m_RightButtonState = false;
            this.m_RightClickPosition.m_X = this.m_Position.m_X;
            this.m_RightClickPosition.m_Y = this.m_Position.m_Y;
            break;
    }
}
//////////////////////////////////////////////////////////////////////////
CMouseInformation.prototype.MouseDown = function ( e )
{
    this.UpdatePosition( e );
    if (!e)
    { 
        var e = window.event;
    }

    if (e.which == null)/* IE case */
    {
       
       button_pressed = (e.button < 2) ? "LEFT" :
                 ((e.button == 4) ? "MIDDLE" : "RIGHT");
    }else/* All others */
    {
       
       button_pressed = (e.which < 2) ? "LEFT" :
                 ((e.which == 2) ? "MIDDLE" : "RIGHT");
     }
     
    //alert(button_pressed ); 
    switch( button_pressed )
    {
        case "LEFT":
            this.m_LeftButtonState = true;
            this.m_LeftClickPosition.m_X = this.m_Position.m_X;
            this.m_LeftClickPosition.m_Y = this.m_Position.m_Y;
            break;
        case "MIDDLE":
            this.m_MiddleButtonState = true;
            this.m_MiddleClickPosition.m_X = this.m_Position.m_X;
            this.m_MiddleClickPosition.m_Y = this.m_Position.m_Y;
            break;
        case "RIGHT":
            this.m_RightButtonState = true;
            this.m_RightClickPosition.m_X = this.m_Position.m_X;
            this.m_RightClickPosition.m_Y = this.m_Position.m_Y;
            break;
    }
}
//////////////////////////////////////////////////////////////////////////
//WINDOW
//////////////////////////////////////////////////////////////////////////
var cur_x;
var cur_y;
var resise_win;
var cur_id_win;
var g_WindowArray = new Array;
//////////////////////////////////////////////////////////////////////////
//FUNCTION
//////////////////////////////////////////////////////////////////////////
function AddWindow( WindowURL )
{
    g_WindowArray.push( new CWindow( g_IdWindow ) );
    g_ZIndex ++ ;
    document.getElementById("MAIN_FRAME").innerHTML+='<div ID="MAIN_FRAME_WINDOW_'+g_IdWindow+'" style="top:100px;left:100px;position:absolute;">Loading...</div>';
    makeRequest( WindowURL+'&ID_WINDOW='+g_IdWindow,'MAIN_FRAME_WINDOW_'+g_IdWindow,BringNewWindowToTop);
    g_IdWindow ++ ;
}
//////////////////////////////////////////////////////////////////////////
function BringNewWindowToTop()
{
    g_WindowArray[ g_IdWindow - 1 ].BringToTop();
}
//////////////////////////////////////////////////////////////////////////
//CLASS CWindow
//////////////////////////////////////////////////////////////////////////
function CWindow( ID_Window )
{
    this.m_IdWindow = ID_Window;
    this.m_ResizeOrigne = "NONE";
    this.m_OldTheme = "";
}
//////////////////////////////////////////////////////////////////////////
CWindow.prototype.Destroy = function()
{
    document.getElementById( "MAIN_FRAME_WINDOW_"+this.m_IdWindow ).innerHTML='';
}
//////////////////////////////////////////////////////////////////////////
CWindow.prototype.BringToTop = function()
{
    g_ZIndex++;
    document.getElementById( "WINDOW_"+this.m_IdWindow ).style.zIndex = g_ZIndex;
   
    for( var index = 0; index < g_WindowArray.length ; index++ )
    {
    //    alert(g_WindowArray.length +" "+ index +" "+g_WindowArray[index] );
    //    alert("WINDOW_"+g_WindowArray[index]+"_FILTER");
        if( index == this.m_IdWindow )
        {
            document.getElementById( "WINDOW_"+this.m_IdWindow+"_FILTER" ).style.display = "none";
            document.getElementById( "WINDOW_"+this.m_IdWindow+"_GLOW" ).style.display = "block";
           // g_WindowArray[index].Enable();
        }else
        {
            if(document.getElementById( "WINDOW_"+g_WindowArray[index].m_IdWindow))
            {
                document.getElementById( "WINDOW_"+g_WindowArray[index].m_IdWindow+"_FILTER" ).style.display = "block";
                document.getElementById( "WINDOW_"+g_WindowArray[index].m_IdWindow+"_GLOW" ).style.display = "none";
                //g_WindowArray[index].Disable();
            }
        }
    }
}
//////////////////////////////////////////////////////////////////////////
CWindow.prototype.Disable = function( )
{
    this.SetTheme("http://dev.utopiapolis.eu/RESSOURCE/WINDOW/THEME/DISABLE/");
}
//////////////////////////////////////////////////////////////////////////
CWindow.prototype.Enable = function( )
{
    this.SetTheme("http://dev.utopiapolis.eu/RESSOURCE/WINDOW/THEME/YELLOW/");
}
//////////////////////////////////////////////////////////////////////////
CWindow.prototype.SetTheme = function( ThemePath )
{
    document.getElementById( "WINDOW_TOP_CENTER_"+this.m_IdWindow ).style.backgroundImage = "url("+ThemePath+"window_top_middle.png);";
    document.getElementById( "WINDOW_TOP_RIGHT_"+this.m_IdWindow ).style.backgroundImage = "url("+ThemePath+"window_top_right.png);";
    document.getElementById( "WINDOW_TOP_LEFT_"+this.m_IdWindow ).style.backgroundImage = "url("+ThemePath+"window_top_left.png);";
    
    document.getElementById( "WINDOW_MIDDEL_LEFT_"+this.m_IdWindow ).style.backgroundImage = "url("+ThemePath+"window_middel_left.png);";
    document.getElementById( "WINDOW_MIDDEL_RIGHT_"+this.m_IdWindow ).style.backgroundImage = "url("+ThemePath+"window_middel_right.png);";
    
    document.getElementById( "WINDOW_BOTTOM_LEFT_"+this.m_IdWindow ).style.backgroundImage = "url("+ThemePath+"window_bottom_left.png);";
    document.getElementById( "WINDOW_BOTTOM_CENTER_"+this.m_IdWindow ).style.backgroundImage = "url("+ThemePath+"window_bottom_middle.png);";
    document.getElementById( "WINDOW_BOTTOM_RIGHT_"+this.m_IdWindow ).style.backgroundImage = "url("+ThemePath+"window_bottom_right.png);";    
}
//////////////////////////////////////////////////////////////////////////
CWindow.prototype.SetSize = function( Width , Height )
{
    var window_base_height = Height;
    var window_base_width = Width;
    
    if(window_base_height<100)window_base_height = 100;
    if(window_base_width<100)window_base_width = 100;
    
    var window_height = window_base_height - 72;
    var window_width= window_base_width -64 ;
    var window_width2 = window_base_width - 32;
    var window_height2 = window_base_height-52;
    
    document.getElementById( "WINDOW_"+this.m_IdWindow ).style.width = window_base_width+"px";
    document.getElementById( "WINDOW_"+this.m_IdWindow ).style.height = window_base_height+"px";
    
    document.getElementById( "WINDOW_CONTENT_"+this.m_IdWindow ).style.width = window_width2+"px";
    document.getElementById( "WINDOW_CONTENT_"+this.m_IdWindow ).style.height = window_height2+"px";
    
    document.getElementById( "WINDOW_TOP_CENTER_"+this.m_IdWindow ).style.width = window_width+"px";
    document.getElementById( "WINDOW_BOTTOM_CENTER_"+this.m_IdWindow ).style.width = window_width+"px";
    
    document.getElementById( "WINDOW_MIDDEL_LEFT_"+this.m_IdWindow ).style.height = window_height+"px";
    document.getElementById( "WINDOW_MIDDEL_RIGHT_"+this.m_IdWindow ).style.height = window_height+"px";
    
    document.getElementById( "WINDOW_TOP_CENTER_"+this.m_IdWindow+"_GLOW" ).style.width = window_width+"px";
    document.getElementById( "WINDOW_BOTTOM_CENTER_"+this.m_IdWindow+"_GLOW" ).style.width = window_width+"px";
    
    document.getElementById( "WINDOW_MIDDEL_LEFT_"+this.m_IdWindow+"_GLOW" ).style.height = window_height+"px";
    document.getElementById( "WINDOW_MIDDEL_RIGHT_"+this.m_IdWindow+"_GLOW" ).style.height = window_height+"px";
}
//////////////////////////////////////////////////////////////////////////
CWindow.prototype.Center = function ()
{
    window_base_width = RemovePxFromStyle( document.getElementById( "WINDOW_"+this.m_IdWindow ).style.width );
    window_base_height = RemovePxFromStyle( document.getElementById( "WINDOW_"+this.m_IdWindow ).style.height );
    
    

    var larg = (window.innerWidth);
    var haut = (window.innerHeight);

    positionY = ( haut / 2 ) - ( window_base_height );
    positionX = ( larg / 2 ) - ( window_base_width *0.8);
    
    //alert(larg+":"+haut+"\n"+window_base_width+":"+window_base_height+"\n"+positionX+":"+positionY);

    this.SetPosition( positionX , positionY );
}
//////////////////////////////////////////////////////////////////////////
CWindow.prototype.SetPosition = function ( PositionX , PositionY )
{
    document.getElementById( "WINDOW_"+this.m_IdWindow ).style.top = PositionY+'px';
    document.getElementById( "WINDOW_"+this.m_IdWindow ).style.left = PositionX+'px';
}
//////////////////////////////////////////////////////////////////////////
function StartResizeWindow( ID_Window )
{
    cur_x = RemovePxFromStyle( document.getElementById( "WINDOW_"+ID_Window ).style.top );
    cur_y = RemovePxFromStyle( document.getElementById( "WINDOW_"+ID_Window ).style.left );
    resise_win = true;
    cur_id_win = ID_Window;
}
//////////////////////////////////////////////////////////////////////////
function StopResizeWindow( ID_Window )
{
    resise_win = false;
}
//////////////////////////////////////////////////////////////////////////
function ResizeWindow( ID_Window )
{
    var window_base_height = g_MouseInformation.GetMousePosition().GetY() -  cur_y;
    var window_base_width = g_MouseInformation.GetMousePosition().GetX() - cur_x;
    
    g_WindowArray[ ID_Window ].SetSize( window_base_width, window_base_height);
}

//////////////////////////////////////////////////////////////////////////
//TRASH
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////


function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function xy(g_e,v) 
{ 
    return(v?(agent('msie')?event.clientY+document.body.scrollTop:g_e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:g_e.pageX)); 
}

/////////////////////////////////////////////////////////////////////////
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}