﻿/*General Behavior of the radWindow*/

function GetRadWindow(){
	var oWindow = null;
	if (window.radWindow) oWindow = window.radWindow;
	else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
	return oWindow;
}

function WindowClose()
{
	var oWindow = GetRadWindow();
	if(oWindow)
		oWindow.close();
}

function WindowAutoResize(){
    var oWindow = GetRadWindow();
	if(oWindow)
	    setTimeout(function(){ oWindow.autoSize(); }, 100); 
}

/*Close on ESC*/
function tryclose(e){

    var key = checkKeyPress(e); 
    if(key == 27){
        WindowClose();
    }
}


/*Close and return the argument in the hidden field hidID*/
function tryclosewarg(sender_aspx, hidID){
    var oWindow = GetRadWindow();
    
    var arg = new Object();  
    
    arg.sender_aspx = sender_aspx; 
    arg.return_msg = document.getElementById(hidID).value;
    
    oWindow.argument = arg; 
    
    if (oWindow)
        oWindow.close();
}



/*Close and return the argument in the hidden field hidID*/
function tryclosewargandevent(e, sender_aspx, hidID){
    var key = checkKeyPress(e); 
    if(key == 27){
        tryclosewarg(sender_aspx, hidID);
    }       
}

/*Adds the argument in the hidden field hidID but doesn't close*/
function addarg(sender_aspx, hidID){
    var oWindow = GetRadWindow();
    
    var arg = new Object();  
    
    arg.sender_aspx = sender_aspx; 
    arg.return_msg = document.getElementById(hidID).value;
    
    oWindow.argument = arg; 
    
}


/*Function that resizes the page once displayed. If a -1 is sent, then only the other dimention is used.*/
function WindowSetResize(width, height){
    var oWindow = GetRadWindow();
    if(oWindow){
        if (width != -1 && height != -1)
            setTimeout(function(){ oWindow.SetSize(width + "px", height + "px"); oWindow.center(); }, 100); 
        else if (width != -1)
            setTimeout(function(){ oWindow.SetSize(width + "px", oWindow.get_height + "px"); oWindow.center(); }, 100); 
        else if (height != -1)
            setTimeout(function(){ oWindow.SetSize(oWindow.get_width + "px", height + "px"); oWindow.center(); }, 100); 
    }
}

/*Increases the size of the window by extra-width and extra-height*/
function WindowIncreaseSize(extrawidth, extraheight){
    var oWindow = GetRadWindow();
    if(oWindow)
        setTimeout(function(){ oWindow.SetSize((oWindow.get_width + extrawidth) + "px", (oWindow.get_height + extraheight) + "px"); oWindow.center(); }, 100); 
}

/*Sets the minimum Width for the window */
function WindowSetMinWidth(width)
{
    var oWindow=GetRadWindow();
    if(oWindow)
    {
        if(width!=-1)
            if(oWindow.get_width<width)
                setTimeout(function(){ oWindow.SetSize(width+"px",oWindow.get_height+"px"); oWindow.center(); }, 100); 
    }
}

/*Sets the minimum Height for the window */
function WindowSetMinHeight(height)
{
    var oWindow=GetRadWindow();
    if(oWindow)
    {
        if(height!=-1)
            if(oWindow.get_height<height)
                setTimeout(function(){ oWindow.SetSize(oWindow.get_width+"px",height+"px"); oWindow.center(); }, 100); 
    }
}
