var xMouse;
var yMouse;

String.prototype.leftTrim = function () 
{
	return (this.replace(/^\s+/,""));
};

String.prototype.rightTrim = function () 
{
	return (this.replace(/\s+$/,""));
};

String.prototype.trim = function () 
{
	return (this.replace(/\s+$/,"").replace(/^\s+/,""));
};


String.prototype.superTrim = function ()
{
	return(this.replace(/\s+/g," ").replace(/\s+$/,"").replace(/^\s+/,""));
};


String.prototype.removeWhiteSpaces = function ()
{
	return (this.replace(/\s+/g,""));
};

	
function getElementsByClassName(oElm, strTagName, oClassNames)
{
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	
	if (typeof oClassNames == "object")
	{
		for (var i=0; i<oClassNames.length; i++)
		{
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
 	}
	else
	{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++)
	{
		oElement = arrElements[j];
		bMatchesAll = true;
		
		for (var k=0; k<arrRegExpClassNames.length; k++)
		{
			if(!arrRegExpClassNames[k].test(oElement.className))
 			{
				bMatchesAll = false;
  			break;                      
			}
 		}
		
		if(bMatchesAll)
		{
			arrReturnElements.push(oElement);
		}
	}
   
	return (arrReturnElements);
}
	
	function getMouseCoords(e) 
	{		
		var posX = 0, posY = 0;
		if (!e) 
		{ 
			e = window.event; 
		} 
		if (!e) 
		{ 
			return [ 0, 0 ]; 
		}
				
		if( typeof(e.pageX ) == 'number') 
		{
      posX = e.pageX; posY = e.pageY;
		}
		else 
		{
			if( typeof( e.clientX ) == 'number' )
			{
				posX = e.clientX; 
				posY = e.clientY;
				
				if (document.body && !(window.opera || window.debug || navigator.vendor == 'KDE')) 
				{
					if (typeof( document.body.scrollTop) == 'number')
					{
						posX += document.body.scrollLeft; 
						posY += document.body.scrollTop;
					}
				}
				if (document.documentElement && !( window.opera || window.debug || navigator.vendor == 'KDE') )
				{
					if (typeof(document.documentElement.scrollTop) == 'number')
					{
						posX += document.documentElement.scrollLeft; 
						posY += document.documentElement.scrollTop;
					}
				}
			}
		}
		xMouse = posX;
		yMouse = posY;
	}	
	
	function createCookie(name,value,miliseconds)
	{
		if (miliseconds)
		{
			var date = new Date();
			date.setTime(date.getTime()+miliseconds);
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name) 
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}
	
 /**
	* Check on value is number 
	* 
	* @version 0.9
	* @return  Boolean
	*/
	function isNumber(value)
	{
		return (/^-?\d+[,.]{0,1}[\d]*$/.test(value));
	}
	
	/**
	* Check on value is integer
	* 
	* @version 0.9
	* @return  Boolean
	*/
	function isInt(value)
	{
		return (/^-?\d+[\d]*$/.test(value));
	}
	
 /**
	* Format a number to string
	*
	* @return String
	*/
	function number_format(number, decimals, dec_point, thousands_sep)
	{
  	var exponent = "";
  	var numberstr = number.toString ();
  	var eindex = numberstr.indexOf ("e");
  	
  	if (eindex > -1)
  	{
    	exponent = numberstr.substring (eindex);
    	number = parseFloat (numberstr.substring (0, eindex));
  	}
  
  	if (decimals != null)
  	{
    	var temp = Math.pow (10, decimals);
    	number = Math.round (number * temp) / temp;
  	}
 	 	
 	 	var sign = number < 0 ? "-" : "";
  	var integer = (number > 0 ? Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  	var fractional = number.toString ().substring (integer.length + sign.length);
  	dec_point  = dec_point != null ? dec_point : ".";
  	fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";
  	
  	if (decimals != null && decimals > 0)
  	{
    	for (i = fractional.length - 1, z = decimals; i < z; ++i)
    	{
      	fractional += "0";
      }
  	}
  
  	thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? thousands_sep : null;
  	
  	if (thousands_sep != null && thousands_sep != "")
  	{
			for (i = integer.length - 3; i > 0; i -= 3)
			{
      	integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  		}
  	}
  	
  	return sign + integer + fractional + exponent;
	}
	
	function checkEmail(email)
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)) 
		{
			return false;
		} 
		
		return true;
	}
	
	function selectForm(formId,value)
	{
		var form = document.getElementById(formId);
		
		if (!form)
		{
			return;
		}
		
		var result = 0;
		for (var i=0; i<form.childNodes.length; i++)
		{
			if (form.childNodes[i].nodeName.toLowerCase() == "option")
			{
				if (form.childNodes[i].getAttribute("value") == value)
				{
					form.selectedIndex = result;
					return;
				}
				
				result++;
			}
		}	
	}
	
	function showLanguage()
	{
		$("#lang_de").toggle();
		$("#lang_en").toggle();
	}
	
	function setLanguage(language)
	{
		$.ajax(
		{
			type: "GET",
  		url: "/page/language.set.php",
  		data: "&language=" + language,
  		cache: false,
  		success: ajaxReload
		});
	}
	
	function ajaxReload(result)
	{
		window.location.reload();
	}
	
	/**
	* Get flashobject
	*
	* Gets flashobject element
	*
	* @access public
	* @param  string moviename or id
	* @return pointer element
	*/
	function getFlashMovieObject(movieName)
	{
  	if (window.document[movieName])
  	{
      return window.document[movieName];
  	}
  	if (navigator.appName.indexOf("Microsoft Internet")==-1)
  	{
    	if (document.embeds && document.embeds[movieName])
    	{
      	return document.embeds[movieName];
      }
  	}
  	else
  	{
    	return document.getElementById(movieName);
  	}
	}
	