
/**
* sSystem Klasse
* author mor_dark
*/
// IE Flickering Bug
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err)
{
	// Nothing to do
};

if(typeof _ptools == 'undefined') {
	var _ptools = {};
};


_ptools.System = function(settings)
{
	var t = this;
	t.settings = settings ? settings : {};

	var browser = navigator.userAgent.toLowerCase();
	t.isMSIE 		= (navigator.appName == "Microsoft Internet Explorer");
	t.isMSIE5 		= t.isMSIE && (navigator.userAgent.indexOf('MSIE 5') != -1);
	t.isMSIE5_0 	= t.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1);
	t.isMSIE6 		= t.isMSIE && (navigator.userAgent.indexOf('MSIE 6') != -1);
	t.isMSIE7 		= navigator.userAgent.indexOf('MSIE 7') != -1;
	t.isFirefox		= browser.indexOf('firefox') != -1;
	t.isGecko 		= browser.indexOf('gecko') != -1;
	t.isGecko18 	= browser.indexOf('Gecko') != -1 && browser.indexOf('rv:1.8') != -1;
	t.isSafari 		= browser.indexOf("safari") != -1;
	t.isKonqueror 	= browser.indexOf("konqueror") != -1;
	t.isOpera 		= (browser.indexOf('opera') != -1);
	t.isMac 		= browser.indexOf('mac') != -1;
	t.isNS7 		= browser.indexOf('netscape/7') != -1;
	t.isNS71 		= browser.indexOf('netscape/7.1') != -1;

	t.host = document.location.protocol+"//"+document.location.host;
	t.settings.host = t.host;

	t.setAttribute = function(name, value)
	{
		if(name == 'host')
		{
			return;
		};

		t.settings[name] = value;
	};

	t.getAttribute = function( name )
	{
		if( t.settings[name] )
		{
			return t.settings[name];
		} else
		{
			return false;
		};
	};
};

// px l�schen
_ptools.System.prototype.replaceEntity = function(ent)
{
	return parseInt(ent);
};
// Max H�he vom Windows
_ptools.System.prototype.getMaxHeight = function()
{
	if (window.innerHeight)
	{
		return window.innerHeight;
	} else if(document.body.clientHeight)
	{
		return document.body.clientHeight;
	} else
	{
		return 768;
	};
};
// Max H�he vom Windows
_ptools.System.prototype.getMaxWidth = function()
{
	if (window.innerHeight)
	{
		return window.innerWidth;
	} else
	{
		return document.body.clientWidth;
	};
};

_ptools.System.prototype.isInteger = function(s)
{
	return (s.toString().search(/^-?[0-9]+$/) == 0);
};

_ptools.System.prototype.hasScrollbar = function(oElm)
{
	if (oElm.clientHeight < oElm.scrollHeight)
	{
   		return true;
	} else
	{
		return false;
	};
};


// Scroll Position herausfinden
_ptools.System.prototype.getScrollXY = function()
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' )
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	};
	return [ scrOfX, scrOfY ];
};

// UTF 8 Encode
_ptools.System.prototype.encode_utf8 = function(rohtext)
{
	// dient der Normalisierung des Zeilenumbruchs
	rohtext = rohtext.replace(/\r\n/g,"\n");
	var utftext = "";
	for(var n=0; n<rohtext.length; n++)
	{
		// ermitteln des Unicodes des  aktuellen Zeichens
		var c=rohtext.charCodeAt(n);
		// alle Zeichen von 0-127 => 1byte
		if (c<128)
		{
			utftext += String.fromCharCode(c);
		} else if((c>127) && (c<2048))
		{
			// alle Zeichen von 127 bis 2047 => 2byte
			utftext += String.fromCharCode((c>>6)|192);
			utftext += String.fromCharCode((c&63)|128);
		} else
		{
			// alle Zeichen von 2048 bis 66536 => 3byte
			utftext += String.fromCharCode((c>>12)|224);
			utftext += String.fromCharCode(((c>>6)&63)|128);
			utftext += String.fromCharCode((c&63)|128);
		};
	};
	return utftext;
};

// UTF 8 Decode
_ptools.System.prototype.decode_utf8 = function(utftext)
{
	var plaintext = ""; var i=0; var c=c1=c2=0;
	// while-Schleife, weil einige Zeichen uebersprungen werden
	while(i<utftext.length)
	{
		c = utftext.charCodeAt(i);
		if (c<128)
		{
			plaintext += String.fromCharCode(c);
			i++;
		} else if((c>191) && (c<224))
		{
			c2 = utftext.charCodeAt(i+1);
			plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;
		} else
		{
			c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;
		};
	};
	return plaintext;
};

// Value pr�fen ob diese leer ist, wenn ja wird ein leerer String zur�ck gegeben
_ptools.System.prototype.checkValue = function( val )
{
	if(val && val != "")
	{
		return val;
	};

	return "";
};

// JavaScript Datei nachladen
_ptools.System.prototype.loadScript = function(__file__)
{
	var aScript = document.getElementsByTagName('script');
	var check = false;

	for(var i = 0, len = aScript.length; i < len; i++)
	{
		if(aScript[i].src == __file__ || aScript[i].src == this.host+__file__)
		{
			check = true;
			break;
		};
	};

	if(!check)
	{
		a = document.createElement('script');
		a.setAttribute('type','text/javascript');
		a.setAttribute('src',__file__);
		document.getElementsByTagName('head')[0].appendChild(a);
	};
};

// eine art var_dump - JavaScript Attribute eines Objektes
_ptools.System.prototype.getAttributesOfObj = function( obj )
{
	var str = '';
	for(i in obj)
	{
		str += i+'=>'+obj[i]+"\n";
	};

	return str;
};

_ptools.System.prototype.var_dump = function( obj )
{
	return this.getAttributesOfObj( obj );
};

// PHP URL Params bekommen
_ptools.System.prototype.getUrlParams = function( str )
{
	var str_ = str.split('?');
	str_ = str_[1].split('&');
	var r = new Array();

	for(var i = 0, len = str_.length; i < len; i++)
	{
		sp = str_[i].split('=');
		r[sp[0]] = sp[1];
	};

	return r;
};

// Input Value bei Focus löschen und wieder herstellen
_ptools.System.prototype.FieldFocus = function( InputField, FValue, SValue )
{
	var InputField = document.getElementById ( InputField );
	var _value = InputField.value;


	if(_value != '' && FValue != '  ')
	{
		SValue =_value;
	};

	if(InputField.value =='')
	{
		InputField.value = SValue;
	};

	if(InputField)
	{
		InputField.onfocus = function ()
		{
			if(InputField.value == SValue)
			{
				InputField.value = FValue;
			} else
			{
				InputField.select ();
			};

		};

		InputField.onblur = function ()
		{
			if(InputField.value == FValue)
			{
				InputField.value = SValue;
			};
		};
	};
};

_ptools.System.prototype.in_array = function( item, arr )
{
	for(p=0;p<arr.length;p++) if (item == arr[p]) return true;
	return false;
};

_ptools.System.prototype.empty = function( v )
{
	if(
		v == '' ||
		v == 0 ||
		v == '0' ||
		v == null ||
		v == false
	)
	{
		return true;
	};

	return false;
};


_ptools._System = new _ptools.System();

/**
 * Browser
 */

_ptools._Browser = {

	__constructor : function() {

		var t = this;

		var browser = navigator.userAgent.toLowerCase();
		t.isMSIE 		= (navigator.appName == "Microsoft Internet Explorer");
		t.isMSIE5 		= t.isMSIE && (navigator.userAgent.indexOf('MSIE 5') != -1);
		t.isMSIE5_0 	= t.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1);
		t.isMSIE6 		= t.isMSIE && (navigator.userAgent.indexOf('MSIE 6') != -1);
		t.isMSIE7 		= navigator.userAgent.indexOf('MSIE 7') != -1;

		t.isFirefox		= browser.indexOf('firefox') != -1;
		t.isGecko 		= browser.indexOf('gecko') != -1;
		t.isGecko18 	= browser.indexOf('Gecko') != -1 && browser.indexOf('rv:1.8') != -1;
		t.isSeamonkey	= browser.indexOf('seamonkey') != -1;

		t.isSafari 		= browser.indexOf("safari") != -1;
		t.isKonqueror 	= browser.indexOf("konqueror") != -1;
		t.isOpera 		= browser.indexOf('opera') != -1;
		t.isMac 		= browser.indexOf('mac') != -1;

		t.isNS7 		= browser.indexOf('Netscape/7') != -1;
		t.isNS71 		= browser.indexOf('Netscape/7.1') != -1;
	}
};
_ptools._Browser.__constructor();

/**
 * Types
 */

_ptools.String = function( string )
{
	var t = this;
	var _string = null;
	var _isMSIE = false;

	t.__constructor = function( string )
	{
		if(_ptools._Browser.isMSIE || _ptools._Browser.isKonqueror)
		{
			_isMSIE = true;
		};

		if(_isMSIE)
		{
			_string = new Array();
			_string[_string.length] = string;
		} else
		{
			_string = string;
		};
	};

	t.push = function( string )
	{
		if(_isMSIE)
		{
			 _string[_string.length] = string;
		} else
		{
			_string += string;
		};
	};

	t.get = function()
	{
		if(_isMSIE)
		{
			return _string.join("");
		} else
		{
			return _string;
		};
	};

	t.__constructor( string );
};

