﻿if (!window.Renault) Renault=new Object();
if (!window.Renault.Tools) Renault.Tools=new Object();

Renault.Tools.clearList=function(Control,LeaveFirst)
{
	if (!LeaveFirst) LeaveFirst=true;
	while (Control.options.length>Number(LeaveFirst))
		Control.removeChild(Control.options[Number(LeaveFirst)]);
}

Renault.Tools.addToList=function(Control,Value,Description)
{
	var Status=false;
	for (var Index=0; Index<Control.options.length; Index++)
		if ((Status=(Control.options[Index].value==Value.toString()))==true)
			break;
	if (Status==false)
	{
		var Option=document.createElement("option");
		Option.value=Value;
		Option.innerHTML=Description;
		Control.appendChild(Option);
	}
}

Renault.Tools.openPopUp=function(url,width,height)
{
	var Window=window.open(url,"_blank","width="+width+",height="+height+",menubar=0,resizable=0,scrollbars=1,status=0,titlebar=1,toolbar=0");
}

Renault.Tools.getStyleBySelector=function(Selector,FuzzySearch)
{
	var Result=new Array();
	var StyleSheets=document.styleSheets;
	var Rules;
	var StyleSheet, j;

	for (var StyleSheet=StyleSheets.length-1; StyleSheet>=0; StyleSheet--)
	{
		Rules=(StyleSheets[StyleSheet].cssRules?StyleSheets[StyleSheet].cssRules:StyleSheets[StyleSheet].rules);
		for (Rule=0; Rule<Rules.length; Rule++)
		{
			if (((FuzzySearch==false)&&(Rules[Rule].selectorText==Selector))||
				((FuzzySearch==true)&&(Rules[Rule].selectorText.indexOf(Selector)!=-1)))
				Result.push(Rules[Rule].style);
		}
	}
	return Result;
}

Renault.Tools.getStyleSheetProperty=function(className,property)
{
	var Rules=Renault.Tools.getStyleBySelector(className,true);
	for (var Rule=0; Rule<Rules.length; Rule++)
	{
		if ((Rules[Rule][property]!=null)&&(Rules[Rule][property]!=""))
			return Rules[Rule][property];
	}
	return "";
}