(function()
{
	var a=window.navigator.userAgent;
	WL.browser={ie:false,firefox:false,safari:false,opera:false,v:0};
	if(a.indexOf("MSIE")>=0)
	{
		if(a.indexOf("Win64")==-1)
		{
			WL.browser.v = parseInt(a.split("MSIE")[1]);
			if(WL.browser.v>=6) WL.browser.ie = true;
		}
	}
	else if(a.indexOf("Firefox")>=0)
	{
		var b=a.split("Firefox/")[1].split("."),c=parseInt(b[0]);
		if(c>=2) WL.browser.firefox = true;
		else
		{
			var d=parseInt(b[1]);
			if(c==1&&d>=5) WL.browser.firefox = true;
		}
	}
	else if(a.indexOf("Chrome")>=0) WL.browser.chrome = true;
	else if(a.indexOf("Safari")>=0) WL.browser.safari = true;
	else if(a.indexOf("Opera")>=0) WL.browser.opera = true;
})();
WL.browser.option = {};
WL.browser.option.rtlTableScrollOnRight = !WL.browser.safari;
WL.browser.option.cssPositionFixed = !(WL.browser.ie && (WL.browser.v < 7 || (document.compatMode && document.compatMode == "BackCompat")));
WL.browser.option.selectOpacityBag = WL.browser.ie && WL.browser.v < 7;

Function.prototype.extend = function(i){return i.apply(this.prototype,Array.prototype.slice.call(arguments,1))}
Function.prototype.bind = function(o){
	var f=this;switch(arguments.length){
		case 0:return f;
		case 1:return function(){return f.apply(o,arguments);};
		default:var a=Array.prototype.slice.call(arguments,1);return function(){return f.apply(o,a.concat(Array.prototype.slice.call(arguments,0)));}}
}
Function.prototype.raise = function(ctx,timeout){
	var f=this;var a=Array.prototype.slice.call(arguments,2);return function(){
		var b=a.concat(Array.prototype.slice.call(arguments,0));if(f.__raiseCookie)window.clearTimeout(f.__raiseCookie); 
		f.__raiseCookie=window.setTimeout(function(){f.__raiseCookie=null;f.apply(ctx,b);},timeout||0); 
	};
}

Array.prototype.clear		= function(){this.splice(0,this.length);}
Array.prototype.insert		= function( index, item ) { this.splice( index, 0, item ); }
Array.prototype.indexOf		= function( item ) { for( var i = 0; i < this.length; ++i ) if( this[i] == item ) return i; return -1; }
Array.prototype.remove		= function( item ) { for( var i = 0; i < this.length; ++i )	if( this[i] == item ) {	this.splice( i, 1 ); } }
Array.prototype.removeAt	= function( index ) { this[index] = null; this.splice( index, 1 ); }
Array.prototype.removeIf	= function( remover,thisp ) {var s=thisp||this; for( var i = this.length-1; i >= 0; i-- ) if( remover.call(s,this[i],i,this) ) this.splice( i, 1 ); return this; }
Array.prototype.findIndex	= function( finder ) { for( var i = 0; i < this.length; ++i ) if( finder( this[i] ) ) return i; return -1; }
Array.prototype.find		= function( finder ) { var i = this.findIndex(finder);return i!=-1?this[i]:null;}
Array.prototype.replace		= function( item, newitem ) { for( var i = 0; i < this.length; ++i )	if( this[i] == item ) {	this[i] = newitem; return; } }
Array.prototype.replaceIf	= function( replacer, newitem ) { for( var i = 0; i < this.length; ++i )	if( replacer( this[i] ) ) {	this[i] = newitem; return; } }
Array.prototype.clone		= function() { var ar = []; for( var i = 0; i < this.length; ++i ) ar.push( this[i] ); return ar; }
//Array.prototype.shiftAt		= function( index, dx ) { var i = index+dx; if( i >= 0 && i < this.length ) { var item = this[index]; this.splice( index, 1 ); this.splice( i, 0, item ); } }
//Array.prototype.shift		= function( item, dx ) { var i = this.indexOf(item); if( i != -1 ) this.shiftAt(i,dx); }
Array.prototype.binarySearch = function( value, comparer ) { var l = 0, r = this.length-1, m; if( comparer != null ) { var res; while( l <= r ) { m = ( l + r ) >> 1; res = comparer( this[m], value ); if( res == 0 ) return m; if( res < 0 ) l = m + 1; else r = m - 1; } } else { while( l <= r ) { m = ( l + r ) >> 1; if( this[m] == value ) return m; if( this[m] < value ) l = m + 1; else r = m - 1; } } return ~l; }
//Array.prototype.addRange	= function(ar){for(var i=0;i<ar.length;++i)this.push(ar[i]);}
Array.prototype.equals		= function(ar,comparer) { if( this.length != ar.length ) return false; if( comparer != null ) { for( var i = 0; this.length; ++i ) if( comparer( this[i], ar[i] ) != 0 ) return false; } else { for( var i = 0; this.length; ++i ) if( this[i]!=ar[i] ) return false; } return true; }
Array.prototype.last		= function(){return this.length==0?null:this[this.length-1];}
Array.prototype.each		= function(f,thisp){var s=thisp||this;for(var i=0,l=this.length;i<l;++i)f.call(s,this[i],i,this);return this}
Array.prototype.map			= function(f,thisp){var s=thisp||this;var i=0,l=this.length,r=new Array(l);for(;i<l;++i)r[i]=f.call(s,this[i],i,this);return r}
Array.prototype.every		= function(f,thisp){var s=thisp||this;var i=0,l=this.length;for(;i<l;++i)if(!f.call(s,this[i],i,this))return false;return true}
Array.prototype.some		= function(f,thisp){var s=thisp||this;var i=0,l=this.length;for(;i<l;++i)if(f.call(s,this[i],i,this))return true;return false}
Array.prototype.filter		= function(f,thisp){var s=thisp||this;var r=[],i=0,l=this.length;for(;i<l;++i)if(f.call(s,this[i],i,this))r.push(this[i]);return r}

String.empty = "";
String.isNullOrEmpty = function(s){return s!=null&&s.length>0;}
String.format = function(f){var a=arguments;return f.replace(/{(\d+)}/ig,function($0,$1){return(a[Number($1)+1]);});}
String.prototype.trim = function(c){if(c==null) c=' ';var i,f,t;for(i=0;i<this.length;++i) if(this.charAt(i)!=c)break;f=i;for(i=this.length-1;i>=0;i--)if(this.charAt(i)!=c)break;t=i;if(f>t) return "";return this.substring(f,t+1);}
String.prototype.trimLeft = function(c){if(c==null) c=' ';var i,f,t;t=this.length-1;for(i=0;i<this.length;++i) if(this.charAt(i)!=c)break;f=i;return this.substring(f,t+1);}
String.prototype.trimRight = function(c){if(c==null) c=' ';var i,f,t;f=0;for(i=this.length-1;i>=0;i--)if(this.charAt(i)!=c)break;t=i;if(f>t) return "";return this.substring(f,t+1);}
String.prototype.escapeXML=function(){return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;");}
String.prototype.unescapeXML=function(){return this.replace(/&apos;/g,"'").replace(/&quot;/g,"\"").replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&amp;/g,"&");}
String.prototype.escapeHTML=function(){return this.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;").replace(/\u00A0/g,"&nbsp;");}
String.prototype.unescapeHTML=function(){return this.replace(/&nbsp;/g,"\u00A0").replace(/&gt;/gm,">").replace(/&lt;/gm,"<").replace(/&amp;/gm,"&");}

Math.middle = function(v1,v2,v3){return v2<v3?(v2<v1?(v3<v1?v3:v1):v2):(v3<v1?(v2<v1?v2:v1):v3);}

Number.prototype.toHexString = function(n){var r=this.toString(16);n-=r.length;if(n<=0) return r;var a=[];while(n--) a.push("0");a.push(r);return a.join("");}
Number.prototype.format = function(n){var c=parseInt(n);var o=this.toString();var d=o.length-c;if(d>0) return o;var a=[];while(d++<0) a.push(0);a.push(o);return a.join("");}
Number.prototype.NaN0 = function(){ return isNaN(this) ? 0 : this; }
Number.prototype.toMoney = function(fraction) { return WL.Utils.floatToString( this, fraction != null ? fraction : CultureInfo.Currency.decimalDigits, true, true, CultureInfo.Currency.groupSeparator, CultureInfo.Currency.decimalSeparator ); }
Number.fromMoney = function(s) { return parseFloat( s.split(CultureInfo.Currency.groupSeparator).join('').replace(CultureInfo.Currency.decimalSeparator,'.') ); }

WL.using = function( ns, use_as ){if( typeof(use_as) == 'undefined' || use_as == null ) use_as = window;for( var p in ns ) use_as[p] = ns[p];}
WL.Class = function(b,i){var l=new Function;l.prototype=b.prototype;var c=new Function;c.prototype=new l;c.extend(i,new l,c);c.prototype.constructor.prototype=c.prototype;for(var j in c)if(c.hasOwnProperty(j))c.prototype.constructor[j]=c[j];return c.prototype.constructor;}
WL.JSObject=function(t,obj){var o=new t();for(var p in obj)if(obj.hasOwnProperty(p))o[p]=obj[p];return o;}

if( typeof( window.showModalDialog ) != "undefined" )
{
WL.__showModalDialog = function( sURL, vArguments, sFeatures, returner )
{
	var ret = window.showModalDialog( sURL, vArguments, sFeatures );
	if( returner != null )
		returner( ret );
}

WL.returnValue = function( value )
{
	window.returnValue = value;
}

WL.getModalDialogFeatures = function( width, height, scroll, resizable )
{
	var features = [ "dialogWidth:",	width	  ? width + "px" : "auto", 
					 ";dialogHeight:",	height	  ? height+	"px" : "auto",
					 ";scroll:",		scroll	  ? "yes" : "no",
					 ";resizable:",		resizable ? "yes" : "no",
					 ";status:yes;help:no" ];
	return features.join( '' );
}
}
else // if( typeof( window.showModalDialog ) != "undefined" )
{
WL.__showModalDialog = function( sURL, vArguments, sFeatures, returner )
{
	var opener = window.self;
	var w = window.open( sURL, "_blank", sFeatures );
		w.dialogArguments = vArguments;
	
	var w_focus = function() { w.focus(); };
	var handler = function()
		{
			if( w.closed && !w.removed )
			{
				w.removed = true;
								
				window.removeEventListener( "focus", handler, true );
				
				var value = undefined;
				if( window.__returnValue )
				{
					value = window.__returnValue;
							window.__returnValue = null;
				}
				
				if( returner != null )
					returner( value );
			}
			else
			{
				try { w.focus(); }catch(e){}
			}
//			window.blur();			
		};
		
	window.addEventListener( "focus", handler, true );
//		 w.addEventListener( "blur",  w_focus, true );
}

WL.returnValue = function( value )
{
	top.opener.__returnValue = value;
}

WL.getModalDialogFeatures = function( width, height, scroll, resizable )
{
	var left = width ? ((window.screen.availWidth-width)/2).NaN0() : 0;
	var top = height ? ((window.screen.availHeight-height)/2).NaN0() : 0;
	return String.format( "modal=yes,channelmode=no,directories=no,fullscreen=no{0}{1}{2}{3},scrollbars={4},resizable={5},titlebar=no,toolbar=no,location=no,menubar=no,status=no",
							top	> 0	? ",top=" + top : "",
							left> 0	? ",left=" + left  : "",
							height	? ",height=" + height : "",
							width	? ",width="	+ width  : "",
							scroll != false ? "yes" : "no",
							resizable != false ? "yes" : "no" );
}
} // end if( typeof( window.showModalDialog ) != "undefined" )

WL.getWindowFeatures = function( width, height, top, left, location, resizable )
{
	return String.format( "channelmode=no,directories=no,fullscreen=no{0}{1}{2}{3},location={4},menubar=yes,resizable={5},scrollbars=yes,status=yes,titlebar=yes,toolbar=yes",
							height			? ",height=" + height	: "",
							left	!= null ? ",left="	 + left		: "",
							width			? ",width="	 + width	: "",
							top		!= null ? ",top="	 + top		: "",
							location  == true  ? "yes" : "no", 
							resizable != false ? "yes" : "no" );
}

if( typeof( document.addEventListener ) != "undefined" )
{
WL.attachListener = function( element, name, handler )
{
	element.addEventListener( name, handler, false );
}
WL.detachListener = function( element, name, handler )
{
	element.removeEventListener( name, handler, false );
}
WL.getEvent = function( e ) { return e; }
WL.returnEvent = function( e, result, cancelBubble )
{
	if( cancelBubble )
	{
		e.stopPropagation();
		e.preventDefault();
	}
	e.returnValue = result;
	return result;
}
}
else // if( typeof( document.addEventListener ) != "undefined" )
{
WL.attachListener = function( element, name, handler )
{
	element.attachEvent( "on" + name, handler );
}
WL.detachListener = function( element, name, handler )
{
	element.detachEvent( "on" + name, handler );
}
WL.getEvent = function( e )
{
	if( window.event ) e = window.event;
	if( e && !e.target )
		e.target = e.srcElement;
	return e;
}
WL.returnEvent = function( e, result, cancelBubble )
{
	window.event.returnValue = result;
	if( cancelBubble != null )
		window.event.cancelBubble = cancelBubble;
	return result;
}
	} // end if( typeof( document.addEventListener ) != "undefined" )

if( WL.browser.ie )
{
WL.$ = document.getElementById;
WL.$e = document.createElement;
WL.$en = function(type,name){return document.createElement('<'+type+' name="'+name+'">');}

WL.uniqueID = function(el) { return el.id || el.uniqueID; }
WL.currentStyle = function( obj ) { return obj.currentStyle; }
} // end if( WL.browser.ie )
else
{
var uniqueID = 0;
WL.uniqueID = function(el) { if(!el.id) el.id = "ms__id" + uniqueID++; el.uniqueID = el.id; return el.uniqueID; }

document._wl_createElement = document.createElement;
document.createElement = function( tag )
{
	var el = document._wl_createElement(tag);
	WL.uniqueID(el);
	return el;
}

WL.$ = function(id) { return document.getElementById(id); }
WL.$e = function(tag) { return document.createElement(tag); }
WL.$en = function(type,name){var el=document.createElement(type);el.setAttribute("name",name);return el;}

WL.currentStyle = function(obj) { return window.getComputedStyle(obj,null); }
} // end else if( WL.browser.ie )

WL.$$ = function( id ) { return WL.$( id ).control; }
WL.$$$ = function() { return WL.$( Array.prototype.slice.call(arguments).join('_') ); }
WL.$$$$ = function( id ) { return WL.$$$( id ).control; }
WL.$$e = function( type, tag, parent ) { var cont=WL.$e(tag); parent.appendChild(cont); var c=new type(); c.generate2( cont ); return c; };
(function(){var A=function(){var E=arguments[0];if(A.x[E]&&!arguments[2]){return A.x[E]}else{if(!E){return undefined}var J=arguments[1]||document;if(J.querySelectorAll){A.z=J.querySelectorAll(E)}else{switch(E){case"a":A.z=J.links||J.getElementsByTagName("a");break;case"body":A.z=J.body;break;case"form":A.z=J.forms||J.getElementsByTagName("form");break;case"head":A.z=J.getElementsByTagName("head")[0];break;case"img":A.z=J.images||J.getElementsByTagName("img");break;default:var C=E.split(/, */),N,G=0;while(N=C[G++]){var F=N.split(/ +/),B=F.length,M,H=0;A.y=J;while(M=F[H++]){M.replace(/([^\.#]+)?(?:#([^\.#]+))?(?:\.([^\.#]+))?/,function(V,Y,K,S){switch(H){case 0:if(!S){if(!Y){A.y=document.getElementById(K);break}if(!K){A.y=J.getElementsByTagName(Y);break}}if(!Y&&!K&&J.getElementsByClassName){A.y=J.getElementsByClassName(S);break}default:var Q=[],U=0,W=0,P;A.y=A.y.length?A.y:[A.y[0]||A.y];while((P=A.y[U++])&&P.nodeName){var R=0,O,T=P.getElementsByTagName(Y||"*"),X=H==B?1:0;while(O=T[R++]){if((!K||(K&&O.id==K))&&(!S||(S&&O.className.match(S)))&&!O.yeasss){if(X){O.yeasss=1}Q[W++]=O}}}A.y=Q;break}})}A.z=A.z||A.y;if(A.y&&G>1){var D,I=0,L=A.z.length;while(D=A.y[I++]){A.z[L++]=D}}}break}}var L=A.z.length;while(L--){A.z[L].yeasss=undefined}A.x[E]=A.z.length>1||A.z.nodeName?A.z:A.z[0];A.z=A.y=null;return A.x[E]}};A.y=null;A.z=null;A.x={};WL.$css=A})();

WL.showModalDialog = function( sURL, vArguments, sFeatures, returner )
{
	if( WL.xmlCallback )
		WL.xmlCallback.updateWindowStatus( true );

	if( vArguments == null ) vArguments = {};
		vArguments.window_opener = window.window_opener;
		vArguments.opener = window.self;
		
	if( sFeatures == null )
		sFeatures = WL.getModalDialogFeatures( null, null, false, true );
	
	if( sURL.toLowerCase().indexOf("http")!=0 ) sURL = window.baseUrl+'/'+sURL;
	
	WL.__showModalDialog( sURL, vArguments, sFeatures, returner );

	vArguments.window_opener = null;
	vArguments.opener = null;
}

WL.windowOpen = function( sURL, sName, sFeatures, bReplace )
{
	WL.Utils.assert( !window.window_opener, "window.window_opener is null" );
	
	var w;
	try
	{
		if( sURL.toLowerCase().indexOf("http")!=0 ) sURL = window.baseUrl+'/'+sURL;
		
		if( window.window_opener )
		{
			w = window.window_opener.open( sURL, sName, sFeatures, bReplace );
			w.window_opener = window.window_opener;
			w.opener = window.self;
		}
		else
		{
			w = window.open( sURL, sName, sFeatures, bReplace );
			w.window_opener = window.self;
		}
	}
	catch(e){}
	return w;
}

WL.navigate = function(url) { if( url.toLowerCase().indexOf(WL.LogoutPage)==0 ) window.logout_alert = true; if( url.toLowerCase().indexOf("http")!=0 ) url = window.baseUrl+'/'+url; WL._closeMethod( function() { window.location.href=url; } ); }
WL.windowClose = function() { WL._closeMethod( function() { window.close(); } ); }

WL.login = function() { WL.navigate( String.format( "{0}?redirect={1}", WL.LogoutPage, encodeURIComponent(window.location.pathname+window.location.search) ) ); }
WL.logoutStatic = function()
{
	var close_method = function() { window.location.href=String.format( "{0}?redirect={1}", WL.LogoutPage, encodeURIComponent(window.location.pathname+window.location.search) ); }
	if( !window.logout_alert ) { window.logout_alert = true; WL.alertCallback=close_method; WL.alert( WL.LogoutMsg ); }	
	else close_method();
}
WL.logoutPopup  = function()
{
	var close_method = function()
	{
		if( window.opener != null &&
			window.opener.closed == false &&
			window.opener.logout != null )
		{
			window.opener.logout_alert = true;
			window.opener.logout();
		}
		window.close();
	}
	if( !window.logout_alert ) { window.logout_alert = true; WL.alertCallback=close_method; WL.alert( WL.LogoutMsg ); }
	else close_method();	
}

WL.onstartup = [];
WL._startup = function() { for( var i = 0; i < WL.onstartup.length; ++i ) WL.onstartup[i](); WL.onstartup.clear(); }

WL.onclose = [];
WL._closeMethod = function( method )
{
	if( window.window_closing ) return;
		window.window_closing = true;

	for( var i = 0; i < WL.onclose.length; ++i )
	{
		try { WL.onclose[i](); }
		catch(e){}
	}
	WL.onclose.clear();
	
	var closeMethod = function()
	{
		window.window_opener = null;
		window.opener = null;
		method();
	}
		
	if( WL.xmlCallback != null && ( WL.xmlCallback.getQueueLength() > 0 || WL.xmlCallback.getLateQueueLength() > 0 ) )
	{
		var request = new ServerAPI.Request( WL.Guids.Api.WebGeneral, "Ping" );		
		window.xmlCallback.doWebRequest( request, this, closeMethod, closeMethod, false );
	}
	else closeMethod();	
}

WL.R = [];
WL.S = function(rid) { return WL.R[rid]||""; }
WL.SHTML = function(rid) { return WL.R[rid]||""; }

var _uIDs = 0;
WL.uniqueID = function(el) { if(!el.id) el.id = "_uid" + _uIDs++; return el.id; }