// General Javascript helper functions for NetCampus
if (typeof (_fileVersions) == 'undefined')
{
	eval('var _fileVersions = new Array()');
}
_fileVersions.push('General 6.6.0.0');

var browserType = new InitBrowser();
var vBrowserObject = new InitBrowser();

function InitBrowser()
{
    var vAgent = navigator.userAgent.toLowerCase();
    this.isIE = ((vAgent.indexOf("msie") != -1) && (document.all));
    this.IsIE = ((vAgent.indexOf("msie") != -1) && (document.all));
    this.IsFF3 = (navigator.appCodeName.toLowerCase() == "mozilla" && vAgent.indexOf("firefox/3.0") != -1);
    this.IsSafari = (navigator.appCodeName.toLowerCase() == "mozilla" && vAgent.indexOf("safari") != -1);
}

window.onunload = UnloadHandler;

function ReloadPage()
{
	window.location = window.location;
}

function AddCleanUpFunction(cleanupFunc)
{
	if (!window.cleanUpFunctions)
	{
		window.cleanUpFunctions = new Array();
	}
		
	window.cleanUpFunctions.push(cleanupFunc);
}

function UnloadHandler()
{
	if (window.cleanUpFunctions != null)
	{
		for(var index = 0; index < window.cleanUpFunctions.length; index++)
		{
			var cleanupFunc = window.cleanUpFunctions[index];
			
			cleanupFunc();
		}
	}
}

function DumpObject(obj, maxValueLength, nameFilter)
{
	var props = new Array();
	
	if (maxValueLength == null)
	{
		maxValueLength = 200;
	}

	if (!nameFilter || nameFilter == "")
	{
		nameFilter = ".+";
	}
	else
	{
		nameFilter = ".+" + nameFilter + ".+";
	}
	
	var nameFilterRegExp = new RegExp(nameFilter, "i");

	for(prop in obj)
	{
		if (prop.search(nameFilterRegExp) < 0)
		{
			continue;
		}
	
		var value = obj[prop];

		if (value != null)
		{	
			if (typeof(value) == 'object')
			{
				props.push(prop + '=(object)');
			}
			else if (typeof(value) == 'function')
			{
				value = value + '';
				
				if (value.length != null && value.length > maxValueLength)
				{
					value = value.substr(0, maxValueLength) + '(...)';
				}

				props.push(prop + '=' + value);
			}
			else if (value != null)
			{			
				if (value.length != null && value.length > maxValueLength)
				{
					value = value.substr(0, maxValueLength) + '(...)';
				}

				props.push(prop + '="' + value + '"');
			}
		}
		else
		{
			props.push(prop);
		}
	}

	return props.sort().join(', ');
}

function CreateXMLObject(objectID)
{
    var xmlObj;
    try
    {
        xmlObj = new ActiveXObject(objectID + '.4.0');
    }
    catch (err)
    {
        try
        {
            xmlObj = new ActiveXObject(objectID + '.3.0');
        }
        catch (err)
        {
            alert("Could not create " + objectID);
            return null;
        }
    }
    return xmlObj;
}

// Creates a DOM Document
// xml - optional.If provided, the DOM Document is loaded with the xml.
function CreateDOMDocument(xml)
{
	var doc;

	if (vBrowserObject.IsIE)
	{
		doc = CreateXMLObject('MSXML2.DOMDocument');

		if (xml != null)
		{
			doc.async = false;
			doc.loadXML(xml);
		}
	}
	else if (xml != null)
	{
		var parser = new DOMParser();

		doc = parser.parseFromString(xml, "text/xml");
	}
	else
	{
		doc = document.implementation.createDocument("", "", null)
	}

	return doc;
}

function CreateFreeThreadedDOMDocument()
{
    return CreateXMLObject('MSXML2.FreeThreadedDOMDocument');
}

function CreateXSLTemplate()
{
    return CreateXMLObject('MSXML2.XSLTemplate');
}

// Get the xml contents in a DOM Document, cross-browser way.
function GetXML(doc)
{
	var xml;

	if (vBrowserObject.IsIE)
	{
		xml = doc.xml;
	}
	else
	{
		var serializer = new XMLSerializer();

		xml = serializer.serializeToString(doc.documentElement);
	}

	return xml;
}

// Encode a text so that it can be injected into HTML safely, without being treated as HTML.
function ToHtmlString(text)
{
	if (text.search(/&/) != -1)
	{
		text = text.replace(/&/g, '&#38;');
	}

	if (text.search(/"/) != -1)
	{
		text = text.replace(/\"/g, '&quot;');
	}
	
	if (text.search(/'/) != -1)
	{
		text = text.replace(/\'/g, '&#39;');
	}

	if (text.search(/>/) != -1)
	{
		text = text.replace(/>/g, '&gt;');
	}
	
	if (text.search(/</) != -1)
	{
		text = text.replace(/</g, '&lt;');		
	}
		
	return text;
}	

function GetNetcampusBaseUrl()
{
	return GetRootUrl() + 'app/netcampus/';
}

function GetTestbuilderBaseUrl()
{
    return GetRootUrl() + 'app/netcampus/administration/testbuilder/';
}

function GetRootUrl()
{
	var baseDir = '/app/';	
	var url = window.location.href.toLowerCase();
	var pos;
	
	pos = url.lastIndexOf(baseDir);
	return url.substr(0, pos) + '/';
}

function GetCallerBaseUrl()
{
	var currentLocationUrl = window.location.href;
	var pos = currentLocationUrl.lastIndexOf('/');

	return currentLocationUrl.substr(0,pos)+ '/';
}

function OpenCalendarSelector(queryParameters)
{
	var dialogParams = 'status:no;dialogWidth:230px;dialogHeight:260px;scroll=no;status=no';
	var url = '../Common/CalendarSelector.aspx?' + queryParameters;
	var dialogUrl = GetNetcampusBaseUrl() + 
					'Common/ModalDialogFrameset.aspx?page=' + escape(url);	
						
	return OpenDialog(dialogUrl, null, dialogParams);
}

function OpenFramesetNoMarginDialog(url, args, params)
{
	try
	{
		var dialogUrl = GetNetcampusBaseUrl() + 
						'Common/ModalDialogFramesetNoMargin.aspx?page=' +	
						GetCallerBaseUrl() + url;

		return OpenDialog(dialogUrl, args, params);
	}
	catch(e)
	{
		alert('Error in OpenFramesetNoMarginDialog:\n\n' + e.message);
	}
}

function OpenFramesetDialog(url, args, params, absUrl)
{
	try
	{   
	    if(!absUrl)
	    {
	        url = GetCallerBaseUrl() + url;
	    }
	    
		var dialogUrl = GetNetcampusBaseUrl() + 
						'Common/ModalDialogFrameset.aspx?page=' +	
						url;

		return OpenDialog(dialogUrl, args, params);
	}
	catch(e)
	{
		alert('Error in OpenFramesetDialog:\n\n' + e.message);
	}
}

function OpenDialog(url, args, dialogSizeOrParams, customWidth, customHeight)
{
    var params;
    var size;

	if (!dialogSizeOrParams)
	{
		dialogSizeOrParams = DialogSize.Small;
	}

	size = GetDialogSize(dialogSizeOrParams, customWidth, customHeight);
    
	if (size == null)
	{
		params = dialogSizeOrParams;
	}
	else
	{
	    params = 'status:no;dialogWidth:' + size.Width + 'px;dialogHeight:' + size.Height + 'px;scroll:no;';
	}

	try
    {
	    return window.showModalDialog(url, args, params);
	}
	catch(e)
	{
		throw 'Error in OpenDialog()\nFile: Script/General.js\n\n' + e.message + 
				'\n\nUrl: ' + url + '\nArgs: ' + args + '\nDialog params: ' + params; 
	}
}

function NCGetRadWindowManager()
{
	var windowMgr = null;
	var findTopmostObject = true;
	var getRadWindowManager = GetParentObject('GetRadWindowManager', findTopmostObject);
	
	if (typeof(getRadWindowManager) != 'function')
	{
		getRadWindowManager = GetObject(window, 'GetRadWindowManager', null);
	}

	if (typeof(getRadWindowManager) != 'function')
	{
		alert('Missing RadWindowManager on page:\n\n' + document.location);
	}
	else
	{
		windowMgr = getRadWindowManager();
    }

	return windowMgr;
}

// Returns the currently active RadWindow. Note, the active window is not necessarily the 
// current dialog. If you call this function before your dialog has loaded (for example, 
// in onload), you will get the other active RadWindow, if any.
function GetActiveRadWindow()
{
	var windowMgr = NCGetRadWindowManager();

	return windowMgr.getActiveWindow();
} 

// Returns the RadWindow of the current dialog, regardless whether the dialog is the 
// current active window or not.
function GetDialogRadWindow()
{
	var foundRadWindow = null;
	var currentWindow = window;
	
	if(currentWindow.frameElement != null)
	{
	    do
	    {
		    foundRadWindow = currentWindow.frameElement.radWindow;
    		
		    if (foundRadWindow != null)
		    {
			    break;
		    }
    		
		    currentWindow = currentWindow.parent;
	    }
	    while(currentWindow != null && currentWindow != currentWindow.parent)
	}

    return foundRadWindow;
}

function GetRadDialogArguments()
{
	var wnd = GetDialogRadWindow();		

    return wnd != null ? wnd.argument.CustomArgs : null;
}

function NConClientClose(sender, args)
{
	var dialogResult = (args != null && typeof (args.get_argument) == "function") ? args.get_argument() : null;
	
	if (dialogResult != null && typeof(dialogResult.CallBackFunction) == "function")
	{
		var runCallBackFunction = (dialogResult.DialogButton & dialogResult.AutorunCallBackButtons) != 0;

		if (runCallBackFunction)
		{
			dialogResult.CallBackFunction(dialogResult.DialogButton, dialogResult);
		}
    }
}

function GetAvailableWindowName(windowMgr, windowType)
{
	var windowBaseName = GetWindowBaseName(windowType);
	var activeWindow = windowMgr.getActiveWindow();
	var availableWindowNumber = 1;

	if (activeWindow != null)
	{
		var windowName = activeWindow.get_name() + '';
		var winRegExp = new RegExp('^' + windowBaseName + '(\\d)+');
		var parts = winRegExp.exec(windowName);
		
		if (parts != null)
		{
			availableWindowNumber = parseInt(parts[1]) + 1;
		}
	}

	return windowBaseName + availableWindowNumber;
}

function OpenRadWindow(url, windowType)
{
	var windowMgr = NCGetRadWindowManager();
	var availableWindow = null;

	if (windowType == undefined)
	{
		windowType = WindowType.FixedDialogWindow;
	}

	if (windowMgr != null)
	{
		var windowName = GetAvailableWindowName(windowMgr, windowType);
		availableWindow = windowMgr.getWindowByName(windowName);		
		availableWindow.NCcallBackExecuted = false;
		availableWindow.setUrl(url);
	}
	
	return availableWindow;
}

function OpenFramesetRadDialog(url, title, callbackFunc, customArgs, dialogSize, customWidth, customHeight)
{
	try
	{
		var dialogUrl = GetNetcampusBaseUrl() + 
						'Common/ModalDialogFrameset.aspx?page=' +	
						GetCallerBaseUrl() + url;

		return OpenRadDialog(dialogUrl, title, callbackFunc, customArgs, dialogSize, customWidth, customHeight);
	}
	catch(e)
	{
		alert('Error in OpenFramesetRadDialog:\n\n' + e.message);
	}
}

function OpenDynamicRadDialog(url, title, callbackFunc, customArgs, dialogSize, customWidth, customHeight)
{
	return OpenRadDialog(url, title, callbackFunc, customArgs, dialogSize, customWidth, customHeight, WindowType.DynamicDialog);
}

function OpenRadDialog(url, title, callbackFunc, customArgs, dialogSize, customWidth, customHeight, autorunCallBackButtons, windowType)
{
    var	wnd;

    if (windowType == undefined || windowType == null)
    {
        windowType = WindowType.FixedDialog;
    }

    var size = GetDialogSize(dialogSize, customWidth, customHeight);
    wnd = OpenRadWindow(url, windowType);

    // the delay solves some window rendering problem
    setTimeout(DelayedOpenRadDialog, 20);

    function DelayedOpenRadDialog()
    {
	    if (wnd != null)
	    {
		    if (!title || title == "")
		    {
			    title = " ";
		    }

		    wnd.argument =
		    {
		        AutorunCallBackButtons: autorunCallBackButtons,
		        CallBackFunction: callbackFunc,
		        CustomArgs: customArgs
		    };
    		
		    wnd.set_title(title);
		    wnd.setSize(size.Width, size.Height);
		    wnd.show();

		    DockWindow(wnd, Dock.Center);
		}
    }

    return wnd;	
}

// Accepts the currently active RadDialog. May be called without arguments.
function AcceptRadDialog(resultArgs)
{
    CloseRadDialog(DialogButton.Ok, resultArgs);
}

// Cancels the currently active RadDialog. May be called without arguments.
function CancelRadDialog(resultArgs)
{
    CloseRadDialog(DialogButton.Cancel, resultArgs);
}

// Close the currently active RadDialog. May be called without arguments.
// If the button argument is not provided, the dialog is canceled by default and 
// callback functions are ignored.
function CloseRadDialog(dialogButton, resultArgs)
{
    var wnd = GetDialogRadWindow();
	var callBackFunction = null;
	var autorunCallBackButtons;

	// Get values that were passed to the dialog for the dialog result object.
 	if (wnd.argument != null)
	{
	    callBackFunction = wnd.argument.CallBackFunction;
	    autorunCallBackButtons = wnd.argument.AutorunCallBackButtons;
	}
	
    if (!dialogButton)
    {
    	dialogButton = DialogButton.Cancel;
    }
 
	if (!autorunCallBackButtons)
	{
		autorunCallBackButtons = DialogButton.Ok;
	}

	var dialogResult =
		CreateDialogResult(DialogOrigin.PageDialog, callBackFunction, dialogButton, autorunCallBackButtons, resultArgs);
	
    // Closing the dialog will trigger the NConClientClose() handler.
    wnd.close(dialogResult);
}

function OpenGenericPromptDialog(windowType, msg, title, callbackFunc, dialogButtons, autorunCallBackButtons)
{
	function AfterOnLoadCallBack()
	{
		DockWindow(wnd, Dock.Center);
	}

	var url = GetNetcampusBaseUrl() + 'Common/Dialogs/GenericPromptDialog.aspx';
	var wnd = OpenRadWindow(url, windowType);

	if (wnd != null)
	{			
		if (!title || title == '')
		{
			title = ' ';
		}

		wnd.argument =
	    {
	        DialogButtons: (dialogButtons != undefined) ? dialogButtons : DialogButton.OkCancel,
	        DialogText: msg,
	        DialogTitle: title,
	        CallBackFunction: callbackFunc,
	        AutorunCallBackButtons: autorunCallBackButtons,
	        AfterOnLoad: AfterOnLoadCallBack
	    };
	}
	
	return wnd;
}

function NCconfirm(msg, title, callbackFunc, dialogButtons, autorunCallBackButtons)
{
    var wnd = OpenGenericPromptDialog(
		WindowType.Confirmation, msg, title, callbackFunc, dialogButtons, autorunCallBackButtons);

    if (wnd == null)
    {
        confirm(msg);
    }

    return wnd;
}

function NCalert(msg, title, callbackFunc)
{
	var wnd = OpenGenericPromptDialog(WindowType.Alert, msg, title, callbackFunc, DialogButton.Ok);

	if (wnd == null)
	{
		alert(msg);
	}

	return wnd;
}

function NCinfo(msg, title, dialogSize)
{
    var url = GetNetcampusBaseUrl() + "Common/Dialogs/InfoDialog.aspx";
    var args =
			{
			    Text: msg
			};
			if (dialogSize == undefined)
			{
			    OpenRadDialog(url, title, null, args, DialogSize.Small);
			}
			else
			{
			    OpenRadDialog(url, title, null, args, dialogSize);
			}
}

function ShowImage(fileStorageFileID, accessContext, connectedAccessID, title, dialogSize)
{
	var commonUrl = GetNetcampusBaseUrl() + "Common/";
	var imagePageUrl = commonUrl + "FileDownload.aspx?AccessContext=" + accessContext +
	                    "&fileId=" + fileStorageFileID + "&nodeId=" + connectedAccessID;
	var dialogUrl = commonUrl + "ModalDialogFrameset.aspx?DialogButtons=true&page=" + escape(imagePageUrl);

	if (!dialogSize)
	{
		dialogSize = DialogSize.Small;
	}
				
	OpenRadDialog(dialogUrl, title, null, null, dialogSize);
	
	// Make sure calls made from ImageButtons don't continue with a postback (default behavior if the event
	// isn't cancelled).
	if (event.srcElement != null && event.srcElement.type == "image")
	{
		event.returnValue = false;
	}
}

function CreateDialogResult(origin, callBackFunction, dialogButton, autorunCallBackButtons, resultArgs)
{
	var	result = 
		{
			DialogButton:			dialogButton, 
			CallBackFunction:		callBackFunction,
			AutorunCallBackButtons:	autorunCallBackButtons,
			Origin:					origin,
			ResultArgs:				resultArgs
		};
			
	return result;
}

function ShowLoading()
{
	document.body.innerHTML += 
		'<div id="loadingDiv" name="loading1" style="position:absolute;left:0px;top=0px;' + 
		'widht=100%;height=100%;background-color=#FFFFFF;filter:alpha(opacity=80);overflow=clip">' +
		'<table border="0" cellspacing="0" cellpadding="0" width="102%" height="100%">' + 
		'<tr>' + 
		'<td align="center"><img src="/images/loading.gif"></td>' + 
		'</tr>' +
	    '</table>' +
		'</div>';
}

// Search for parent element with a specific tagName. Note, tagName must be in uppercase.
function GetParentTag(currentElement, tagName)
{
    if (currentElement != null)
    {
   		currentElement = currentElement.parentNode;
    }

	while(currentElement != null)
	{
		if (currentElement.tagName == tagName)
		{
			break;
		}

		currentElement = currentElement.parentNode;
	}
	
	return currentElement;
}

// Find an element by looking in current and descendant frames 
// (except the frame defined in ignoreFrame, if any)
function GetObject(currentWindow, objectID, ignoreFrame)
{
	var index;
	var foundObject = currentWindow[objectID];

	if (foundObject == null)
	{
		foundObject = currentWindow.document.getElementById(objectID)

		if (foundObject == null)
		{	
			for(index = 0; index < currentWindow.frames.length; index++)
			{
				var checkedFrame = currentWindow.frames[index];

				if (ignoreFrame != checkedFrame && checkedFrame != null)
				{
				    foundObject = GetObject(checkedFrame, objectID);
				}
				
				if (foundObject != null)
				{
					break;
				}
			}
		}
	}
	
	return foundObject;
}

// Find object in parent frame hierarchy, either in the HTML or as a property on the window object.
function GetParentObject(objectID, findTopmostObject, onlyLookOneLevelUp)
{
	var currentWindow = window;
	var foundObject = null;
	var resultObject = null;

	if (!objectID)
	{
		alert('GetParentObject: missing objectID');
		return null;
	}

	while(currentWindow.parent != null && currentWindow != currentWindow.parent)
	{
		var ignoreFrame = currentWindow;
		
		currentWindow = currentWindow.parent;
		
		foundObject = GetObject(currentWindow, objectID, ignoreFrame);

		if (foundObject != null)
		{
		    resultObject = foundObject;

		    if (!findTopmostObject)
		    {
		        break;
		    }
		}
		else if (onlyLookOneLevelUp)
		{
		    break;
		}
		
	}
	
	return resultObject;
}

function ShowNodeInfo(nodeID, infoType, userID, callbackFunc, customArgs)
{
	var url;
	
	if (infoType == null)
	{
		infoType = 'preview';
	}
	
	url = GetNetcampusBaseUrl() + 
			'Student/CourseCatalog/ConceptInformation.aspx?nodeId=' + nodeID + 
			'&typ=' + infoType;

	if (userID != null)
	{
	    url += '&user=' + userID;
	}

	var wnd = OpenRadDialog(url, null, callbackFunc, customArgs, DialogSize.MediumWide);
	
	return wnd;
}

function ShowUserInfo(studentID)
{
	var url = GetNetcampusBaseUrl() + "Administration/Users/StudentInfo.aspx?studentId=" + studentID;

	var wnd = OpenRadDialog(url, null, null, null, DialogSize.Medium);
	
	DockWindow(wnd, Dock.Center);
}

function ShowGroupInfo(id)
{
    var url = GetNetcampusBaseUrl() + 'Administration/Settings/Group/GroupInfoDialog.aspx?objectId=' + id;
	
	var wnd = OpenRadDialog(url, null, null, null, DialogSize.Custom, 360, 400);
	
	DockWindow(wnd, Dock.Center);
}

function ShowNodeMembers(nodeid1)
{
    var url = GetNetcampusBaseUrl() + 'Administration/Settings/Group/GroupMembers.aspx?viewOnly=true&idName=nodeID';
    url += '&value=' + nodeid1;
      OpenRadDialog(url, null, null, null, DialogSize.MediumWide);
}

function ShowGroupMembers(groupId1, groupId2)
{
	var url = GetNetcampusBaseUrl() + 'Administration/Settings/Group/GroupMembers.aspx?viewOnly=true&idName=groupIDs';

    if(groupId2)
    {
		url += '&groupId=' + groupId1 + '&groupId2=' + groupId2;
    }
    else
    {
		url += '&groupId=' + groupId1;
    }
    
    OpenRadDialog(url, null, null, null, DialogSize.MediumWide);
}

function PreviewQuestion(QuestionID)
{
    var hWnd = window.open(GetTestbuilderBaseUrl() + "QuestionPreview.aspx?QuestionID=" + QuestionID, null, 'top=0,left=0,width=1012,height=693,status=yes,toolbar=no,menubar=no,location=no,resizable=yes');
    hWnd.focus();
}

function CloseForm()
{
	window.returnValue = true;
	window.close();
}

function CancelForm()
{
	window.returnValue = false;
	window.close();
}

function CloseWindow()
{
    window.close();
}

function StartNode(nodeID, nodeType, accessContext)
{
    var url;
    var appUrl = GetRootUrl();
    var width = 1013;
    var height = 693;

    if (window.screen.availWidth < width) {
        width = window.screen.availWidth;
    }
    if (window.screen.availHeight < height) {
        height = window.screen.availHeight;
    }

    var url = appUrl + "/App/Netcampus/Student/StartPage/StartNode.aspx?nodeID=" + nodeID + "&AccessContext=" + accessContext;
    var windowParams = "scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes" +
                               ",width=" + width + ", height=" + height;

    if (nodeType == ConceptType.Hyperlink ||
        nodeType == ConceptType.Document) 
    {
        windowParams = "scrollbars=yes,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes" +
                               ",width=" + width + ", height=" + height;
    }
    else if (nodeType == ConceptType.WebTest)
    {
        windowParams = "scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=no" +
                               ",width=" + width + ", height=" + height;
    }

    window.open(url, "startnode_" + nodeID, windowParams);
}

function PreviewNodeResource(nodeId, resourceId, type) 
{
	switch (type)
	{
	    case ConceptType.Document:
	        window.location=GetRootUrl() + 'App/Netcampus/Common/FileDownload.aspx?AccessContext=4' + 
	                    '&fileId=' + resourceId + '&nodeId=' + nodeId;      
	        break; 
		case ConceptType.WebCourse:
		    window.open(GetRootUrl() + 'App/Netcampus/Student/CoursePlayer/StartCoursePlayer.aspx?sFolderId=' + 
						resourceId + 
						'&type=preview', 
						'_blank',
						'top=0,left=0,width=1012,height=693,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
			break;
		case ConceptType.WebTest:
		    window.open(GetRootUrl() + 'App/Netcampus/Student/TestPlayer/TestStart.aspx?preview=1&TestID=' + 
						resourceId, 
						'Test', 
						'top=0,left=0,width=1012,height=693,status=no,toolbar=no,menubar=no,location=no,resizable=no');
			break;
		case ConceptType.WebSurvey:
		    window.open(GetRootUrl() + 'App/Netcampus/Student/CoursePlayer/StartCoursePlayer.aspx?sFolderId=' + 
						resourceId +
						'&type=preview', 
						'_blank',
						'top=0,left=0,width=1012,height=693,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
			break;
        case ConceptType.Room:
            window.open(GetNetcampusBaseUrl() + 'Room/Room.aspx?conceptID=' + 
                        nodeId +
                        '&type=preview',
                        '',
                        'width=1016,height=705,top=0,left=0,resizable=yes');
            break;
	}    
}

function OpenWindow(url, windowSize, customWidth, customHeight)
{
    var size = GetDialogSize(windowSize, customWidth, customHeight);

    window.open(url, "_blank", "status = no, width = " + size.Width + "px, height = " + size.Height + "px, scrollbars = yes");
}

function OpenNamedWindow(url, name, windowSize, customWidth, customHeight)
{
    var size = GetDialogSize(windowSize, customWidth, customHeight);

    window.open(url, name, "status = no, width = " + size.Width + "px, height = " + size.Height + "px, scrollbars = yes");
}

function AddEventListener(control, type, method)
{
    if (control.addEventListener)
    {
        //ff style
        control.addEventListener(type.replace(/^on/, ''), method, false);
    } else if (control.attachEvent)
    {
        // IE style
        control.attachEvent(type, method);
    }

}

// Workaround for the _events issue (handler cleanup problem with new RadControls and old RadAjaxManager).
function CustomRemoveHandler(a, e, f)
{
    if (a._events != null)
    {
        window.originalRemoveHandler(a, e, f);
    }
}

function AddCustomRemoveHandlerFunction()
{
    if (window.$removeHandler != null
        && window.$removeHandler != CustomRemoveHandler)
    {
        window.originalRemoveHandler = window.$removeHandler;
        window.$removeHandler = CustomRemoveHandler;
    }
}

function ShowHelp(articleID)
{
    var openArticleArticleRef = GetParentObject('OpenHelpArticle');
    openArticleArticleRef(articleID);
}

function EditHelp(articleID)
{
    var editArticleArticleRef = GetParentObject('EditHelpArticle');
    editArticleArticleRef(articleID);
}

function SetObjectAccess(objectAccessCategory, objectID, callbackFunction)
{
    var url = "../Common/Access/Authority.aspx?dialog=true&categoryId=" +
        objectAccessCategory + "&objectId=" + objectID;

    OpenRadDialog(url, '', callbackFunction, null, DialogSize.Custom, 700, 500);
}

function OpenFileExplorer(mediaType, callbackFunction)
{
    var url = "../Common/Files/FileExplorer.aspx?dialog=true&mediaType=" + mediaType;

    OpenRadDialog(url, '', callbackFunction, null, DialogSize.Large);
}

function GetSourceElement(e)
{
	var evt = window.event || e;
	return evt.target || evt.srcElement;
}

function GetText(textID)
{
    var s = _localizedTexts[textID];
    
    if (s == null) return (textID + " is not registred in ScriptLocalization.ashx");

    for (var i = 1; i < arguments.length; i++)
    {
        s = s.replace("{" + (i - 1) + "}", arguments[i]);
    }

    return s;
}

function abortPostbacks(sender, args)
{
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (prm.get_isInAsyncPostBack())
        args.set_cancel(true);
}

AddEventListener(document,'readystatechange',AddCustomRemoveHandlerFunction)




