function preventBubble( E )
{
	if( window.event ){
		window.event.cancelBubble = true;
		window.event.returnValue  = false;
	} else if( E && ( typeof E.stopPropagation != 'undefined' ) ) {
		E.stopPropagation();
	}
	else if( E && ( typeof E.preventBubble != 'undefined' ) ) {
		E.preventBubble();
	}
    
	if( E && ( typeof E.preventDefault != 'undefined' ) ) {
		E.preventDefault();
	}
}

function isEnterKey( E )
{
	var k = 0;
	if( window.event ) {
		k = window.event.keyCode;
	}
	else {
		k = E.keyCode;
	}
	return k == 13;
}
/* page bus */
if(!window["OpenAjax"]){OpenAjax=new function(){var t=true;var f=false;var g=window;var _4;var _5="org.openajax.hub.";var h={};this.hub=h;h.implementer="http://tibco.com";h.implVersion="0.6";h.specVersion="0.6";h.implExtraData={};var _4={};h.libraries=_4;h.registerLibrary=function(_7,_8,_9,_a){_4[_7]={prefix:_7,namespaceURI:_8,version:_9,extraData:_a};this.publish(_5+"registerLibrary",_4[_7]);};h.unregisterLibrary=function(_b){this.publish(_5+"unregisterLibrary",_4[_b]);delete _4[_b];};h._subscriptions={c:{},s:[]};h._cleanup=[];h._subIndex=0;h._pubDepth=0;h.subscribe=function(_c,_d,_e,_f,_10){if(!_e){_e=window;}var _11=_c+"."+this._subIndex;var sub={scope:_e,cb:_d,fcb:_10,data:_f,sid:this._subIndex++,hdl:_11};var _13=_c.split(".");this._subscribe(this._subscriptions,_13,0,sub);return _11;};h.publish=function(_14,_15){path=_14.split(".");this._pubDepth++;this._publish(this._subscriptions,path,0,_14,_15);this._pubDepth--;if((this._cleanup.length>0)&&(this._pubDepth==0)){for(var i=0;i<this._cleanup.length;i++){this.unsubscribe(this._cleanup[i].hdl);}delete (this._cleanup);this._cleanup=[];}};h.unsubscribe=function(sub){var _18=sub.split(".");var sid=_18.pop();this._unsubscribe(this._subscriptions,_18,0,sid);};h._subscribe=function(_1a,_1b,_1c,sub){var _1e=_1b[_1c];if(_1c==_1b.length){_1a["."].push(sub);}else{if(!_1a[_1e]){_1a[_1e]={".":[]};this._subscribe(_1a[_1e],_1b,_1c+1,sub);}else{this._subscribe(_1a[_1e],_1b,_1c+1,sub);}}};h._publish=function(_1f,_20,_21,_22,msg){if(typeof _1f!="undefined"){var _24;if(_21==_20.length){_24=_1f;}else{this._publish(_1f[_20[_21]],_20,_21+1,_22,msg);this._publish(_1f["*"],_20,_21+1,_22,msg);_24=_1f["**"];}if(typeof _24!="undefined"){var _25=_24["."];var max=_25.length;for(var i=0;i<max;i++){if(_25[i].cb){var sc=_25[i].scope;var cb=_25[i].cb;var fcb=_25[i].fcb;var d=_25[i].data;if(typeof cb=="string"){cb=sc[cb];}if(typeof fcb=="string"){fcb=sc[fcb];}try{if((!fcb)||(fcb.call(sc,_22,msg,d))){cb.call(sc,_22,msg,d);}}catch(err){if(err.message=="PageBus.StackOverflow"){throw err;}h.publish("com.tibco.pagebus.error.callbackError",{name:escape(_22),error:escape(err.message)});}}}}}};h._unsubscribe=function(_2c,_2d,_2e,sid){if(typeof _2c!="undefined"){if(_2e<_2d.length){var _30=_2c[_2d[_2e]];this._unsubscribe(_30,_2d,_2e+1,sid);if(_30["."].length==0){for(var x in _30){return;}delete _2c[_2d[_2e]];}return;}else{var _32=_2c["."];var max=_32.length;for(var i=0;i<max;i++){if(sid==_32[i].sid){if(this._pubDepth>0){_32[i].cb=null;this._cleanup.push(_32[i]);}else{_32.splice(i,1);}return;}}}}};};OpenAjax.hub.registerLibrary("OpenAjax","http://openajax.org/hub","0.6",{});}if(!window["PageBus"]){PageBus=new function(){var _35="1.2.0";var D=0;var Q=[];var Reg={};var _39=[];var RD=0;_throw=function(n){throw new Error("PageBus."+n);};_badName=function(n){_throw("BadName");};_fix=function(p){if(typeof p=="undefined"){return null;}return p;};_valPub=function(_3e){if((_3e==null)||(_3e.indexOf("*")!=-1)||(_3e.indexOf("..")!=-1)||(_3e.charAt(0)==".")||(_3e.charAt(_3e.length-1)==".")){_badName();}};_valSub=function(_3f){var _40=_3f.split(".");var len=_40.length;for(var i=0;i<len;i++){if((_40[i]=="")||((_40[i].indexOf("*")!=-1)&&(_40[i]!="*")&&(_40[i]!="**"))){_badName();}if((_40[i]=="**")&&(i<len-1)){_badName();}}return _40;};this.subscribe=function(_43,_44,_45,_46,_47){_47=_fix(_47);_46=_fix(_46);var _48=_valSub(_43);return OpenAjax.hub.subscribe(_43,_45,_44,_46,_47);};this.publish=function(_49,_4a){_valPub(_49);if(D>20){_throw("StackOverflow");}Q.push({n:_49,m:_4a,d:(D+1)});if(D==0){while(Q.length>0){var _4b=Q.shift();var _4c=_4b.n.split(".");try{D=_4b.d;OpenAjax.hub.publish(_4b.n,_4b.m);D=0;}catch(err){D=0;throw (err);}}}};this.unsubscribe=function(sub){try{OpenAjax.hub.unsubscribe(sub);}catch(err){_throw("BadParameter");}};this.store=function(_4e,msg,_50){_store=function(_51,_52,_53,_54,msg){var tok=_52[_53];var len=_52.length;if(typeof _51[tok]=="undefined"){_51[tok]={};}var n=_51[tok];if(_53==len-1){if(typeof n["."]!="undefined"){if(RD==0){delete n["."];}else{n["."].v=null;_39.push(n["."]);}}if(msg!=null){n["."]={n:_54,v:msg};}}else{_store(n,_52,_53+1,_54,msg);if(msg==null){for(var x in n[_52[_53+1]]){return;}if(RD==0){delete n[_52[_53+1]];}else{_39.push(n[_52[_53+1]]);n[_52[_53+1]]=null;}}}};_valPub(_4e);var _5a=_4e.split(".");_store(Reg,_5a,0,_4e,msg);if(!_50||!_50.quiet){PageBus.publish(_4e,msg);}};this.query=function(_5b,_5c,cb,_5e,fcb){_query=function(_60,_61,idx,_63){function _doRCB(_64,_65){var z=_65.z;var cb=_65.c;var d=_65.d;var fcb=_65.f;var n=_64["."];if(!n||!n.v){return true;}if((fcb==null)||fcb.call(z,n.n,n.v,d)){return cb.call(z,n.n,n.v,d);}return true;};var len=_61.length;var tok=_61[idx];var _6d=(idx==len-1);if(tok=="**"){for(tok in _60){if(tok!="."){if(!_doRCB(_60[tok],_63)){return false;}if(!_query(_60[tok],_61,idx,_63)){return false;}}}}else{if(tok=="*"){for(tok in _60){if(tok!="."){if(_6d){if(!_doRCB(_60[tok],_63)){return false;}}else{if(!_query(_60[tok],_61,idx+1,_63)){return false;}}}}}else{if(typeof _60[tok]!="undefined"){if(_6d){return _doRCB(_60[tok],_63);}else{return _query(_60[tok],_61,idx+1,_63);}}}}return true;};if(_5c==null){_5c=window;}var _6e=_valSub(_5b);var len=_6e.length;var res;try{RD++;var _71={z:_5c,c:cb,d:_5e,f:fcb};res=_query(Reg,_6e,0,_71);RD--;}catch(err){RD--;throw err;}if(RD==0){while(_39.length>0){var p=_39.pop();delete p;}}if(!res){return;}var _73="com.tibco.pagebus.query.done";if((fcb==null)||fcb.call(_5c,_73,null,_5e)){cb.call(_5c,_73,null,_5e);}};};OpenAjax.hub.registerLibrary("PageBus","http://tibco.com/PageBus","1.2.0",{});}
/* end of page bus */

var pageBusNamespace = "listings_bus_subscribers";

function crossPublishToGlobalBus( subject, msg )
{
	try
	{
		if( window.opener != null && window.opener != window && window.opener["PageBus"] ) {
			window.opener["PageBus"].publish( subject, msg );
		}
	}
	catch( e ) {}
	try
	{
		if( window.parent && window.parent != window && window.parent["PageBus"] ) {
			window.parent["PageBus"].publish( subject, msg );
		}
	}
	catch( e ) {}
	try
	{
		if( window.parent && window.parent != window ) {
			window.parent.frames["__mrp_listings"]["PageBus"].publish( subject, msg );
		}
	}
	catch( e ) {}
}

function publishToBus( subject, msg, crossPublish )
{
	/*
	if(  ( browser.isIE && browser.ieVersion < 9 ) && !isIELoaded() ) {
		return;
	}
	*/
	if( typeof window.PageBus == 'undefined' ) {
		return false;
	}
	window.PageBus.publish( subject, msg );
	if( crossPublish ) {
		crossPublishToGlobalBus( subject, msg );
	}
	return false;
}

function subscribeToBus( subject, nmspace, callback, data )
{
	if( typeof window.PageBus == 'undefined' ) {
		return false;
	}
	if( typeof subject == "string" ) {
		window.PageBus.subscribe( subject, nmspace, callback, data );
	}
	else {
		for( var i=0; i<subject.length; ++i ) {
			window.PageBus.subscribe( subject[i], nmspace, callback, data );
		}
	}
	return false;
}

if( typeof window.PageBus != 'undefined' ) {
	subscribeToBus( "global.alert", null, function( s, m, d ) {
		if( m ) {
			alert( m );
		}
	}, null );
}

// jsonp support
function do_j( url, msg, callback, timeout ) {
	if( url.indexOf( '?' ) == -1 ) {
		url += '?';
	}
	else {
		url += '&';
	}
	var r = '' + Math.random();
	var idx = r .indexOf( '.' );
	r = r.substring( idx + 1 );
	r = 'cb' + r;
	url += '_cb=' + escape( r );
	
	//alert( url );
	
	window[r] = function( payload, error ) { callback( payload, error ), window[r] = null };
	
	for( var i in msg ) {
		var val = msg[i];
		if( ( typeof val == 'number' ) || ( typeof val == 'string' ) ) {
			url += '&' + escape(i) + '=' + escape( val );
		}
	}
	
	if( ( typeof timeout == 'number' ) && timeout > 0 ) {
		setTimeout( function() {
			if( window[r] ) {
				window[r]( null, { "error" : "Timeout" } );
				window[r] = null;
			}
		}, timeout );
	}
	
	var s = document.createElement( "script" );
	s.type = "text/javascript";
	s.src = url;
	document.body.appendChild( s );
}

function call_comp( url, msg, componentId, opts )
{
	if( ( typeof opts == 'undefined' ) || !opts ) {
		opts = {};
	}
	var callback = function( p, err ) {
		if( err && !p ) {
			if( typeof opts["timeoutCallback"] == 'function' ) {
				opts["timeoutCallback"]( err, opts );
			}
			return;
		}
		var e = document.getElementById( componentId );
		if( e ) {
			var parentNode = e.parentNode;
			if( parentNode ) {
				var sibling = e.nextSibling;
				var newNode = document.createElement( "div" );
				//newNode.style.display = "none";
				//document.body.appendChild( newNode );
				newNode.innerHTML = p;
				var firstElem = null;
				var nodes = newNode.childNodes;
				for( var i=0; i<nodes.length; ++i ) {
					if( nodes.item(i).nodeType == 1 ) {
						firstElem = nodes.item(i);
						break;
					}
				}
				e.parentNode.removeChild( e );
				if( sibling ) {
					parentNode.insertBefore( firstElem, sibling );
				}
				else {
					parentNode.appendChild( firstElem );
				}
				
				if( typeof window.adjustIFrameHeight != 'undefined' ) {
					setTimeout( window.adjustIFrameHeight, 100 );
				}
				//newNode.parentNode.removeChild( newNode );
			}
		}
		if( typeof opts["callback"] == 'function' ) {
			opts["callback"]( opts );
		}
	};
	
	var timeout = 5000;
	if( opts["timeout"] ) {
		var customTimeout = parseInt(opts["timeout"]);
		if( !isNaN( customTimeout ) ) {
			timeout = customTimeout;
		}
	}
	do_j( url, msg, callback, timeout );
	return false;
}

function testJSONP()
{
	do_j( "http://localhost:8080/wps/rest/5/l/outertest", { }, function( payload, error ) {
		if( payload ) {
			alert( payload );
		}
		else if( error ) {
			alert( error["error"] );
		}
	}, 5000 );
}
// /jsonp support

// -- start browser identifying code
var browser = {};
browser._sniff = function(){
	var c = browser;
	var u = navigator.userAgent;
	//c.isDom  = document.getElementById;
	c.isMac  = (u.indexOf("Mac"  )>0);
	c.isIE   = (u.indexOf("MSIE" )>0);
	c.isNS   = (u.indexOf("Gecko")>0);
	c.isSafari = (u.indexOf("Safari")>0);
	c.isWebKit = (u.indexOf("WebKit")>0);
	c.isIPad = (u.indexOf("iPad")>0 && c.isSafari);
	c.isTable = c.isIPad;
	
	//-----
	c.isIE5  = false;
	c.isIE50 = false;
	c.isIE55 = false;
	c.isIE6  = false;
	c.isIE60 = false;
	c.isIE7  = false;
	c.isIE70 = false;
	//-----
	c.isNS6  = false;
	c.isNS7  = false;
	//-----
	
	if(c.isIE){
		var i    = navigator.appVersion.indexOf("MSIE");
		var temp = navigator.appVersion.substring(i+5,i+8);
		c.isIE50   = (temp=="5.0");
		c.isIE55   = (temp=="5.5");
		c.isIE60   = (temp=="6.0");
		c.isIE70   = (temp=="7.0");
		c.isIE5    = temp.charAt(0) == "5";
		c.isIE6    = temp.charAt(0) == "6";
		c.isIE7    = temp.charAt(0) == "7";
		c.ieVersion = parseFloat(temp);
	};
	if(c.isNS){
		c.isNS6    = (u.indexOf("Netscape6" )>0||u.indexOf("rv:0.")>0);
		c.isNS7    = (u.indexOf("Netscape/7")>0||u.indexOf("rv:1.")>0);
	}
	c.isIEMac  = c.isMac && c.isIE;
	c.isIE5Mac = c.isMac && c.isIE5;
};

browser._sniff();

// -- end of browser identifying code

function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

function protectThyselfFromSP2()
{
	try
	{
		document.getElementById( "nothing" );
	}
	catch( e )
	{
		location.href = location.href;
	}
}

function getXY( elem ) {
	var x = elem.offsetLeft;
	var y = elem.offsetTop;
	
	if( browser.isIE ) {
		if( elem.style.borderLeftWidth ) {
			var w = elem.style.borderLeftWidth.replace( 'px', '' );
			x += Number(w);
		}
		if( elem.style.borderTopWidth ) {
			var w = elem.style.borderTopWidth.replace( 'px', '' );
			y += Number(w);
		}
	}
	
	if( elem.offsetParent ) {
		var xy = getXY( elem.offsetParent );
		x += xy[0];
		y += xy[1];
	}
	var out = new Array(2);
	out[0] = x;
	out[1] = y;
	return out;
}

function makeNewWindow( name, url, width, height, options, centerWindowOrScreen )
{
	var xMax = 0;
	var xMax = screen.width, yMax = screen.height;
	var xOffset = (xMax - width)/2;
	var yOffset = (yMax - height)/2;
	
	if( centerWindowOrScreen == "window" ) {
		xMax = document.body.clientWidth;
		yMax = document.body.clientHeight;
		xOffset = (xMax - width)/2;
		yOffset = (yMax - height)/2;
		if( browser.isIE ) {
			xOffset += window.screenLeft;
			yOffset += window.screenTop;
		}
		else {
			xOffset += window.screenX;
			yOffset += window.screenY;
		}	
	}
    
	var win = window.open( url, name, "height=" + height + ",width=" + width + "," + 
		"screenX=" + xOffset + ",screenY=" + yOffset + 
		",top=" + yOffset + ",left=" + xOffset + "," + 
		options );
	if( win != null ) {
		win.focus();
	}
}

function onLinkMouseOver( link )
{
	if( !link )
		return;
	link.style.textDecoration = 'underline';
	link.origColor = link.style.color;
	link.style.color = 'red';
}

function onLinkMouseOut( link )
{
	if( !link )
		return;
	link.style.textDecoration = 'none';
	link.style.color = link.origColor;
}

function reload_captcha()
{
	var img = document.getElementById( "captcha_image" );
	if( !img )
		return;
	img.src = "captcha?" + Math.random();
}

function autosizeWindow( window, aroundElement, center )
{
	if( aroundElement == null ) {
		return;
	}
	
	var max_popup_width = 700;
	var max_popup_height = 550;
	
	var width = aroundElement.offsetWidth + 50;
	var height = aroundElement.offsetHeight + 70;
	
	if( width > max_popup_width ) {
		width = max_popup_width;
	}
	if( height > max_popup_height ) {
		height = max_popup_height;
	}
	sizeWindow( window, width, height, center );
}

function isNumeric(sText) {
   var ValidChars = "0123456789.";
   var Char;
   for (i = 0; i < sText.length; i++) {
       Char = sText.charAt(i);
       if (ValidChars.indexOf(Char) == -1) {
          return false;
       }
    }
   return true;
}

function prettyNumberIfNecessary(nStr,prefix)
{
	if( !isNumeric(nStr) ) {
		return nStr;
	}
	if( prefix ) {
		nStr = prefix + nStr;
	}
	else {
		nStr += '';
	}
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function sizeWindow( window, wwidth, wheight, center )
{
	if( !window || !wwidth || !wheight )
		return;
		
	if( center ) {
		var x = ( screen.width - wwidth ) / 2;
		var y = ( screen.height - wheight ) / 2;
		window.moveTo( x, y );
	}
	window.resizeTo( wwidth, wheight );
}

if( typeof window.onloads == 'undefined' ) {
	window.onloads = new Array();
}


function bodyOnLoad() {
	
	for ( var i = 0 ; i < onloads.length ; i++ ) {
		try {
    		onloads[i]();
		}
		catch( e ) {
		}
	}
	//setTimeout( goToViewtop, 100 );
}

function getScrollTop()
{
	if( browser.isIE ) {
		return document.body.scrollTop;
	}
	else {
		return window.pageYOffset;
	}
}

function getScrollLeft()
{
	if( browser.isIE ) {
		return document.body.scrollLeft;
	}
	else {
		return window.pageXOffset;
	}
}

function getBodyWidth()
{
	if( browser.isIE ) {
		return document.body.clientWidth;
	}
	else {
		return window.innerWidth;
	}
}

function getBodyHeight()
{
	if( browser.isIE ) {
		return document.body.clientHeight;
	}
	else {
		return window.innerHeight;
	}
}

function elemAddClassName(element, className) 
{
    elemRemoveClassName(element, className);
    element.className += ' ' + className;
}

function elemRemoveClassName(element, className) {
    if (!element)
      return;
    var newClassName = '';
    var a = element.className.split(' ');
    for (var i = 0; i < a.length; i++) {
      if (a[i] != className) {
        if (i > 0)
          newClassName += ' ';
        newClassName += a[i];
      }
    }
    element.className = newClassName;
}

/*
 *
 * ContentLoaded.js
 *
 * Author: Diego Perini (diego.perini at gmail.com)
 * Summary: Cross-browser wrapper for DOMContentLoaded
 * Updated: 17/05/2008
 * License: MIT
 * Version: 1.1
 *
 * URL:
 * http://javascript.nwbox.com/ContentLoaded/
 * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
 *
 * Notes:
 * based on code by Dean Edwards and John Resig
 * http://dean.edwards.name/weblog/2006/06/again/
 *
 */

// @w	window reference
// @f	function reference
function ContentLoaded(f) {
	var w = window;
	var	d = w.document,
		D = 'DOMContentLoaded',
		// user agent, version
		u = w.navigator.userAgent.toLowerCase(),
		v = parseFloat(u.match(/.+(?:rv|it|ml|ra|ie)[\/: ]([\d.]+)/)[1]);

	function init(e) {
		if (!document.isdomloaded) {
			document.isdomloaded = true;
			// pass a fake event if needed
			f((e.type && e.type == D) ? e : {
				type: D,
				target: d,
				eventPhase: 0,
				currentTarget: d,
				timeStamp: +new Date,
				eventType: e.type || e
			});
		}
	}

	// safari < 525.13
	if (/webkit\//.test(u) && v < 525.13) {

		(function () {
			if (/complete|loaded/.test(d.readyState)) {
				init('khtml-poll');
			} else {
				setTimeout(arguments.callee, 10);
			}
		})();

	// internet explorer all versions
	} else if (/msie/.test(u) && !w.opera) {

		d.attachEvent('onreadystatechange',
			function (e) {
				if (d.readyState == 'complete') {
					d.detachEvent('on'+e.type, arguments.callee);
					init(e);
				}
			}
		);
		if (w == top) {
			(function () {
				try {
					d.documentElement.doScroll('left');
				} catch (e) {
					setTimeout(arguments.callee, 10);
					return;
				}
				init('msie-poll');
			})();
		}

	// browsers having native DOMContentLoaded
	} else if (d.addEventListener &&
		(/opera\//.test(u) && v > 9) ||
		(/gecko\//.test(u) && v >= 1.8) ||
		(/khtml\//.test(u) && v >= 4.0) ||
		(/webkit\//.test(u) && v >= 525.13)) {

		d.addEventListener(D,
			function (e) {
				d.removeEventListener(D, arguments.callee, false);
				if (/webkit\//.test(u) ) {
					// bill: webkit sporadically has wrong dimensions for
					// horizontal menu items: at least .5 sec needed
					setTimeout( function() { init( e ); }, 500 );
				}
				else {
					init(e);
				}
			}, false
		);

	// fallback to last resort for older browsers
	} else {

		// from Simon Willison
		var oldonload = w.onload;
		w.onload = function (e) {
			init(e || w.event);
			if (typeof oldonload == 'function') {
				oldonload(e || w.event);
			}
		};
	}
}

function getCookie( c_name )
{
	if (document.cookie.length>0)
	{
		var c_start=document.cookie.lastIndexOf(c_name + "=");
		if (c_start != -1)
		{
			c_start=c_start + c_name.length + 1;
			var c_end=document.cookie.indexOf( ";" , c_start );
			if( c_end == -1 ) 
				c_end=document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
  		}
 	}
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
		";path=/" +
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function setViewPref( name, value )
{
	var val = getCookie( "mrp-view-prefs" );
	if( val.indexOf( name + "|" ) != -1 ) {
		var a = val.split( "," );
		for( var i=0; i<a.length; ++i ) {
			if( a[i].indexOf( name + "|" ) == 0 ) {
				a[i] = name + "|" + value;
				break;
			}
		}
		val = a.join( "," );
		//val = val.replace( new RegExp( name + "\\|[^,]+", "" ), name + "|" + value );
	}
	else {
		if( val.length > 0 ) {
			val += ",";
		}
		val += name + "|" + value;
	}
	setCookie( "mrp-view-prefs", val );
}

function getViewPref( name )
{
	var val = getCookie( "mrp-view-prefs" );
	var tks = val.split( "," );
	for( var i=0; i<tks.length; ++i ) {
		var nv = tks[i].split( "|" );
		if( nv && nv.length == 2 && name == nv[0] ) {
			return nv[1]
		}
	}
	return "";
}
function goToViewtop()
{
	var _u = window.location.href;
	if( _u ) {
	        var idx = _u.indexOf( "#" );
	        if( idx != -1 ) {
	                _u = _u.substring( 0, idx );
	        }
	        if( typeof window.location.replace == 'function' ) {
	        	window.location.replace( _u + "#viewtop" );
	        }
	        else {
	        	window.location = _u + "#viewtop";
	        }
	}
}

function scrollToAnchor( scrollTo )
{
	var loc = window.location.href;
	var idx = loc.indexOf( "#" );
	if( idx != -1 ) {
		loc = loc.substring( 0, idx );
	}
	window.location = loc + "#" + scrollTo;
}

function redirect( url )
{
	if( url && url.indexOf( "/" ) == 0 ) {
		window.location = url;
		return false;
	}
	
	// base tag
	if( document.getElementsByTagName ) {
		var elems = document.getElementsByTagName( 'base' );
		if( elems.length ) {
			var baseAddr = elems[ 0 ].href;
			if( baseAddr ) {
				var idx = baseAddr.lastIndexOf( "/" );
				if( idx != -1 ) {
					baseAddr = baseAddr.substring( 0, idx );
					url = baseAddr + "/" + url;
				}
			}
		}
	}
	window.location = url;
	return false;
}


// uom

var currentUnits = getViewPref( "uom" );
if( currentUnits != "i" && currentUnits != "m" ) {
	currentUnits = "i";
}
function showUnitSwitchTitle( switcher )
{
	var title = "Switch units of measure";
	if( currentUnits == "i" ) {
		title = "Show metric system measurements";
	}
	else {
		title = "Show imperial system measurements";
	}
	switcher.alt = title;
	switcher.title = title;
}

function switchToAltUnits()
{
	currentUnits = ( currentUnits == "i" ? "m" : "i" );
	switchUnits( currentUnits );
	setViewPref( "uom", currentUnits );
}
function switchUnits( units )
{
	var pref = "i-units";
	var alt = "m-units";
	currentUnits = "i";
	if( "m" == units ) {
		pref = "m-units";
		alt = "i-units";
		currentUnits = "m";
	}
	for( var i=1; i<100; ++i ) {
		var prefE = document.getElementById( pref + i );
		var altE = document.getElementById( alt + i );
		if( !pref && !altE ) {
			return;
		}
		if( prefE ) {
			prefE.style.display = "";
		}
		if( altE ) {
			altE.style.display = "none";
		}
	}
}

// end of uom

function isIELoaded()
{
	if( browser.isIE ) {
		try
		{
			if( "complete" == document.readyState ) {
				return true;
			}
			else {
				return false;
			}
		}
		catch( e )
		{
			return false;
		}
	}
	else {
		return true;
	}
}

function optimalHeight( desired )
{
	optimalWindowHeight( desired );
}

function optimalWindowHeight( desired )
{
	if( desired && desired < screen.availHeight ) {
		return desired;
	}
	
	var h = 500;
	if( screen.availHeight > 600 ) {
		h = 700;
	}
	if( screen.availHeight > 800 ) {
		h = 800;
	}
	return h;
}

function openNewWindow( url, width, height, name )
{
	if( !height ) {
		height = optimalWindowHeight();
	}

    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	
	if( !name ) {
		name = Math.random();
	}
	var w = window.open( url, name, "width=" + width + ",height=" + height + 
		",scrollbars=1,location=1,left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top );
	
	if( w == null ) {
		alert( "Please enable popups in your browser" );
	}
	else {
		w.focus();
	}
	
	return w;
}

