/************************************************
 *
 *	Class RadWindow
 *
 ************************************************/
function RadWindow(id)
{
	this.Id = id;
	this.Width = 200;
	this.Height = 200;  
	//TO DO: other properties - color, etc,  Header text
	this.OnClientClose = null;
	//Private members
	this.ContentWindow = null;
	this.ContentTD = null;
	this.ContentWrapperTable = null;
	this.X = 0;
	this.Y = 0;
	this.ShowContentWhenMoving = false;
	
	this.CanMove = true;
	this.CanResize = true;
	
	this.DragMode = "";	// "move" "size"
};

RadWindow.prototype.IsVisible = function()
{
	if (this.ContentWrapperTable)
		return this.ContentWrapperTable.style.display == "block";
		
	return false;
}

RadWindow.prototype.ShowWindow = function(show, x, y)
{
	var displayStyle = show ? "block" : "none";
	
	if (this.ContentWrapperTable)
		this.ContentWrapperTable.style.display = displayStyle;
		
	if (this.ContentWindow)
	{
		this.ContentWindow.style.display = displayStyle;
		if (null != x && null != y)
		{
			x += 10;			
			this.ContentWrapperTable.style.left = x + 'px';
			this.ContentWrapperTable.style.top = y + 'px';		
		}
								
		for (var i = 0; i < this.ContentWindow.childNodes.length; i++)
		{			
			try
			{
				this.ContentWindow.childNodes[i].style.display = displayStyle;												
			}
			catch (ex)
			{			
			}
		}
	}
	
	//NS
	if (!document.all)
	{	
		//this.ContentWindow.style.width = this.Width;
	}
}

RadWindow.prototype.Initialize =  function(contentElem, show)
{
	//Use the Id to get a reference to the ContentWindow	
	if (this.Id) 
	{
		this.ContentWrapperTable = document.getElementById("RadWindowContentWrapper" + this.Id);	 
		this.ContentWindow = document.getElementById("RadWindowContentWindow" + this.Id);	 
		this.ContentTD = document.getElementById("RadWindowContentTD" + this.Id);
		
		//Set the content of the r.a.d.window
		if (contentElem) 
		{
			this.SetContentElement(contentElem);	 	 	 	 	 
		}
		
		if (null == show)
			var show = true;

		this.ShowWindow(show);
		
	}
	else 
		alert ("No window Id provided");
};

RadWindow.prototype.SetContentElement = function (contentElem)
{
	var parentNode = contentElem.parentNode;
	if (parentNode) parentNode.removeChild(contentElem);		
	this.ContentWindow.removeChild(this.ContentWindow.childNodes.item(0));		
	this.ContentWindow.appendChild(contentElem);		
	this.SetContentWindowSize(contentElem.style.width, null);	
}

RadWindow.prototype.SetContentWindowSize = function (width, height)
{
	this.Width = width;	
	/*
	this.ContentWindow.style.width = width + "px";
	
	if (height)
	{
		this.Height = height;
		this.ContentWindow.style.height = height + "px";	
	}*/
	
	if (!document.all)
	{	//For NS only!	    
		this.ContentWrapperTable.getElementsByTagName("TABLE").item(0).style.width = width + "px";	  
	}	
};

RadWindow.prototype.SetContentVisible = function (visible)
{
	if (document.all)
	{
		this.ContentWindow.style.visibility = visible ? "visible" : "hidden";
	}
	else
	{
		this.ContentWindow.childNodes[0].childNodes[0].style.display = visible ? "block" : "none";	 //visible ? "visible" : "hidden";	
	}
};

RadWindow.prototype.Close =  function()
{
	if (this.OnClientClose != null) 
		this.OnClientClose();
		
	this.ShowWindow(false);
};
			
RadWindow.prototype.ToggleCanMove =  function(oDiv)
{
	this.CanMove = !this.CanMove;
	
	oDiv.innerText = this.CanMove ? "+" : "O";
};

RadWindow.prototype.CanDrag = function()
{
	return ("move" == this.DragMode && this.CanMove)
			|| ("size" == this.DragMode && this.CanResize);
}

RadWindow.prototype.OnDragStart = function(e)
{   
	if (!this.CanDrag())
		return;
	
	this.X = (e.offsetX == null) ? e.layerX : e.offsetX;
	this.Y = (e.offsetY == null) ? e.layerY : e.offsetY;    
	
	MousePosX = e.clientX;
	MousePosY = e.clientY;
	
	this.SetContentVisible(this.ShowContentWhenMoving);
	
	RadWindowActiveWindow = this; 
	RadWindowDragStart();
};

RadWindow.prototype.SetActive = function(activate)
{			
	if (activate)
	{
		if (null != RadWindowActiveWindow && RadWindowActiveWindow != this)
		{
			RadWindowActiveWindow.SetActive(false);
		}
	
		RadWindowActiveWindow = this;
	}
	else
	{
		if (this == RadWindowActiveWindow)
			RadWindowActiveWindow = null;
	}
}

RadWindow.prototype.SetPosition = function(left, top)
{
	this.ContentWrapperTable.style.left = parseInt(left) + 'px';
	this.ContentWrapperTable.style.top = parseInt(top) + 'px';
}

RadWindow.prototype.GetWidth = function()
{
	var width = 0;
	if (document.all)
	{	
		width = this.ContentWrapperTable.clientWidth;		
	}
	else
	{
		width = this.ContentWrapperTable.width;
	}
	
	return width;	
}

RadWindow.prototype.SetWidth = function(width)
{
	width = parseInt(width) + "px";
	if (document.all)
	{	
		this.ContentWrapperTable.style.width = width;		
	}
	else
	{
		this.ContentWrapperTable.width = width;
		
		var maxWidth = 0;
		for (var i = 0; i < this.ContentWrapperTable.rows.length; i++)
		{
			var row = this.ContentWrapperTable.rows[i];
			var rowWidth = 0;
			for (var j = 0; j < row.cells.length; j++)
			{
				rowWidth += parseInt(row.cells[j].scrollWidth);
			}
			if (rowWidth > maxWidth)
				maxWidth = rowWidth;
		}
		
		this.ContentWrapperTable.width = maxWidth + "px";
	}
}


RadWindow.prototype.GetHeight = function()
{
	var height = 0;
	if (document.all)
	{
		height = this.ContentWrapperTable.clientHeight
	}
	else
	{
		height = 0;
		for (var i = 0; i < this.ContentWrapperTable.rows.length; i++)
		{
			var rowHeight = parseInt(parseInt(this.ContentWrapperTable.rows[i].scrollHeight));
			if (!isNaN(rowHeight))
				height += rowHeight;
		}
	}
	
	return height;
}

RadWindow.prototype.SetHeight = function(height)
{
	height = parseInt(height);
	if (document.all)
	{	
		this.ContentWrapperTable.style.height = height + "px";		
	}
	else
	{
		for (var i = 0; i < this.ContentWrapperTable.rows.length; i++)
		{
			if (this.ContentTD.parentNode.rowIndex == i)
				continue;
			
			var rowHeight = parseInt(parseInt(this.ContentWrapperTable.rows[i].scrollHeight));
			if (!isNaN(rowHeight))
				height -= rowHeight;
		}
		
		this.ContentTD.height = height + "px";
	}
}

RadWindow.prototype.SetSize = function(width, height)
{
	this.SetWidth(width);
	this.SetHeight(height);
}

//-------------------------------------MOVEMENT RELATED---------------------------------//
var RadWindowActiveWindow = null; //Points to the active window 
var RadWindowActiveWindowSpan = null;
var MousePosX = 0;
var MousePosY = 0;

/* Attach Event Handlers */
function RadWindowDragStart()
{   
	if (!RadWindowActiveWindow.CanDrag())
		return;

	if (document.all) 
	{
		document.body.attachEvent ("onmousemove", RadWindowDrag);
		document.body.attachEvent ("onmouseup", RadWindowDragEnd);
	} 
	else 
	{
		document.addEventListener("mousemove", RadWindowDrag, false);
		document.addEventListener("mouseup", RadWindowDragEnd, false);			
	}
	
	RadWindowInitializeDrag(RadWindowActiveWindow);
}

/*Detach Event Handlers*/
function RadWindowDragEnd()
{	
	if (document.all)
	{
		document.body.detachEvent ("onmousemove", RadWindowDrag);
		document.body.detachEvent ("onmouseup", RadWindowDragEnd);
	}
	else 
	{  
		document.removeEventListener("mousemove", RadWindowDrag, false);
		document.removeEventListener("mouseup", RadWindowDragEnd, false);		
	}
	
	RadWindowUnInitializeDrag(RadWindowActiveWindow);	
	RadWindowActiveWindow.SetContentVisible(true);
}

function RadWindowDrag(e)
{	
	if (RadWindowActiveWindow.CanDrag())
	{
		switch (RadWindowActiveWindow.DragMode)
		{
			case "move":
				RadWindowMove(e);							
				break;
		
			case "size":
				RadWindowSize(e);
				break;		
		}
	}
	e.cancelBubble = true;
	
	MousePosX = e.clientX;
	MousePosY = e.clientY;
	
	return false;
}

function RadWindowInitializeDrag(targetWindow)
{
	if (!targetWindow)
		return;

	if (!RadWindowActiveWindowSpan)
	{
		RadWindowActiveWindowSpan = document.createElement("SPAN");
		RadWindowActiveWindowSpan.className = "RadETableWrapperResizeSpan";
				
		RadWindowActiveWindowSpan.style.position = "absolute";	
		RadWindowActiveWindowSpan.style.zIndex = 10000;
		
		document.body.appendChild(RadWindowActiveWindowSpan);
	}
	
	RadWindowActiveWindowSpan.style.visibility = "visible";
	
	RadWindowActiveWindowSpan.style.top = targetWindow.ContentWrapperTable.style.top;
	RadWindowActiveWindowSpan.style.left = targetWindow.ContentWrapperTable.style.left;
	RadWindowActiveWindowSpan.style.width = targetWindow.GetWidth();
	RadWindowActiveWindowSpan.style.height = targetWindow.GetHeight();
	
	switch (targetWindow.DragMode)
	{
		case "move":
			RadWindowActiveWindowSpan.style.cursor = "default";
			break;
	
		case "size":
			RadWindowActiveWindowSpan.style.cursor = "se-resize";
			break;		
	}
}

function RadWindowUnInitializeDrag(targetWindow)
{
	if (RadWindowActiveWindowSpan)
		RadWindowActiveWindowSpan.style.visibility = "hidden";

	targetWindow.SetPosition(RadWindowActiveWindowSpan.style.left, RadWindowActiveWindowSpan.style.top);
	targetWindow.SetSize(RadWindowActiveWindowSpan.style.width, RadWindowActiveWindowSpan.style.height);
}

function RadWindowMove(e)
{	
	var RadWindowX = RadWindowActiveWindow.X;
	var RadWindowY = RadWindowActiveWindow.Y;

	var el = RadWindowActiveWindowSpan;	//RadWindowActiveWindow.ContentWrapperTable;   

	if (document.all)
	{   
		var left = (e.clientX * 1 + document.body.scrollLeft - RadWindowX)+'px';
		var right = (e.clientY * 1 + document.body.scrollTop - RadWindowY)+'px';
		
		el.style.left = left;
		el.style.top = right;	
	}
	else
	{       
		el.style.left = (e.pageX * 1 - RadWindowX) + 'px';
		el.style.top = (e.pageY * 1 - RadWindowY) + 'px';				
	}
}

function RadWindowSize(e)
{	
	var offsetX = e.clientX - MousePosX;
	var offsetY = e.clientY - MousePosY;	
	
	var width = parseInt(RadWindowActiveWindowSpan.style.width);
	var height = parseInt(RadWindowActiveWindowSpan.style.height);

	RadWindowActiveWindowSpan.style.width = (width + offsetX) + "px";
	RadWindowActiveWindowSpan.style.height = (height + offsetY) + "px";
}	


function BuildContentWrapperTable(editorID, toolsWidth, toolsHeight, visible, contentElementID, radControlsPath, caption)
{
	var html =	"";	
	html +=	"		<table border='0' id='RadWindowContentWrapper" + editorID + "' class='RadETableWrapper' style='display:block; z-index:1000; position:absolute;' cellspacing='0' cellpadding='0' width='" + toolsWidth + "px' height='" + toolsHeight + "px'>\n"
			+ "			<tr>\n"
			+ "				<td width='1' class='RadETableWrapperHeaderLeft' nowrap></td>\n"
			+ "					<td width='100%' class='RadETableWrapperHeaderCenter' nowrap='true' onmousedown='radToolbar_" + editorID + ".DragMode=\"move\"; return radToolbar_" + editorID + ".OnDragStart(event);' onselectstart='return false;'>\n"
			+ "						<span onselectstart='return false;' class='RadERadWindowHeader'>" + caption + "</span>\n"
			+ "					</td>\n"
			+ "				<td width='1' class='RadETableWrapperHeaderCenter' align=right>\n"
			+ "					<span class='RadERadWindowButton' onclick='radToolbar_" + editorID + ".Close()'>X</span>\n"
			+ "				</td>\n"			
			+ "				<td width='1' class='RadETableWrapperHeaderRight' nowrap></td>\n"
			+ "			</tr>\n"
			+ "			<tr>\n"
			+ "				<td id='RadWindowContentTD" + editorID + "' colspan='4'>\n"
			+ "					<table border='0' width='100%' height='100%' cellspacing='0' cellpadding='0'>\n"
			+ "						<tr>\n"
			+ "							<td width='1' class='RadETableWrapperBodyLeft' nowrap></td>\n"
			+ "							<td width='100%' class='RadEToolBarContainer' align='left' valign='top' onselectstart='return false;'>\n"
			+ "								<div id='RadWindowContentWindow" + editorID + "'>empty....</div>\n"
			+ "							</td>\n"
			+ "							<td width='1' class='RadETableWrapperBodyRight' nowrap></td>\n"
			+ "						</tr>\n"
			+ "					</table>\n"
			+ "				</td>\n"
			+ "			</tr>\n"
			+ "			<tr>\n"
			+ "				<td width='1' class='RadETableWrapperFooterLeft' nowrap></td>\n"
			+ "				<td colspan='2' width='100%' class='RadETableWrapperFooterCenter' nowrap>&nbsp;</td>		\n"
			+ "				<td width='1' class='RadETableWrapperFooterRight' onmousedown='radToolbar_" + editorID + ".DragMode=\"size\"; return radToolbar_" + editorID + ".OnDragStart(event);' onmouseover='this.className=\"RadETableWrapperFooterRightOver\"' onmouseout='this.className=\"RadETableWrapperFooterRight\"' onselectstart='return false;' nowrap></td>\n"
			+ "			</tr>\n"
			+ "		</table>\n";
			
	return html;
}

function InitToolbarFrame(editorID, frameID, divID)
{
	var radEditor = GetRadEditor(editorID);
	
	var frm = document.getElementById(frameID);	
	var tmpDiv = document.getElementById(divID);
	
	var innerHTML = "\n" + tmpDiv.innerHTML + "\n";
	
	var cssLink = "\n<link rel=\"stylesheet\" type=\"text/css\" href=\"" + radEditor.BaseScheme + "Editor.css\">\n";
	
	var eventHander =	"\n<script language='JavaScript' for='radEditorButton" + editorID + "' event='onmouseover'>parent.radEditorOverButton(this, '" + editorID + "');</script>\n";
	eventHander		+=	"<script language='JavaScript' for='radEditorButton" + editorID + "' event='onmouseout'>parent.radEditorOutButton(this, '" + editorID + "');</script>\n";
	eventHander		+=	"<script language='JavaScript' for='radEditorButton" + editorID + "' event='onclick'>parent.radEditorButtonClick('" + editorID + "', this, '" + radEditor.SessionID2 + "');</script>\n";
	
	eventHander		+=	"<script language='JavaScript' for='radEditorButton" + editorID + "' event='onfocus'>return false;</script>\n";
		
	var html = cssLink + innerHTML + eventHander;
	html = unescape(html.replace(/\+/ig, " "));
	
	var windowContent = document.getElementById(frameID).contentWindow;	
	var contentDocument = windowContent.document;
	contentDocument.open();
	contentDocument.write("<style></style><body class='RadEToolBarContainer' style='margin:0px;border:0px solid red;overflow:hidden;'>" + html + "</body>");
	contentDocument.close();
}

/************************************************
 *
 *	Allow only 1 instance of RadEditor object per editorID
 *
 ************************************************/
function GetRadEditor(editorID)
{
	var radEditorVarName = "window.RadEditor_" + editorID;
	var re = eval(radEditorVarName);	
	
	if (re)
		return re;
		
	eval(radEditorVarName + " = new RadEditorObject('" + editorID + "');");
	return eval(radEditorVarName);	
}

function CreateRadEditor(	editorID
							, allowCustomColors
							, applicationPath
							, language
							, dialogsScheme
							, serverName
							, serverPort 								
							, serverPath 
							, windowWidth
							, mediaFilters
							, documentsFilters
							, sessionID1							
							, useSession
							, newLineBr		
							, baseScheme							
							, toolsFile								
							, toolsWidth
							, toolsHeight
							, toolsOnPage
							, toolsClientID
							, sessionID2
							, clearPasteFormatting
							, stripAbsoluteAnchorPaths
							, enableUndoRedo
							, enableHtmlIndentation
						)
{
	var radEditor = GetRadEditor(editorID);
	
	radEditor.ApplicationPath	= applicationPath;
	radEditor.Language			= language;	
	radEditor.Localization		= eval("localization_" + radEditor.Language.replace("-", "_"));	
	
	radEditor.BaseScheme		= baseScheme;
	radEditor.DialogsScheme		= dialogsScheme;
	radEditor.RadControlsDir	= eval("radEditorRadControlsDir" + editorID);
	
	radEditor.ServerName		= serverName;
	radEditor.ServerPort		= serverPort;
	radEditor.ServerPath		= serverPath;
	
	radEditor.Window			= null;
	radEditor.WindowName		= null;
	
	radEditor.ToolBar			= null;
	radEditor.ContentArea		= document.getElementById("radEditorContainer" + editorID);
	radEditor.HtmlArea			= document.getElementById("radEditorText" + editorID);

	radEditor.MediaFilters		= mediaFilters;
	radEditor.DocumentsFilters	= documentsFilters;
	
	radEditor.SessionID			= sessionID1;
	radEditor.SessionID2		= sessionID2;
	
	radEditor.UseSession			= useSession;
	radEditor.NewLineBr				= newLineBr;
	radEditor.AllowCustomColors		= allowCustomColors;
	radEditor.ClearPasteFormatting	= clearPasteFormatting;
	radEditor.StripAbsoluteAnchorPaths = stripAbsoluteAnchorPaths;
		
	radEditor.Width				= windowWidth;
	
	radEditor.ToolsFile			= toolsFile;
	radEditor.ToolsClientID		= toolsClientID;
	radEditor.ToolsOnPage		= toolsOnPage;
	radEditor.ToolsWidth		= toolsWidth;
	radEditor.ToolsHeight		= toolsHeight;
	
	radEditor.EnableUndoRedo		= enableUndoRedo;
	radEditor.EnableHtmlIndentation	= enableHtmlIndentation;

	//radEditor.OnPaste = MyOnPaste; //ATTACH OnPaste HANDLER EXAMPLE
	
	return radEditor;
}

function MyOnPaste(radEditor)
{
	alert("MyOnPaste");
}

/************************************************
 *
 *	Class RadEditor - main r.a.d.editor object
 *
 ************************************************/
function RadEditorObject(editorID, sessionID)
{
	this.RadEditorID		= editorID;
	this.SessionID			= sessionID;
	
	this.ApplicationPath	= "";
	this.RadControlsDir		= "";
	
	this.Language			= "";
	this.Localization		= null;
	
	this.DialogsScheme		= "";
	this.BaseScheme			= "";
	
	this.ServerName			= "";
	this.ServerPort			= "";
	this.ServerPath			= "";
	
	this.Window				= null;	// RAD editor main window
	this.ContentArea		= null;	// document.all["radEditorContainer" + editorID]
	this.HtmlArea			= null;	// document.all["radEditorText" + editorID]
	this.ToolBar			= null;
	
	this.UseSession			= false;
	this.NewLineBr			= false;;
	this.MediaFilters		= "";
	this.DocumentFilters	= "";	
	
	this.AllowCustomColors			= true;
	this.ClearPasteFormatting		= false;
	this.StripAbsoluteAnchorPaths	= false;
	
	this.ToolsFile			= "";	
	
	this.Width				= 0;
	
	this.ToolsClientID		= "";
	this.ToolsOnPage		= false;
	this.ToolsWidth			= 0;
	this.ToolsHeight		= 0;

	this.EnableUndoRedo		= true;
	this.EnableHtmlIndentation	= true;

	this.OnPaste = null;
};

RadEditorObject.prototype.GetFullRadControlsPath = function(sessionID)
{
	if (!sessionID)
		var sessionID = "";
		
	return (this.ApplicationPath + sessionID + this.RadControlsDir);
};

RadEditorObject.prototype.GetServerUrlArray = function()
{
	return new Array(	this.ServerName + ":" + this.ServerPort + this.ServerPath,
						this.ServerName + this.ServerPort,
						this.ServerName + ":" + this.ServerPort,
						this.ServerName	);
};

/////////////////////////////////////////////////
//	RadCssClass
//
function RadCssClass(rule, alias)
{	
	this.Rule = rule;	
	this.Tag = this.GetClassTag(this.Rule);
	
	if (!alias || "" == alias)
		this.Alias = this.GetDisplayName(this.Rule);
	else
		this.Alias = alias;
		
	this.ClassName = this.GetClassName(this.Rule);
}

RadCssClass.prototype.GetClassTag = function(rule)
{
	var str = rule ? rule.selectorText : "";
	var lastIndex = str.lastIndexOf(".");
	if (lastIndex == 0) 
	{ 
		return "ALL"; 
	}
	var firstIndex = str.lastIndexOf(" ", lastIndex);
	return str.substring((firstIndex + 1), lastIndex);
}

RadCssClass.prototype.GetDisplayName = function(rule)
{
	if (!rule)
		return "";
		
	var ruleSelectorText = rule.selectorText;
		
	var startIndex = ruleSelectorText.indexOf(".");
	if (-1 == startIndex)
		startIndex = 0;
	else
		startIndex += 1;
		
	var endIndex = ruleSelectorText.indexOf(":");
	if (-1 == endIndex)
		endIndex = ruleSelectorText.length;
		
	return ruleSelectorText.substring(startIndex, endIndex);
}

RadCssClass.prototype.GetClassName = function(rule)
{	
	var str = rule.selectorText;
	var lastIndex = str.lastIndexOf(".");
	if (lastIndex == -1) 
		return "";
	var firstIndex = str.indexOf(":", lastIndex);
	if (firstIndex != -1)
		return "";
	firstIndex = str.indexOf(" ", lastIndex);
	if (firstIndex == -1) 
		firstIndex = str.length;
	return str.substring((lastIndex + 1), firstIndex);

}

RadCssClass.prototype.CompareByTag = function(radCssClass)
{
	if (this.Tag != radCssClass.Tag)
	{
		if ("ALL" == this.Tag.toUpperCase())
			return 1;			
		else if ("ALL" == radCssClass.Tag.toUpperCase())
			return -1;
	}

	if (this.Tag > radCssClass.Tag)
		return 1;
	else if (this.Tag < radCssClass.Tag)
		return -1;
		
	return 0;
}

RadCssClass.prototype.CompareByTagSelectorText = function(radCssClass)
{
	var res = this.CompareByTag(radCssClass);
	if (0 != res)
		return res;

	if (this.selectorText > radCssClass.selectorText)
		return 1;
	else if (this.selectorText < radCssClass.selectorText)
		return -1;
	else
		return 0;
}

RadCssClass.prototype.CompareByTagAlias = function(radCssClass)
{
	var res = this.CompareByTag(radCssClass);
	if (0 != res)
		return res;
	
	if (this.Alias > radCssClass.Alias)
		return 1;
	else if (this.Alias < radCssClass.Alias)
		return -1;
	else
		return 0;
}

/////////////////////////////////////////////////
//	RadCssClassArray
//
function RadCssClassArray(editorID, cssFilter)
{	
	this.IsIE = (null != document.all);
	this.CssClassArray = this.CreateCssArray(editorID, cssFilter);
}

RadCssClassArray.prototype.CreateCssArray = function(editorID, cssFilter)
{
	var arr = new Array();
	try
	{
		for (var i = 0; i < document.styleSheets.length; i++)
		{
			try
			{
				var cssHref = document.styleSheets[i].href;
				
				if (cssHref.lastIndexOf(eval('radEditorScheme' + editorID)) > -1) 
					continue;
				
				var arrRules = null;				
				if (this.IsIE)
					arrRules = document.styleSheets[i].rules;
				else
					arrRules = document.styleSheets[i].cssRules;
					
				for (var j = 0; j < arrRules.length; j++)
				{
					try
					{	
						var rule = arrRules[j];
						var outAlias = this.CheckCssFilter(rule, cssFilter);
						if (null != outAlias && !this.FindRule(arr, rule))		
						{
							arr[arr.length] = new RadCssClass(rule, outAlias);
						}
					}
					catch (ex)
					{
					}
				}
			}
			catch (ex)
			{
			}
		}
		
		arr.sort(SortRadCssClassesArrayByTagSelectorText);	
	}
	catch(ex)
	{
		arr = null;
	}
	
	return arr;
}

RadCssClassArray.prototype.FindRule = function(radCssClassArray, rule)
{
	if (!radCssClassArray)
		return true;
	
	var ruleSelector = rule.selectorText;
	ruleSelector = ruleSelector.replace(/:\w*/gi, "");
	
	var rcc = null;	
	for (var i = 0; i < radCssClassArray.length; i++)
	{
		rcc = radCssClassArray[i];
		if (rcc.Rule.selectorText == ruleSelector)
			return true;
	}
	
	return false;
}

RadCssClassArray.prototype.CheckCssFilter = function(rule, arrFilter)
{
	if (!arrFilter)
		return "";
	if (!rule)
		return null;
	for (var i = 1; i < arrFilter.length; i += 2)
	{
		var value = arrFilter[i];
		var name = arrFilter[i + 1];
		
		if (rule.selectorText.toUpperCase() == value.toUpperCase())
		{
			return name;
		}
	}		
	return null;
}

RadCssClassArray.prototype.SelectCssClassesByTagName = function(arrTags)
{
	var arr = new Array();	
	for (var i = 0; i < this.CssClassArray.length; i++)
	{
		var rcc = this.CssClassArray[i];
		
		if (!arrTags)
		{
			arr[arr.length] = rcc;
		}
		else
		{
			for (var j = 0; j < arrTags.length; j++)
			{
				if (rcc.Tag.toUpperCase() == arrTags[j].toUpperCase())
					arr[arr.length] = rcc;
			}
		}
	}	
	arr.sort(SortRadCssClassesArrayByTagAlias);
	return arr;
}

function SortRadCssClassesArrayByTagSelectorText(radCssClass1, radCssClass2)
{
	if (!radCssClass1 && !radCssClass2)
		return 0;
		
	if (!radCssClass2)
		return 1;
		
	if (!radCssClass1)
		return -1;
		
	return radCssClass1.CompareByTagSelectorText(radCssClass2);
}

function SortRadCssClassesArrayByTagAlias(radCssClass1, radCssClass2)
{
	if (!radCssClass1 && !radCssClass2)
		return 0;
		
	if (!radCssClass2)
		return 1;
		
	if (!radCssClass1)
		return -1;
		
	return radCssClass1.CompareByTagAlias(radCssClass2);
}
