/**
 *	restyle : object voor het overschrijven van styles van objecten waar DOTNETNUKE.
 * 	3 gelijkwaardige array's met obj = objectid, atr = te wijzigen attribute, val = value van attribute
 * 	Array deb is een array met elementid's waarvan we de innerHTML gaan tonen.
 */
 
function restyle()
{
	this.obj = new Array();
	this.atr = new Array();
	this.val = new Array();
	this.deb = new Array();
	this.alleen_beheerders_style = "";
	this.focusid = "";
	
	//Om geen events op de onLoad te overschrijven slaan we deze op in een variabelle.
	//Dit doen we zodat we ons eigen onload event er tussen kunnen hangen.
	//Na het uitvoeren van de orginele onload voeren we onze eigen execute uit.
	this.onload_ = window.onload;
	
	
	//Voeg een style toe aan het object voor een element
	this.add = function( obj_name, atr_name, value)
	{
		var counter = this.obj.length;

		this.obj[counter] 	= obj_name;
		this.atr[counter] 	= atr_name;
		this.val[counter] 	= value;
	}
	
	
	//Overschrijf direct een style van een element
	this.add_to_style = function( obj_name, style_value)
	{
		var input_obj = parent.document.getElementById( obj_name );
		var input_obj_style = input_obj.style;
		input_obj_style.cssText += style_value; 		
	}

	this.execute = function()
	{
		var i;
		var counter = this.obj.length;

		try
		{
			this.onload_;
		}catch(err)
		{}
		
		try
		{
			this._fix_alleen_beheerders(); 
		}catch(err)
		{}
		
		for ( i=0; i<counter; i++)
		{
		
			var input_obj = parent.document.getElementById( this.obj[i] );

			if ( !(input_obj == null))
			{
				var input_obj_style = input_obj.style;	
				input_obj_style.cssText += this.atr[i] + ": " + this.val[i] + ";"; 
				
				//Volgende methodes zijn NIET firefox compatible
				//input_obj.setAttribute( 'style.width', '165px');
				//input_obj_style.setAttribute( this.atr[i], this.val[i], null);
			}
		}
		
		//Focus zetten?
		if( this.focusid != "")
		{
			try
			{
				var foc_obj = parent.document.getElementById( this.focusid);
				if( foc_obj != undefined)
				{
					foc_obj.focus();
				}
			}catch(err)
			{}
		}
		
	}

	//Bepaal of er een focus moet worden gezet op een id als deze bestaat op de website
	//Zou nog een array met prio hoog tot laag kunnen worden.
	this.setFocusOnId = function( elementId)
	{
		this.focusid = elementId;
	}
	
	// Javascript function that will return an array of elements based on DOM element, tag, and class name.
	// For instance, getElementsByClassName(document, 'tr', 'INFO') will get all "tr" tags under the document node with the "INFO" class and return an array of them.
	this._getElementsByClassName = function(oElm, strTagName, strClassName)
	{
		var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
		var arrReturnElements = new Array();
		strClassName = strClassName.replace(/\-/g, "\\-");
		var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
		var oElement;
		for(var i=0; i<arrElements.length; i++)
		{
			oElement = arrElements[i];
		    if(oRegExp.test(oElement.className))
			{
		        arrReturnElements.push(oElement);
		    }
		}
		return (arrReturnElements)
	}
	
	
	//Als alleen_nbeheerders_style is gezet dan wordt deze functie in de execute uitgevoerd
	//Dit is een string die aan de style wordt toegevoegd
	this._fix_alleen_beheerders = function()
	{
		if ( this.alleen_beheerders_style != "")
		{	
			//Classname gebruikt voor het aangeven "Alleen voor beheerders"
			//Style van class kan aangepast worden in style.css of een andere stylesheet bijbehorend aan de skin of container.
			var classname = "NormalRed";
			var NormalReds = new Array();
			NormalReds = this._getElementsByClassName(document,'span',classname);
			
	
			var child;
			var parent; 		
			for( var i=0; i<NormalReds.length; i++)
			{
				child = NormalReds[i];
				if( child != undefined)
				{
					parent = child.parentNode;
					//eerst nog even de <CENTER> tags weghalen (dit kan we lweer me style worden aangezet..
					var regEx = new RegExp ('<center+>', 'gi') ;
					child.innerHTML = child.innerHTML.replace(regEx, "");
					if( parent != undefined)
					{
						if ( parent.id.indexOf('pane'))
						{
							this.add_to_style( parent.id, this.alleen_beheerders_style);
						}
					}
				}
			}
		}
	}
	
	//Voeg een style toe aan het object voor een element
	this.add_debug = function( obj_name)
	{
		var counter = this.deb.length;

		this.deb[counter] 	= obj_name;
	}	

	//Om snel eens even met javascript te alerten..
	this.debug = function()
	{
		var i;
		var counter = this.deb.length;
		
		for ( i=0; i<counter; i++)
		{
		
			var input_obj = parent.document.getElementById( this.deb[i] );

			if ( !(input_obj == null))
			{
				window.alert( input_obj.innerHTML);
				//var input_obj_style = input_obj.style;	
				//input_obj_style.cssText += this.atr[i] + ": " + this.val[i] + ";"; 
			}
		}
		return true;
	}
	
	
				
}

restyle = new restyle();
window.onload = function(){ restyle.execute(); }