﻿///<reference path="_intellisense.js" />

/* ******** USAGE DESCRIPTION ***********

### $OL ###

$OL holds all methods that should be executed after the document (and all javascripts)
are loaded this ensures that all required methods/objects are existing
Every list entry contains an array.
Parameters:
	[0] ... index to sort the list to be able to execute the commands in a controlled order
	[1] ... string or function that will be evaluated/executed
	[2] ... context/scope which will be referenced in the 'this' inside the called function
	[3] ... parameter list for the function
	[4] ... string that will be evaluated, if it returns false: the method won't be executed, optional
Example:
	$OL.push( [ 10, "CallMgr.Call", CallMgr, [ "972542384150", "972542384151" ] ] );

### $X ###

$X represents the Ajax interface
The ajax request can either been done using POST or GET, whereby the GET request could be cached if needed.
Parameters:
	url ............. the url to send the request to ($X.Url.Default, $X.Url.Call, ... or a custom)
	server_method ... which method should be called on the server
	params .......... the parameters sent to the server
		-) string
		-) array
		-) key-value-object (the value could also be an array)
	callback ........ the javascript method that should be called with the result from the ajax request
	usetoken ........ optional, enables/disables transmission of security token (default = true)
	async ........... optional, if the ajax-request should be asyncrounus or not (default = true)
Examples:
	$X.Post( $X.Url.Account, "CheckNicknameExistance", { nick : "roberkules" }, NickManager.NickCallBack.link( NickManager, nick ) ).Send();
	-> NickManager.NickCallBack( nick, ajax-result, success )
	$X.Get( $X.Url.Call, "GetRate", { from : "972542384150", to : "972542384175" }, CallMgr.ShowRate.link( CallMgr ), false ).Send();
	-> CallMgr.ShowRate( ajax-result, success ) -> this request could be cacheable
	$X.Get( "/ping.html", null, getCacheBuster(), function(r,ok){ alert(r); }, false ).Send( false );
	-> Gets the ping.html content syncrounusly, and alerts the result

*/



/* VARIABLES START */
var $d = document,
$b,
$un = "undefined",
$GA_url = $un == typeof $GA_url ? "" : $GA_url,
OLExecuted = false,
unknownDC,
chooseC,
dctimer = null,
myActiveTab,
specialDC = [ 39, 225, 228, 241, 250, 352 ],
$Tel,
CallMgr,
DestMgr,
ABMgr,
GroupMgr,
SmsMgr,
NrControlMgr,
AdsManager,
RedialManager,
RecentCallsRenderer,
DelayedCallListManager,
TabStrip,
ClickOnTab = false,
$notify = false;
/* VARIABLES END */



/* EXTEND METHODS FOR STRINGS, NUMBERS, ARRAYS AND OBJECTS START */
String.prototype.ltrim = function()
{
	return this.replace( /^\s+/g, "" );
};

String.prototype.rtrim = function()
{
	return this.replace( /\s+$/g, "" );
};

String.prototype.trim = function()
{
	return this.replace( /^\s+|\s+$/g, "" );
};

String.prototype.wrap = function( l )
{
	var reg = new RegExp( "(\\S{" + l + ",})", "g" );
	return this.replace( reg, function()
	{
		var r = "",
		s = arguments[0];
		while( s.length >  l)
		{
			r = r + s.substring( 0, l ) + "<wbr />";
			s = s.substring( l );
		}
		return r + s;
	} );
};

String.prototype.startsWith = Number.prototype.startsWith = function( s )
{
	return String( this ).substring( 0, String( s ).length ) == String( s );
};

Array.prototype.each = function()
{
	var args = $A(arguments),
	f = args.shift(),
	_this = args.shift();
	
	for( var i = 0, l = this.length; i < l; i++ )
	{
		f.apply( _this || this, [ this[ i ] ].concat( args ) );
	}
};

Array.prototype.hasKey = Object.prototype.hasKey = function( k )
{
	return $un != typeof( this[ k ] );
};

Array.prototype.contains = function( v )
{
	for( var i = 0, len = this.length; i < len; i++ )
	{
		if( this[i] == v )
		{
			return true;
		}
	}
	return false;
};

Array.prototype.clone = function( keepref )
{
	if( $un == typeof keepref )
	{
		keepref = false;
	}
	var arr;
	if( keepref )
	{
		arr = this.slice( 0 );
	}
	else
	{
		arr = [];
		for( var i = 0, len = this.length; i < len; i++ )
		{
			switch( typeof( this[i] ) )
			{
				case "object":
				case "array":
					arr.push( null == this[i] ? null : this[i].clone( keepref ) );
					break;
				default:
					arr.push( this[i] );
					break;
			}
		}
	}
	return arr;
};

Object.prototype.clone = function( keepref )
{
	if( $un == typeof( keepref ) )
	{
		keepref = false;
	}
	var o = {},
	k = GetKeys( this );
	for( var i = 0, len = k.length; i < len; i++ )
	{
		switch( typeof( this[k[i]] ) )
		{
			case "object":
			case "array":
				o[k[i]] = this[k[i]].clone( keepref );
				break;
			default:
				o[k[i]] = this[k[i]];
				break;
		}
	}
	return o;
};

function equals( a, b )
{
	if( typeof a != typeof b )
	{
		return false;
	}
	
	if( isFunction( a.toSource ) )
	{
		return a.toSource().toLowerCase() == b.toSource().toLowerCase();
	}
	
	if( isArray( a ) )
	{
		if( a.length != b.length )
		{
			return false;
		}
		for( var i = 0, l = a.length; i < l; i++ )
		{
			if( !equals( a[i], b[i] ) )
			{
				return false;
			}
		}
		return true;
	}
	
	if( isObject( a ) )
	{
		var k = GetKeys( a );
		
		if( !equals( k, GetKeys( b ) ) )
		{
			return false;
		}
		
		for( var i = 0, l = k.length; i < l; i++ )
		{
			if( !equals( a[k[i]], b[k[i]] ) )
			{
				return false;
			}
		}
		return true;
	}
	
	if( isFunction( a ) )
	{
		return a.toString() == b.toString();
	}
	
	return String( a ).toLowerCase() == String( b ).toLowerCase();
}

Function.prototype.link = function()
{
	var m = this,
	args = $A( arguments ),
	_this = args.shift();
	
	return function()
	{
		return m.apply( _this, args.concat( $A( arguments ) ) );
	};
};

Function.prototype.delay = function()
{
	var m = this,
	args = $A( arguments ),
	t = args.shift() || 1,
	_this = args.shift();
	
	return window.setTimeout( function() { m.apply( _this, args ); }, t );
};

function GetKeys( o )
{
	var k = [];
	for( var key in o )
	{
		if( o.hasOwnProperty( key ) )
		{
			k.push( key );
		}
	}
	return k;
}
/* EXTEND METHODS FOR STRINGS, NUMBERS, ARRAYS AND OBJECTS START */



/* FAKE TEXT MANAGER IF NOT EXISITNG */
if( typeof $T == $un )
{
	$T = function( id, v )
	{
		if( typeof TM != $un )
		{
			return TM.Get( id );
		}
		if( v )
		{
			return v;
		}
		else
		{
			return id.replace(/\./, " ");
		}
	}
}
/* END TEXT MANAGER */



/* EVENT MANAGER START
var EventManager = function()
{
	this.events = {};
}
EventManager.prototype =
{
	attach : function( o, e, f )
	{
		alert( "ole" );
	},
	
	detach : function( o, e, f )
	{
		
	},
	
	fire : function()
	{
	
	}
}
var Event = new EventManager();

var EventBroker = {
	events: {},
	invoke:function(eventKey, data) {
		var events = EventBroker.ensureEvents(eventKey);
		for(var i=0; i<events.length; ++i) {
			if(typeof(events[i])=="function") {
				events[i](data);
			}
		}
	},
	subscribe:function(eventKey, callback) {
		var events = EventBroker.ensureEvents(eventKey);
		events.push(callback);
	},
	ensureEvents:function(eventKey) {
		if(EventBroker.events[eventKey]==null)
			EventBroker.events[eventKey]=[];
		return EventBroker.events[eventKey];
	}
}
/* EVENT MANAGER END */



/* INIT START */
preload( "/images/animations/loading.gif" );

if ( $d.addEventListener )
{
	AttachEvent( $d, "DOMContentLoaded", OnContentLoad );
}
AttachEvent( window, "load", function(){ OnContentLoad(); OnLoad(); } );

function OnContentLoad()
{
	if( OLExecuted )
	{
		return;
	}
	
	OLExecuted = true;
	
	$b = $d.body;

	unknownDC = $T( "unknown.dialcode", "Invalid country code" );
	chooseC = $T( "country.choose", "Please select country" );

	TabStrip = new TabStripMgr();
	myActiveTab = 0;

	var init = [
		"PhoneNumberManager", function()
			{
				$Tel = new PhoneNumberManager();
			},
		"NrControlManager", function()
			{
				NrControlMgr = new NrControlManager();
			},
		"CallManager", function()
			{
				CallMgr = new CallManager( "CallMgr" );
			},
		"DestinationManager", function()
			{
				DestMgr = new DestinationManager();
			},
		"SmsManager", function()
			{
				SmsMgr = new SmsManager();
			},
		"ABManager", function()
			{
				ABMgr = new ABManager( "ABMgr" );
			},
		"GroupManager", function()
			{
				GroupMgr = new GroupManager( 'GroupMgr' );
			},
		"AdsMgr", function()
			{
				AdsManager = new AdsMgr();
			},
		"RedialMgr", function()
			{
				RecentCallsRenderer = new RecentCallsRendererMgr();
				RedialManager = new RedialMgr( "RedialManager", RecentCallsRenderer );
			},
		"ScheduleManager", function()
			{
				DelayedCallListManager = new ScheduleManager();
			},
		"clickHandler", function()
			{
				AttachEvent( $d, "click", clickHandler );
			}
	];
	
	for( var i = 0, len = init.length; i < len; i=i+2 )
	{
		if( eval( "$un != typeof(" + init[i] + ")" ) )
		{
			init[i+1]();
		}
	}
	
	ExecuteOL();
}

function OnLoad()
{
	if( CallMgr )
	{
		//PreLoadAnimations.delay( 5000, null );
	}
}

function ExecuteOL()
{
	if( $un == typeof( $OL ) )
	{
		return;
	}
	
	$OL.sort( function( a, b ){ return a[0] - b[0] } );
	
	for( var i = 0, len = $OL.length; i < len; i++ )
	{
		var valid = true;
		if( $OL[i].length > 4 )
		{
			try
			{
				valid = eval( $OL[i][4] );
			}
			catch( ex )
			{
				$Log( ex );
				valid = false;
			}
		}
		
		if( valid )
		{
			var f = eval( $OL[i][1] );
			if( isFunction( f ) )
			{
				f.apply( eval( $OL[i][2] ), $OL[i][3] || [] );
			}
		}
	}
	
	$OL = [];
}
/* INIT END */



/* AJAX START */
var Ajax = function()
{
	this.Methods =
	{
		Get : "GET",
		Post : "POST"
	};
	
	this.Timeout = 15; // in seconds
	
	this.Path = "/engine/ajax/";
	
	this.Url =
	{
		Account : this.Path + "account.ashx",
		Button : this.Path + "services/button.ashx",
		Call : this.Path + "services/call.ashx",
		Contacts : this.Path + "contacts.ashx",
		Default : this.Path + "default.ashx",
		Modal : this.Path + "ui/modal.ashx",
		Mobile : this.Path + "services/mobile.ashx",
		SMS: this.Path + "services/sms.ashx",
		Sync : this.Path + "sync.ashx"
	};
	
	this.defaultUrl = this.Url.Default;
	
	this.JSONDateRegex = new RegExp( "/Date\\((\\d+)([+-]\\d+)?\\)/", "gi" );
};

Ajax.prototype =
{
	Enabled : function()
	{
		return null != this.XHR();
	},
	
	XHR : function()
	{
		if( $un != typeof XMLHttpRequest )
		{
			return new XMLHttpRequest();
		}
		if( $un != typeof ActiveXObject )
		{
			try
			{
				return new ActiveXObject( "Msxml2.XMLHTTP" );
			}
			catch( e )
			{
			}
			
			try
			{
				return new ActiveXObject( "Microsoft.XMLHTTP" );
			}
			catch( e )
			{
			}
		}
		return null;
	},
	
	Send : function( method, url, server_func, params, cb, secure )
	{
		return new AjaxReq( this.XHR(), method, url, server_func, params, cb, secure, this );
	},
	
	Get : function()
	{
		return this.Send.apply( this, [ this.Methods.Get ].concat( $A( arguments ) ) );
	},
	
	Post : function()
	{
		return this.Send.apply( this, [ this.Methods.Post ].concat( $A( arguments ) ) );
	},
	
	ParseJSONDate : function( key, value )
	{
		if( null == value || !value.replace )
		{
			return value;
		}
		return this.JSONDateRegex.test( value ) ? new Date( parseInt( value.replace( this.JSONDateRegex, "$1" ) ) ) : value;
	}
};

function AjaxReq( xhr, method, url, server_func, params, cb, secure, base )
{
	this.base = base;
	this.XHR = xhr;
	this.method = method || this.base.Methods.Post;
	this.url = url || this.base.defaultUrl;
	this.server_func = server_func || "";
	this.params = params;
	this.cb = cb || null;
	this.secure = $un == typeof secure ? true : !!secure;
	this.cancelTimer = null;
	this.isTimeout = false;
}

AjaxReq.prototype =
{
	Send: function(async) {
		if (null == this.XHR) {
			return false;
		}

		if ($un == typeof async) {
			async = true;
		}

		try {
			this.XHR.open(this.method, this.url + this.GetQuery(), async);
			if (this.method == this.base.Methods.Post) {
				this.XHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			this.XHR.send(this.GetBody());

			var _this = this;
			this.cancelTimer = window.setTimeout(function() { _this.isTimeout = true; _this.XHR.abort(); }, this.base.Timeout * 1000);

			if (null != (this.cb || null)) {
				if (async) {
					this.OnStateChange.delay(1, this); // IE cache fix
					this.XHR.onreadystatechange = this.OnStateChange.link(this);
				}
				else {
					this.cb(this.GetResponse(), this.Ok());
					this.CleanUp();
				}
			}
		}
		catch (e) {
			this.CleanUp();
			return false;
		}

		return true;
	},

	OnStateChange: function() {
		if (null != this.XHR && 4 == this.XHR.readyState) {
			window.clearTimeout(this.cancelTimer);
			this.cb(this.GetResponse(), this.Ok());
			this.CleanUp();
		}
	},

	Ok: function() {
		var status = ((null != this.XHR ? this.XHR.status : null) || 0);
		return (200 <= status && 300 > status) || 1223 /* 204 in IE*/ == status;
	},

	GetQuery: function() {
		if (this.method == this.base.Methods.Get) {
			return ((this.url || this.base.defaultUrl).indexOf("?") > -1 ? "&" : "?") + this.GetParamQuery();
		}
		return "";
	},

	GetBody: function() {
		if (this.method == this.base.Methods.Post) {
			return this.GetParamQuery();
		}
		return "";
	},

	GetParamQuery: function() {
		var p = this.params,
		q = "_sf=" + this.server_func + (this.secure ? "&_sid=" + (typeof $sid != $un ? $sid : "") : "");

		if (null == p) {
			return q;
		}

		if (isArray(p)) {
			for (var i = 0, l = p.length; i < l; i++) {
				q += this.Prefix(q) + "_p=" + urlEncode(this.ToString(p[i]));
			}
		}
		else if (isObject(p)) {
			var k = GetKeys(p);
			for (var i = 0, l = k.length; i < l; i++) {
				if (null != p[k[i]] && isArray(p[k[i]]) && p[k[i]].length > 0) {
					q += this.Prefix(q) + this.ToString(p[k[i]], urlEncode(k[i]));
				}
				else {
					q += this.Prefix(q) + urlEncode(k[i]) + "=" + urlEncode(this.ToString(p[k[i]]));
				}
			}
		}
		else {
			q += ("" == q ? "" : "&") + this.ToString(p);
		}

		return q;
	},

	Prefix: function(q) {
		return ("" == q || q.match(/(\&|\?)$/i)) ? "" : "&";
	},

	ToString: function(v, n) {
		if (null == v) {
			return "";
		}
		if (isArray(v)) {
			var q = "";
			for (var i = 0, l = v.length; i < l; i++) {
				q += this.Prefix(q) + (n || "_p") + "=" + urlEncode(this.ToString(v[i]));
			}
			return q;
		}
		if (isFunction(v.toString)) {
			return v.toString();
		}
		return v;
	},

	GetResponse: function() {
		if (!this.Ok()) {
			if (403 == this.XHR.status) {
				var modal = /.+\(m:(.*)\)$/.exec(this.XHR.responseText);
				if (null != modal) {
					$M.Show(modal[1]);
				}
			}
			return this.isTimeout ? "timeout" : this.XHR.statusText;
		}

		if (204 == this.XHR.status || 1223 /* 204 in IE */ == this.XHR.status) {
			return "";
		}

		var ctype = this.XHR.getResponseHeader("Content-type");
		if (null != ctype && ctype.match(/^application\/json(;.*)?$/i)) {
			var re = null;
			hack = "while(1){};";
			txt = this.XHR.responseText.startsWith(hack) ? this.XHR.responseText.substring(hack.length) : this.XHR.responseText;

			try {
				re = txt.parseJSON(this.base.ParseJSONDate.link(this.base));
			}
			catch (ex) {
				//$Log( ex.message, location.href, "$X.GetResponse" );
				try {
					re = Eval(txt);
				}
				catch (ex) {
					$Log(ex.message, location.href, "$X.GetResponse");
				}
			}
			return re;
		}

		return this.XHR.responseText;
	},

	EmptyFunc: function() {
	},

	CleanUp: function() {
		if (null == this.XHR) {
			return;
		}
		// kill this xhr-object
		this.XHR.onreadystatechange = this.EmptyFunc;
		this.XHR = null;
	}
};

var $X = new Ajax();
/* AJAX END */



/* CHECK FOR SUPPORTED BROWSER START */
(function()
{
	if( -1 == window.location.href.indexOf( "\/mini" ) && "?nr" != window.location.search )
	{
		var bot = [ "bot", "yahoo", "crawler" ],
		nav = window.navigator;
		
		if( nav )
		{	
			for( var i=0, l=bot.length; i<l; i++ )
			{
				if( nav.userAgent.indexOf( bot[i] ) > -1 )
				{
					return;
				}
			}
		}
		
		if( !$X.Enabled() )
		{
			redirect( "http://mobile.jajah.com/" );
		}
	}
})();
/* CHECK FOR SUPPORTED BROWSER END */



/* GENERAL ERROR LOGGING START */
function $Log( msg, url, line, stack )
{
	// try/catch only needed because the 'new Image' breaks the vs2008-intellisense
	try
	{
		var a = $A( arguments );
		if( 1 == a.length )
		{
			msg = a[0].message;
			url = a[0].fileName;
			line = a[0].lineNumber;
			stack = a[0].stack;
		}
		
		var i = new Image();
		i.src = "/engine/log4js.ashx?msg=#m#&url=#u#&line=#l#&stack=#s#".replace( /#m#/, urlEncode( msg ) ).replace( /#u#/, urlEncode( url ) ).replace( /#l#/, urlEncode( line ) ).replace( /#s#/, urlEncode( stack ) );
		return false;
	}
	catch( e )
	{
	}
}
window.onerror = $Log;
/* GENERAL ERROR LOGGING END */



/* DOM METHODS START */
function el( id )
{
	return "string" == typeof( id ) ? $d.getElementById( id ) : id;
}

function create( tag )
{
	return $d.createElement( tag );
}

function elByTag( o, t )
{
	if( null == ( o = el( o || document.body ) ) )
	{
		return [];
	}
	return $A( o.getElementsByTagName( t ) );
}

function setText( c, t )
{
	var o = el( c );
	if( null == o )
	{
		return;
	}
	
	if( "clear" == t )
	{
		t = "";
	}

	if( "" == t.replace( /[\s]/g, "" ) )
	{
		t = "";
	}

	if( t != o.innerHTML )
	{
		o.innerHTML = t;
	}

	o.style.display = ( "" == t ? "none" : "" );
		
	if( "infobox" == c || "lowerinfobox" == c )
	{
		o = el( c + "line" );
		if( null != o )
		{
			o.style.display=(t==""?"none":"");
		}
	}
}

function isVisible( o )
{
	o = el( o );
	if( null == o )
	{
		return false;
	}
	return( ( "none" != o.style.display ) || ( o.getAttribute( "isVisible" ) && "true" == o.getAttribute( "isVisible" ) ) );
}

function $html( o, h )
{
	return $mod.apply( this, [ function( o ){ o.innerHTML = h || ""; } ].concat( [ o ] ) );
}

function $show()
{
	return $tog.apply( this, $A( arguments ).concat( [ true ] ) );
}

function $hide( id )
{
	return $tog.apply( this, $A( arguments ).concat( [ false ] ) );
}

function $tog()
{
	var args = $A( arguments ),
	show = args.pop();
	
	return $s.apply( this, args.concat( [ "display", show ? "" : "none" ] ) );
}

function $class( o, css )
{
	return $mod.apply( this, [ function( o ){ o.className = css; } ].concat( [ o ] ) );
}

function $s( o, k, s )
{
	///<summary>sets a style of an element</summary>
	///<param name="o" type="domElement|String">the element to apply the style to, or an id of an element</param>
	///<param name="k" type="String">the style key</param>
	///<param name="v" type="String">the style value</param>
	///<returns type="domElement" mayBeNull="true">the passed element to immediately use it again</returns>
	
	o = $A( arguments ),
	v = o.pop(),
	k = o.pop();
	
	return $mod.apply( this, [ function( o ){ o.style[ fixStyle( k ) ] = v; } ].concat( o ) );
	
	function fixStyle( n )
	{
		if( "float" == n )
		{
			// float x-browser-compatibility
			// ie : styleFloat
			// def: cssFloat
			return $un != typeof create( "DIV" ).style.styleFloat ? "styleFloat" : "cssFloat";
		}
		if( n.indexOf( "-" ) > -1 )
		{
			return n.replace( /-./gi, function( match )
			{
				return match.substr( 1 ).toUpperCase();
			});
		}
		return n;
	}
}

function $mod()
{
	var o = $A( arguments ),
	f = o.shift();
	
	for( var i = 0, len = o.length; i < len; i++ )
	{
		o[i] = el( o[i] );
		if( null != o[i] )
		{
			f( o[i] );
		}
	}
	
	return 1 == o.length ? o[0] : o;
}
/* DOM METHODS END */



/* CHECK FOR EXISTANCE... START */
function isFunction( f )
{
	return "function" == typeof f;
}

function isObject( o )
{
	return o && "object" == typeof o;
}

function isArray( o )
{
	return $un != typeof o && [].constructor == o.constructor;
}
/* CHECK FOR EXISTANCE... END */



/* MISC START */
function $A( a )
{
	if( !a )
	{
		return [];
	}
	
	if( a.toArray )
	{
		return a.toArray();
	}
	
	if( $un != typeof a.length )
	{
		try
		{
			return Array.prototype.slice.call( a, 0 );
		}
		catch( ex )
		{
			var r = [];
			for( var i = 0, l = a.length; i < l; i++ )
			{
				r.push( a[i] );
			}
			return r;
		}
	}
	
	return [ a ];
}

function fixE( e )
{
	return e || window.event;
}

function Eval( s )
{
	return eval( '(' + s.replace( /\r|\n/g, ' ' ) + ')' );
}

function urlEncode( s )
{
	if( encodeURIComponent )
	{
		return encodeURIComponent( s );
	}
	return encode( s );
}

function encode( t )
{
	return t.replace( /\"/, "&quot;" ).replace( /</, "&lt;" ).replace( />/, "&gt;" );
}

function redirect( url )
{
	window.location.href = url;
}

function foc( o )
{
	if( "string" == typeof( o ) )
	{
		o = el( o );
	}

	if( null != o )
	{
		if( $un != typeof focTimer && null != focTimer )
		{
			window.clearTimeout( focTimer );
			focTimer = null;
		}
		focTimer = setfocus.delay( 400, null, o );
	}
}

function setfocus( o )
{
	if( $un == typeof( o ) || null == o || $un == typeof( o.focus ) )
	{
		return;
	}
	o.focus();
}

function getMouseXY( e )
{
	e = fixE(e);
	if( $un != typeof( e.pageX ) )
	{
		return { x : e.pageX, y : e.pageY };
	}
	else if( e.clientX )
	{
		return { x : ( e.clientX + document.documentElement.scrollLeft ), y : ( e.clientY + document.documentElement.scrollTop ) };
	}
	return { x : 0, y : 0 };
}

function _parseFloat( v, g, d )
{
	return parseFloat( v.replace( eval( "/\\"+g+"/" ), "" ).replace( eval( "/\\" + d + "/" ), "." ) );
}

function CryptNumber( nr )
{
	return nr.substr( 0, 3 ) + "<span></span>" + nr.substr( 3 );
}

function onlyDigits( e, o, plusAllowed, extAllowed, numOnly )
{
	if( e.ctrlKey || e.altKey || e.metaKey )
	{
		return true;
	}

	var chars = ( numOnly ? "" : "- ,./\()" ) + "0123456789",
	key = e.which || e.keyCode;
	
	var ok = ( isSpecialKey( key ) || ( plusAllowed && key == 43 && o.value.indexOf( '+' ) == -1 ) || ( extAllowed && key == 120 && o.value.indexOf('x') == -1 ) || chars.indexOf( String.fromCharCode( key ) ) > -1 );
	
	if( !ok )
	{
		preventDefaultEvent( e );
	}
	
	return ok;
}

function isSpecialKey( k )
{
	return ( "|" + [ 8, 9, 13, 17, 18, 35, 36, 37, 38, 39 ].join( "|" ) + "|" ).indexOf( "|" + k + "|" ) > -1;
}

function CustomSubmit( f, url, method, target )
{
	var a = f.action,
	t = f.target,
	m = f.method;
	
	f.action = url;
	f.target = $un == typeof( target ) ? t : target;
	f.method = method;
	
	f.submit();
	
	f.action = a;
	f.target = t;
	f.method = m;
	
	return false;
}

function pop( u, n, w, h, s, r )
{
	if( $un == typeof( s ) )
	{
		s = true;
	}
	if( $un == typeof( r ) )
	{
		r = false;
	}
	( window.open( u, n, "width=" + w + ",height=" + h + ",resizable=" + ( r ? "yes" : "no" ) + ",scrollbars=" + ( s ? "yes" : "no" ) ) ).focus();
}

function togSWF( v, p )
{
	$s.apply( this, $swf( p || null ).concat( [ "visibility", v ? "visible" : "hidden" ] ) );
}

function $swf( p )
{
	return elByTag( p || $d.body, "OBJECT" ).concat( elByTag( p || $d.body, "EMBED" ) );
}
/* MISC END */



/* IMAGE PRELOADING START */
function preload( s )
{
	// try/catch only needed because the 'new Image' breaks the vs2008-intellisense
	try
	{
		if( $un == typeof( pre ) )
		{
			pre = [];
		}
		var img = new Image();
		img.src = s;
		pre.push( img );
	}
	catch( e )
	{}
}
function PreLoadAnimations()
{
	var ba = [ "call.gif", "call-2.gif", "call-3.gif" ];
	if( CallMgr.IsLoggedIn )
	{
		ba.push( "send_1.png", "send_2.png", "send_3.png", "set_green_1.gif", "set_green_2.gif", "set_green_3.gif", "set_orange_1.png", "set_orange_2.png", "set_orange_3.png" );
	}
	
	for( var i = 0; i < ba.length; i++ )
	{
		preload( "/images/en/" + ba[i] );
	}
	
	var ia = [ "phone_1.gif", "phone_2.gif", "laeuten_1.gif", "ruhend_2.gif", "connect_call.gif", "call_globe.gif", "abheben_1.gif", "laeuten_2.gif", "abheben_2.gif", "active_call.gif", "auflegen_1.gif", "besetzt_1.gif", "besetzt_2.gif", "auflegen_2.gif" ];
	if( CallMgr.IsLoggedIn )
	{
		ia.push( "sms_1.gif", "sms_2.gif", "sms_call.gif" );
	}
	
	for( var i = 0; i < ia.length; i++ )
	{
		preload( "/images/animations/" + ia[i] );
	}
}
/* IMAGE PRELOADING END */



/* LOADING START */
function ShowLoader( css, container )
{
	var l = '<div' + ( null != css ? ' class="' + css + '"' : ' style="margin:6px 0px;"' ) + ' align="center"><div class="loading">loading</div></div>';
	if( container )
	{
		return $html( container, l );
	}
	else
	{
		$d.write(l);
	}
}
/* LOADING END */



/* LANGUAGE SELECTION START */
function LanguageMgr()
{
	this.timer = null;
	this.id = "langlist";
	this.opened = false;
}

LanguageMgr.prototype =
{
	Open : function()
	{
		if( this.opened )
		{
			return;
		}
		
		$show( this.id );
		this.opened = true;
		fade( el( this.id ), 0, 100, 10, 5, null );
	},
	
	Close : function()
	{
		fade( el( this.id ), 100, 0, 10, 5, ( function(){ $hide( this.id ); this.opened = false; } ).link( this ) );
	},
	
	MouseOut : function()
	{
		if( this.opened )
		{
			this.timer = this.Close.delay( 500, this );
		}
	},
	
	MouseOver : function()
	{
		if( null != this.timer )
		{
			window.clearTimeout( this.timer );
			this.timer = null;
		}
	}
}
var LangMgr = new LanguageMgr();
/* LANGUAGE SELECTION END */



/* AJAX HELPER START */
function ExecuteAjaxJS(t)
{
	var regex = new RegExp( "<script[^>]*>(.*?)</scr"+"ipt>", "gi" ),
	res;
	while( res = regex.exec(t) )
	{
		try
		{
			eval( RegExp.$1 );
		}
		catch( e )
		{
		}
	}
}
function CleanAjaxJS(t)
{
	return t.replace( new RegExp( "<script[^>]*>(.*?)</scr"+"ipt>", "gi" ), "" );
}
/* AJAX HELPER END */



/* MESSAGES START */
function $msg( msg, typ, line, link, cont )
{
	var html = ( line ? '<div class="cboxline">&nbsp;</div>' : '' ) + '<div class="content">{link}<table cellpadding="0" cellspacing="0" width="100%"><tr><td class="infoimg"><img src="/images/icons/{img}" width="25" height="25" alt="" /></td><td>' + ( /^(error|e)$/.test( typ ) ? '<div class="jbx info"><div><div class="tl"><div class="tr"><div class="tm"></div></div></div></div><div class="ml"><div class="mr"><div style="padding: 2px 8px;" class="m">{msg}</div></div></div><div><div class="bl"><div class="br"><div class="bm"></div></div></div></div></div>' : '<div class=\"infomsg\">{msg}</div>' ) + '</td></tr></table></div>',
	img;

	switch( typ )
	{
		case "error":
		case "e":
			img = "fehler.gif";
			break;
		case "jajah":
		case "j":
			img = "jajah.gif";
			break;
		case "buddy":
		case "b":
			img = "buddy.gif";
			break;
		case "info":
		case "i":
		default:
			img = "hinweis.gif";
			break;
	}
	
	var l = "";
	if( null != link && "" != link )
	{
		l = '<div style="float:right;"><b class="bluebtn-li">&nbsp;</b><a href="{href}" class="bluebtnlink">{name}</a><b class="bluebtn-re">&nbsp;</b></div>'.replace( /\{href\}/g,link.href ).replace( /\{name\}/g, link.name );
	}
	html = html.replace( /\{msg\}/g, msg ).replace( /\{img\}/g, img ).replace( /\{link\}/g, l );
	if( $un != typeof( cont ) && null != cont )
	{
		cont = el( cont );
		cont.innerHTML = html;
		cont.style.display = "";
	}
	return html;
}
/* MESSAGES END */



/* EVENTS START */
function ExecuteWhenLoaded( requiredobj, call, t )
{
	var exist = false;
	t = t || 250;
	
	try
	{
		exist = $un != typeof( eval( requiredobj ) );
	}
	catch(e)
	{
	}
	
	if( !exist )
	{
		ExecuteWhenLoaded.delay( t, null, requiredobj, call, t );
	}
	else
	{
		if( isFunction( call ) )
		{
			call();
		}
		else
		{
			eval( call );
		}
	}
}
function ExecuteWhenRendered( element, call )
{
	if( null == el( element ) )
	{
		ExecuteWhenRendered.delay( 250, null, element, call );
	}
	else
	{
		if( isFunction( call ) )
		{
			call();
		}
		else
		{
			eval( call );
		}
	}
}
function LoadScript( src, id )
{
	var script = el( id );
	if( null == script )
	{
		script = create( "SCRIPT" );
		if( $un != id )
		{
			script.id = id;
		}
	}
	else if( src == script[ "relsrc" ] )
	{
		return;
	}
	script.src = src;
	script[ "relsrc" ] = src;
	script.type = "text/javascript";
	elByTag( $d, "head" )[0].appendChild( script );
}
function AttachEvent( o, e, f )
{
	if( "submit" == e )
	{
		var f2 = o.onsubmit;
		
		if( isFunction( f2 ) )
		{
			o.onsubmit = function( e ){ f2(); f(); };
		}
		else
		{
			o.onsubmit = f;
		}
	}
	else if( o.addEventListener )
	{
		o.addEventListener( e, f, false );
	}
	else
	{
		o.attachEvent( "on" + e, f );
	}
}
function DetachEvent( o, e, f )
{
	if( o.removeEventListener )
	{
		o.removeEventListener( e, f, false );
	}
	else
	{
		o.detachEvent( "on" + e, f );
	}
}
function getEventSource( e )
{
	e = fixE( e );
	return e.target || e.srcElement;
}
function preventDefaultEvent( e )
{
	e = fixE( e );

	e.returnValue = false;

	stopBubble( e );

	if( e.preventDefault )
	{
		e.preventDefault();
	}
	return false;
}
function stopBubble( e )
{
	if( e.stopPropagation )
	{
		e.stopPropagation();
	}
	else if( $un != typeof( e.cancelBubble ) )
	{
		e.cancelBubble = true;
	}
}
function Notify( start, cid, nid ) // cid = content placeholder id, nid = notification placeholder id
{
	$notify = start;
	if( cid )
	{
		notifyDefContent = cid;
		notifyArea = nid;
	}
	if( start )
	{
		DisLinks();
		$show( notifyArea );
		$hide( notifyDefContent );
	}
	else if( $un != typeof( notifyArea ) )
	{
		$hide( notifyArea );
		$show( notifyDefContent );
	}
}
function DisLinks()
{
	var l = document.links;
	for( var i = 0, len = l.length; i < len; i++ )
	{
		if( $un != typeof( l[i].defOnClick ) )
		{
			continue;
		}
		
		l[i].defOnClick = l[i].onclick;
		l[i].onclick = function()
		{
			this.onclick = this.defOnClick;
			if( isFunction( this.onclick ) )
			{
				Notify( false );
				return this.onclick();
			}
		}
	}
}

function $track( url )
{
	try
	{
		if( window.GAT )
		{
			window.GAT._trackPageview( url );
		}
	}
	catch(ex)
	{
	}
}
/* EVENTS END */



/* FADING MANAGER START */
function FadeManager()
{
	this.container = null;
	this.step = 5;
	this.delay = 20;
	this.pause = 4000;
	this.index = 0;
	this.texts = [];
}

FadeManager.prototype =
{
	add : function( txt )
	{
		this.texts.push( txt );
	},

	transform : function()
	{
		this.index++;
		if( this.index >= this.texts.length )
		{
			this.index = 0;
		}
		this.fadeOut();
	},

	fadeOut : function()
	{
		fade( this.container, 100, 0, this.step, this.delay, ( function(){ this.fadeIn(); } ).link( this ) );
	},
	
	fadeIn : function()
	{
		this.container.innerHTML = this.texts[this.index];
		fade( this.container, 0, 100, this.step, this.delay, ( function(){ this.transform.delay( this.pause, this ) } ).link( this ) );
	}
};

function fade( o, as, ae, st, t, cb ) // object, alpha-start, alpha-end, step, time-delay, callback
{
	var na = as > ae ? as - st : as + st;	// new alpha
	if( !isArray( o ) )
	{
		o = [ o ];
	}
	for( var i = 0, len = o.length; i < len; i++ )
	{
		setOpacity( o[i], na );
	}
	if( ( ae < as && na <= ae ) || ( ae > as && na >= ae ) )
	{
		if( null != cb )
		{
			cb();
		}
	}
	else
	{
		fade.delay( t, this, o, na, ae, st, t, cb );
	}
}

function setOpacity( o, val )
{
	if ( 100 == val )
	{
		[ "opacity", "MozOpacity", "KhtmlOpacity", "filter" ].each( function( key )
		{
			if( o.style.removeProperty )
			{
				o.style.removeProperty( key );
			}
			else
			{
				o.style.removeAttribute( key, false );
			}
		});
	}
	else
	{
		o.style.opacity = ( val / 100 );
		o.style.MozOpacity = ( val / 100 );
		o.style.KhtmlOpacity = ( val / 100 );
		o.style.filter = "alpha(opacity=" + val + ")";
	}
	return o;
}
/* FADING MANAGER END */


/* TOOLTIP MANAGER START */

function ToolTipMgr()
{
	this.template = '<div class="tl"><div class="tr"><div class="tm">%t%</div></div></div><div class="ml"><div class="mr"><div class="m">%h%</div></div></div><div class="bl"><div class="br"><div class="bm">%tip%</div></div></div>';
	this.list = {};
	this.open = null;
	this.timer = null;
}

ToolTipMgr.prototype =
{
	Cfg : function( title, html, parent, tip, size, fade )
	{
		return {
			title:	 title,
			html:	 html,
			parent:	 parent,
			tip:	 tip,
			size:	 size,
			fade:	 fade
		};
	},
	
	Add : function( name, cfg )
	{
		this.list[ name ] =
		{
			title:	 cfg.title,
			html:	 cfg.html,
			parent:  cfg.parent,
			tip:	 { show : cfg.tip ? cfg.tip.show : false, xpos : cfg.tip ? ( cfg.tip.xpos ? cfg.tip.xpos : null ) : null },
			size:	 cfg.size,
			fade:	 cfg.fade,
			obj:	 null
		};
	},
	
	Show : function( name, cfg )
	{
		this.timer = ( function( name, cfg )
		{
			if( !this.list.hasKey( name ) )
			{
				if( !cfg )
				{
					return;
				}
				this.Add( name, cfg );
			}
			
			this.Draw( name );
		} ).delay( 300, this, name, cfg );
	},
	
	Hide : function( name )
	{
		if( this.timer != null )
		{
			window.clearTimeout( this.timer );
		}
		
		this.timer = ( function( name )
		{
			if( this.list.hasKey( name ) )
			{
				var tt = this.list[ name ];
				if( tt.fade )
				{
					fade( tt.obj, 100, 0, 4, 20, $hide.link( this, tt.obj ) );
				}
				else
				{
					$hide( tt.obj );
				}
			}
		} ).delay( 300, this, name );
	},
	
	Draw : function( name )
	{
		if( !this.list.hasKey( name ) )
		{
			return;
		}
		
		var tt = this.list[ name ];
		
		if( null != tt.obj )
		{
			if( !isVisible( tt.obj ) )
			{
				if( this.fade )
				{
					setOpacity( tt.obj, 0 );
				}
				
				$show( tt.obj );
				
				if( tt.fade )
				{
					fade( tt.obj, 0, 100, 4, 20, null );
				}
			}
			return;
		}
		
		var n = $class( create( "div" ), "bln" );

		n.innerHTML = this.template.replace( /%t%/, tt.title ).replace( /%h%/, tt.html ).replace( /%tip%/, tt.tip.show ? '<div class="tip"' + ( null != tt.tip.xpos ? ' style="left:' + tt.tip.xpos + 'px;"' : '' )  + '></div>' : '' );

		if( tt.size )
		{
			var s = GetKeys( tt.size );
			for( var k in s )
			{
				n.style[s[k]] = tt.size[s[k]] + "px";
			}
		}
		
		if( tt.tip.show )
		{
			n.style.paddingBottom = "12px";
		}
		
		tt.obj = n;
		
		if( tt.fade )
		{
			setOpacity( n, 0 );
		}
		
		el( tt.parent ).appendChild( n );
		
		if( tt.fade )
		{
			fade( n, 0, 100, 4, 20, null );
		}
		
		return n;
	}
};

var $TT = new ToolTipMgr();

/* TOOLTIP MANAGER END */



/* NEEDS TO BE REWRITTEN START */

/* TABSTRIP START */
function TabStripMgr()
{
    this.tabsList = [
		0,
		0,
		0,
		0
	];
    
    this.regTab = function( ix )
    {
		this.tabsList[ix] = 1;
	};
	
    this.nextTab = function( ix )
    {
		for( var i = ix + 1, len = this.tabsList.length; i < len; ++i )
		{
			if( 1 == this.tabsList[i] )
			{
				return i;
			}
		}
		return -1;
	};

	this.prevTab = function( ix )
	{
		for( var i = ix - 1; i >= 0; --i )
		{
			if( 1 == this.tabsList[i] )
			{
				return i;
			}
		}
		return -1;
	};

	this.init = function()
	{
		var tabObj;
		for( var i = 0; i < 4; ++i )
		{
			tabObj = el( "mytab" + i + "x1" );
			if( null != tabObj )
			{
				this.tabsList[i] = 1;
			}
		}
	};
}
function showMyTab( tabid )
{
	if (ClickOnTab==false && tabid!=4)
	{ 
	    var str = document.cookie;
	    ClickOnTab = true;
	    if (str.indexOf("tabClick")<0)
	    {
	      document.cookie="tabClick=true;Path=/members/";
	    }
	}
	if( tabid == myActiveTab )
	{
		return;
	}
	
	var c = elByTag( "MyTabContainer", "div" );
	
	for( var i = 0, len = c.length; i < len; i++ )
	{
		var id = c[i].id;
		if( $un != typeof( id ) && "MyTab" == id.substring( 0, 5 ) )
		{
			c[i].style.display = parseInt( id.substring( 5, id.length ) ) == tabid ? "" : "none";
		}
	}
	
	if( myActiveTab > -1 )
	{
		if( myActiveTab > 0 && -1 != TabStrip.prevTab( myActiveTab) ) //set the right gif of the previous tab
		{
			$class( "mytab" + TabStrip.prevTab( myActiveTab ) + "x3", "headtab2-r" );
		}
		$class( "mytab" + myActiveTab + "x1", "headtab2-l" );
		$class( "mytab" + myActiveTab + "x2", "headtab2" );
		$class( "mytab" + myActiveTab + "x3", "headtab2-r" );
		$hide( "tabText" + ( myActiveTab + 1 ) );
	}
	
	if( tabid > 0 && -1 != TabStrip.prevTab( tabid ) )
	{
		$class( "mytab" + TabStrip.prevTab( tabid ) + "x3", "headtab2" ); //set the right gif of the previous tab
	}
	$class( "mytab" + tabid + "x1", "headtab-l" );
	$class( "mytab" + tabid + "x2", "headtab" );
	$class( "mytab" + tabid + "x3", "headtab-r" );
	$show( "tabText" + ( tabid + 1 ) );
	myActiveTab = tabid;
}
/* TABSTRIP END */

/* NEEDS TO BE REWRITTEN END */

function sealMe( sID ) //Verisign Seal
{
	var div = el(sID);
	
	if( null != div )
	{
		var ifr = create( "iframe" ),
		q = "?l=" + $T( "l", "en" );
		ifr.id = sID + "_seal2";
		ifr.width = 100;
		ifr.height = 72;
		ifr.scrolling = "no";
		ifr.frameBorder = "0";
		ifr.style.border = "none";
		ifr.src = "https://secure.jajah.com/payment/verisign.html" + q;
		
		div.innerHTML = "";
		div.appendChild( ifr );
	}
}



/* MODAL START */
function Modal()
{
	this.timer = null;
	this.modals = [];
	this.OnWinResize = this.onresize.link( this );
	this.bg = "modalbg";
	this.useiframe = !!window.attachEvent;
	this.iframe = this.bg + "iframe";
	this.opacity = 65;
	this.$cached = {};
	this.cacheprefix = "mod__";
	this.OnShow = null;
}

Modal.prototype =
{
	DefaultLayout : function( b, w )
	{
		///<summary>Create default Layout, just the inner Body needs to be set</summary>
		///<param name="b" type="String">the inner HTML</param>
		///<param name="w" type="Number" integer="true" optional="true">width of the modal dialog</param>
		///<returns type="domElement">the default-styled modal dialog element</returns>
		
		var m = $class( create( "DIV" ), "defmodal" ),
		close = $html( $class( create( "DIV" ), "close" ), '<a href="#" onclick="$M.Close();return false;">Close</a>' ),
		body = $s( $html( create( "DIV" ), b ), "padding", "10px" );
		
		if( $un != typeof w )
		{
			$s( m, "width", w + "px" );
		}
		
		m.appendChild( close );
		m.appendChild( body );
		
		return m;
	},
	
	Create : function( body, fadein, replacelast, params )
	{
		this.CreateBg();
		
		var b = create( "DIV" );
		$class( b, "modal" );

		if( "string" == typeof body )
		{
			if( $un != typeof params && isObject( params ) )
			{
				var k = GetKeys( params );
				for( var i = 0, l = k.length; i < l; i++ )
				{
					var reg = new RegExp( "{" + k[i] + "}", "gi" );
					body = body.replace( reg, params[k[i]] );
				}
				body = body.replace( /{[^}]*}/g, "" );
			}
			b.innerHTML = body;
		}
		else
		{
			b.appendChild( body );
		}
		
		window.scrollTo( 0, 0 );
		togSWF( false );
		
		if( this.HasOpenModal() )
		{
			if( replacelast )
			{
				this.RemoveLast();
			}
			else	
			{
				$hide( this.modals[ this.modals.length - 1 ] );
			}
		}
		else
		{
			AttachEvent( window, "resize", this.OnWinResize );
		}
		
		if( $un == typeof fadein || fadein )
		{
			$d.body.appendChild( setOpacity( b, 0 ) );
			fade( b, 0, 100, 15, 8, null );
		}
		else
		{
			$d.body.appendChild( b );
		}
		
		this.modals.push( b );
		
		return this;
	},
	
	CreateBg : function()
	{
		if( null != el( this.bg ) )
		{
			if( !this.HasOpenModal() )
			{
				this.onresize();
			}
		}
		else
		{
			var o = create( "DIV" ),
			s = getPageSize();
			
			o.id = this.bg;
			o.style.width = s.pw + "px";
			o.style.height = s.ph + "px";
			
			var o2 = o.cloneNode( false );
			
			if( this.useiframe )
			{
				var i = create( "IFRAME" );
				i.src = "/blank.html";
				//i.border = i.frameBorder = "0";
				
				o2.id = this.iframe;
				o2.appendChild( i );
				$d.body.appendChild( setOpacity( o2, 0 ) );
			}
			
			$d.body.appendChild( setOpacity( o, this.opacity ) );
		}
	},
	
	HasOpenModal : function()
	{
		return this.modals.length > 0;
	},
	
	RemoveLast : function()
	{
		var box = this.modals.pop();
		$swf( box ).each( function( o ){ o.parentNode.removeChild( o ); } );
		box.parentNode.removeChild( box );
	},
	
	Close : function()
	{
		this.RemoveLast();
		if( this.HasOpenModal() )
		{
			$show( this.modals[ this.modals.length - 1 ] );
		}
		else
		{
			DetachEvent( window, "resize", this.OnWinResize );
			$hide( this.bg );
			$hide( this.iframe );
			togSWF( true );
		}
	},
	
	onresize : function()
	{
		if( null != this.timer )
		{
			window.clearTimeout( this.timer );
			this.timer = null;
		}
		
		var a = [ el( this.iframe ), el( this.bg ) ];
		if( null != a[1] )
		{
			this.timer = (function()
			{
				this.each( $hide );
				(function()
				{
					var s = getPageSize();
					for( var i = 0; i < 2; i++ )
					{
						if( null != this[i] )
						{
							this[i].style.width = s.pw + "px";
							this[i].style.height = s.ph + "px";
						}
					}
					this.each( $show );
				}).delay( 1, this );
			}).delay( 50, a );
		}
	},
	
	Load : function( n, s, params, replacelast )
	{
		///<summary>Loads a modal from the server</summary>
		///<param name="n" type="String">the modal identifier</param>
		///<param name="s" type="Boolean">if true it will be shown, otherwise just preloaded</param>

		$X.Get( $X.Url.Modal, "GetModal", { id : n, l : $T( "l", "en" ) }, this.GetResult.link( this, n, s, params, replacelast ), false ).Send();
	},
	
	GetResult : function( n, s, params, replacelast, re, ok )
	{
		if( ok && re.length > 0 )
		{
			this.$cached[ this.cacheprefix + n ] = re;
			
			if( s )
			{
				this.Show( n, params, replacelast );
			}
		}
	},
	
	Show : function( n, params, replacelast )
	{
		///<summary>Loads a modal from the server and shows it</summary>
		///<param name="n" type="String">the modal identifier</param>

		if( null == ( this.$cached[ this.cacheprefix + n ] || null ) )
		{
			return this.Load( n, true, params, replacelast );
		}
		
		this.Create( this.$cached[ this.cacheprefix + n ], null, replacelast, params );
		
		if( null != this.OnShow )
		{
			try
			{
				this.OnShow();
			}
			catch(ex)
			{
				$Log(ex);
			}
			this.OnShow = null;
		}
	}
};

var $M = new Modal();

function LoadCSS( src )
{
	var script = create( "LINK" );
	script.href = src;
	script.rel = "stylesheet";
	script.type = "text/css";
	elByTag( $d, "head" )[0].appendChild( script );
}


function getPageSize(){
	
	var xScroll,
	yScroll,
	windowWidth,
	windowHeight;
	
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if( $d.body.scrollHeight > $d.body.offsetHeight) // all but Explorer Mac
	{
		xScroll = $d.body.scrollWidth;
		yScroll = $d.body.scrollHeight;
	}
	else // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	{
		xScroll = $d.body.offsetWidth;
		yScroll = $d.body.offsetHeight;
	}
	
	if( self.innerHeight )	// all except Explorer
	{
		windowWidth = $d.documentElement.clientWidth ? document.documentElement.clientWidth : self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if( $d.documentElement && $d.documentElement.clientHeight ) // Explorer 6 Strict Mode
	{
		windowWidth = $d.documentElement.clientWidth;
		windowHeight = $d.documentElement.clientHeight;
	}
	else if( $d.body ) // other Explorers
	{
		windowWidth = $d.body.clientWidth;
		windowHeight = $d.body.clientHeight;
	}
	
	return {
		pw : ( xScroll < windowWidth ? xScroll : windowWidth ),
		ph : ( yScroll < windowHeight ? windowHeight : yScroll ),
		ww : windowWidth,
		wh : windowHeight
	};
}

/* MODAL END */



/* sove IE background-image flicker bug */
try
{
	document.execCommand( "BackgroundImageCache", false, true );
}
catch(e)
{
}


/* ON PAGE INIT */

function BaseInit()
{
	// Update Language-Dropdown links with current querystring
	var q = window.location.search.replace(/(\?l=[^&]*&?)|(&l=[^&]*)/, "");
	if( /[?&]/.test(q[0]) )
	{
		q = q.substr(1);
	}
	
	if( "" != q )
	{
		elByTag( "langlist", "A" ).each
		(
			function( a )
			{
				a.href = a.search + "&" + q;
			}
		);
	}
	
	// Update TopNavigation to enable pressed button state
	elByTag( "mainnav", "A" ).each( function( a )
	{
		AttachEvent( a, "mousedown", $press.link( a, a ) );
	} );
	
	/*
	// Remove "index.aspx" from the form action (just cosmetics)
	elByTag( $d, "FORM" ).each
	(
		function( f )
		{
			var a = f.action;
			try
			{
				if( a.startsWith( "index.aspx" ) )
				{
					f.action = "./" + a.substr( 10 );
				}
				else
				{
					f.action = a.replace( /^([^?]+)(index.aspx(?=(\?)|([^?]*$))(.*)?)/i, "$1$5" );
				}
			}
			catch( ex )
			{
				f.action = a;
			}
		}
	);*/
}

function $press( a )
{
	( function(){ this.blur() } ).delay( 1, a );
	if( !$disabled( a ) )
	{
		a.className = "pressed";
		[ "mouseup", "mouseout" ].each( function( e )
			{
				AttachEvent( this, e, $unpress.link( this ) );
			}, a
		);
	}
}

function $unpress()
{
	$class( this, "" );
	/* needs to be fixed, doesn't work anyways --> Event-Observer-Pattern !!!
	[ "mouseup", "mouseout" ].each( function( e )
		{
			DetachEvent( this, e, $unpress );
		}, this
	);
	*/
}

function $disable( o )
{
	o = el( o );
	if( o.tagName == "A" )
	{
		o = o.parentNode;
	}
	setOpacity( o, 33 );
	$class( elByTag( o, "A" )[ 0 ], "btndisabled" );
}

function $disabled( a )
{
	return /btndisabled/i.test( a.className );
}

function $enable( o )
{
	elByTag( o, "a" ).each( function( a )
		{
			setOpacity( a.parentNode, 100 );
			$class( a, "" );
		}
	);
}

function getElementsByClassName(className, tag, elm) {
    var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
    for (var i = 0; i < length; i++) {
        current = elements[i];
        if (testClass.test(current.className)) {
            returnElements.push(current);
        }
    }
    return returnElements;
}

function SetGrayText(id, s, col) {
    var inpt = el(id);
    if ($un == typeof col) col = "#838383";
    inpt.data = s;
    //inpt.isPass = (inpt.type == "password");
    AttachEvent(inpt, "focus", function() { focus.call(inpt); });
    AttachEvent(inpt, "blur", function() { blur.call(inpt); });
    blur.call(inpt);

    function focus() {
        if (this.value == this.data) {
            //if (this.isPass) inpt.type = "password";
            this.value = "";
        }
        $s(this, "color", "");
    }
    function blur() {
        if (this.value.length == 0 || this.value == this.data) {
            $s(this, "color", col);
            //if (this.isPass) inpt.type = "text";
            this.value = this.data;
        }
    }
}

function TZMgr( f, c, l)
{
	this.brOff = -new Date().getTimezoneOffset();
	this.usrOff = null;
	this.cont = c;
	this.list = l;
	this.first = !f;
}

TZMgr.prototype =
{
	start : function()
	{
		if(this.list != null && this.list.selectedIndex > -1 && this.list.options[this.list.selectedIndex].defaultSelected)
		{
			this.usrOff = this.list.value;
		}
		else
		{
			this.usrOff = this.brOff;
			if( null != this.list )
		    {
		    	this.list.value = this.usrOff;
		    }
		}
		window.setInterval( this.timer.link( this ), 1000 );
	},
	
	timer : function()
	{
		if(this.cont != null)
		{
			var parsed = new Date( new Date().getTime() + ( this.usrOff - this.brOff ) * 60000 ).toLocaleTimeString();
			this.cont.innerHTML = parsed.indexOf( " GMT" ) > -1 ? parsed.substr( 0, parsed.indexOf( " GMT" ) ) : parsed;
		}
	},
	
	update:function( v )
	{
		this.usrOff = v;
		this.timer();
	}
};

