/**
 * Util.js 
 * This file is lisenced under LGPL 
 * Copyright (C) 2006 nightlabs
 * author : khaled at nightlabs dot de
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; 
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 */ 
function Util(){
	this.instance = null;
}
Util.getInstance = function(){
	if(this.instance == null)
		this.instance = new Util();
	return this.instance;	
}

Util.prototype.imageUrlToString = function (url){
	str = url.substring(4,url.length-1);
return str;
 }
 /* Cross Browser Event adding (workaround for the IE) */
Util.prototype.crossBrowserAddEventListener = function( obj, type, fn )
{
   if (obj.addEventListener) {
       obj.addEventListener( type, fn, false );
   } else if (obj.attachEvent) {
      obj["e"+type+fn] = fn;
      obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
      obj.attachEvent( "on"+type, obj[type+fn] );
   }
}
Util.prototype.crossBrowserRemoveEventListener = function ( obj, type, fn )
{
   if (obj.removeEventListener) {
      obj.removeEventListener( type, fn, false );
   } else if (obj.detachEvent) {
      obj.detachEvent( "on"+type, obj[type+fn] );
      obj[type+fn] = null;
      obj["e"+type+fn] = null;
   }
}
/*	function to reference an object through the previous event handling 
 *  @param argument will be ignored if not passed 
*/
Util.prototype.createMethodReference = function (object, methodName)
{
	return function() {
 		 object[methodName].apply(object,arguments);
 	 }
}
Util.prototype.getStyleRule = function (ruleName, attribute){
 	for(i=0; i<document.styleSheets.length; i++) {
 		if(document.styleSheets[i].cssRules)
 			rules = document.styleSheets[i].cssRules;
 		else if (document.styleSheets[i].rules)
 			rules = document.styleSheets[i].rules;
 		if(rules) {
		 	for(j=0; j<rules.length; j++) {
		 	  if(rules[j].selectorText == ruleName) {
		 	    return rules[j].style[attribute];
		 	  }
		 	}
	 	}
	}
 } 
Util.prototype.doStyleRule = function (ruleName,theELement){
 	for(i=0; i<document.styleSheets.length; i++) {
 		if(document.styleSheets[i].cssRules)
 			rules = document.styleSheets[i].cssRules;
 		else if (document.styleSheets[i].rules)
 			rules = document.styleSheets[i].rules;
 		if(rules) {
 			for(j=0; j<rules.length; j++) {
		 	  if(rules[j].selectorText == ruleName) {
		 	  	//alert(rules[j].cssText);
		 	 	break;
		 	  }
		 	}
	 	}
	}
 } 
 