			
		// remote scripting library
		// (c) copyright 2005 modernmethod, inc
		var sajax_debug_mode = false;
		var sajax_request_type = "GET";
		var sajax_target_id = "";
		var sajax_failure_redirect = "";
		
		function sajax_debug(text) {
			if (sajax_debug_mode)
				alert(text);
		}
		
 		function sajax_init_object() {
 			sajax_debug("sajax_init_object() called..")
 			
 			var A;
 			
 			var msxmlhttp = new Array(
				'Msxml2.XMLHTTP.5.0',
				'Msxml2.XMLHTTP.4.0',
				'Msxml2.XMLHTTP.3.0',
				'Msxml2.XMLHTTP',
				'Microsoft.XMLHTTP');
			for (var i = 0; i < msxmlhttp.length; i++) {
				try {
					A = new ActiveXObject(msxmlhttp[i]);
				} catch (e) {
					A = null;
				}
			}
 			
			if(!A && typeof XMLHttpRequest != "undefined")
				A = new XMLHttpRequest();
			if (!A)
				sajax_debug("Could not create connection object.");
			return A;
		}
		
		var sajax_requests = new Array();
		
		function sajax_cancel() {
			for (var i = 0; i < sajax_requests.length; i++) 
				sajax_requests[i].abort();
		}
		
		function sajax_do_call(func_name, args) {
			var i, x, n;
			var uri;
			var post_data;
			var target_id;
			
			sajax_debug("in sajax_do_call().." + sajax_request_type + "/" + sajax_target_id);
			target_id = sajax_target_id;
			if (typeof(sajax_request_type) == "undefined" || sajax_request_type == "") 
				sajax_request_type = "GET";
			
			uri = "/lib/js/common.js.php?v=2_4_5";
			if (sajax_request_type == "GET") {
			
				if (uri.indexOf("?") == -1) 
					uri += "?rs=" + escape(func_name);
				else
					uri += "&rs=" + escape(func_name);
				uri += "&rst=" + escape(sajax_target_id);
				uri += "&rsrnd=" + new Date().getTime();
				
				for (i = 0; i < args.length-1; i++) 
					uri += "&rsargs[]=" + escape(args[i]);

				post_data = null;
			} 
			else if (sajax_request_type == "POST") {
				post_data = "rs=" + escape(func_name);
				post_data += "&rst=" + escape(sajax_target_id);
				post_data += "&rsrnd=" + new Date().getTime();
				
				for (i = 0; i < args.length-1; i++) 
					post_data = post_data + "&rsargs[]=" + escape(args[i]);
			}
			else {
				alert("Illegal request type: " + sajax_request_type);
			}
			
			x = sajax_init_object();
			if (x == null) {
				if (sajax_failure_redirect != "") {
					location.href = sajax_failure_redirect;
					return false;
				} else {
					sajax_debug("NULL sajax object for user agent:\n" + navigator.userAgent);
					return false;
				}
			} else {
				x.open(sajax_request_type, uri, true);
				// window.open(uri);
				
				sajax_requests[sajax_requests.length] = x;
				
				if (sajax_request_type == "POST") {
					x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
					x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				}
			
				x.onreadystatechange = function() {
					if (x.readyState != 4) 
						return;

					sajax_debug("received " + x.responseText);
				
					var status;
					var data;
					var txt = x.responseText.replace(/^\s*|\s*$/g,"");
					status = txt.charAt(0);
					data = txt.substring(2);

					if (status == "") {
						// let's just assume this is a pre-response bailout and let it slide for now
					} else if (status == "-") 
						alert("Error: " + data);
					else {
						if (target_id != "") 
							document.getElementById(target_id).innerHTML = eval(data);
						else {
							try {
								var callback;
								var extra_data = false;
								if (typeof args[args.length-1] == "object") {
									callback = args[args.length-1].callback;
									extra_data = args[args.length-1].extra_data;
								} else {
									callback = args[args.length-1];
								}
								callback(eval(data), extra_data);
							} catch (e) {
								sajax_debug("Caught error " + e + ": Could not eval " + data );
							}
						}
					}
				}
			}
			
			sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
			x.send(post_data);
			sajax_debug(func_name + " waiting..");
			delete x;
			return true;
		}
		
				
		// wrapper for acknowledge_im		
		function x_acknowledge_im() {
			sajax_do_call("acknowledge_im",
				x_acknowledge_im.arguments);
		}
		
				
		// wrapper for finished_reading_admin_message		
		function x_finished_reading_admin_message() {
			sajax_do_call("finished_reading_admin_message",
				x_finished_reading_admin_message.arguments);
		}
		
				
		// wrapper for create_album		
		function x_create_album() {
			sajax_do_call("create_album",
				x_create_album.arguments);
		}
		
				
		// wrapper for get_video_preview		
		function x_get_video_preview() {
			sajax_do_call("get_video_preview",
				x_get_video_preview.arguments);
		}
		
		
	
	function callback_acknowledge_im(z) {}
	function do_acknowledge_im(ident) {
		x_acknowledge_im(ident, callback_acknowledge_im);
	}
	
	// Video Preview
	function callback_get_video_preview(z) {
		$("#preview").html(z);
		$("#preview_indicator").hide();
	}
	function do_get_video_preview(url) {
		$("#preview_indicator").show();
		$("#preview_note").hide();
		x_get_video_preview(url, callback_get_video_preview);
	}
	function clear_video_preview() {
		$("#preview").html();
		$("#preview_note").hide();
	}
	
// -= Userplane =- 
function up_launchWM( userID, destinationUserID, destinationName ) {
	window.open( "/lib/userplane/wm.php?strDestinationUserID=" + destinationUserID, "WMWindow_" + up_replaceAlpha(userID) + "_" + up_replaceAlpha(destinationUserID), "width=468,height=595,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}
function up_launchUL( ) {
	window.open( "ul.php", "UL_Window", "width=220,height=700,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}

function up_replaceAlpha( strIn ) {
	var strOut = "";
	for( var i = 0 ; i < strIn.length ; i++ )
	{
		var cChar = strIn.charAt(i);
		if( ( cChar >= 'A' && cChar <= 'Z' )
			|| ( cChar >= 'a' && cChar <= 'z' )
			|| ( cChar >= '0' && cChar <= '9' ) )
		{
			strOut += cChar;
		}
		else
		{
			strOut += "_";
		}
	}
	return strOut;
}
function pop_im(z) {
	window.open('{$CFG->wwwroot}im.php?dst='+z,'window'+z,'width=480,height=480,scrollbars=yes,status=yes');
}

function pop_chat(c) {
	window.open('{$CFG->wwwroot}do/chat?dst='+c,'window'+c,'width=800,height=600,scrollbars=yes,status=yes');
}

function pop_url(url, w, h) {
	window.open(url,'window_url','width='+w+',height='+h+',scrollbars=yes,status=yes');
}

		function csEvent( strEvent, strParameter1, strParameter2, cssID )
		{
			if( strEvent == "InstantCommunicator.StartConversation" )
			{
				var strUserID = strParameter1;
				var bServer = strParameter2;
				// open up an InstantCommunicator window.  For example:
				launchWM( "", strUserID );
			}
			else if( strEvent == "User.ViewProfile" )
			{
				var strUserID = strParameter1;
			}
			else if( strEvent == "User.Block" )
			{
				var strBlockedUserID = strParameter1;
				var bBlocked = strParameter2;
			}
			else if( strEvent == "User.AddFriend" )
			{
				var strFriendUserID = strParameter1;
				var bFriend = strParameter2;
			}
			else if( strEvent == "Chat.Help" )
			{
			}
			else if( strEvent == "User.NoTextEntry" )
			{
			}
			else if( strEvent == "Minichat.LaunchWebchat" )
			{
			}
			else if( strEvent == "Connection.Success" )
			{
			}
			else if( strEvent == "Connection.Failure" )
			{
				if( strParameter1 == "Session.Timeout" )
				{
					//handle timeout here, both inactivity and session timeouts
				}
				if( strParameter1 == "User.Banned" )
				{
					//handle ban event here
				}
			}
		}
		function launchWM( userID, destinationUserID )
		{
			var popupWindowTest = window.open( "wm.php?strDestinationUserID=" + destinationUserID, "WMWindow_" + replaceAlpha(userID) + "_" + replaceAlpha(destinationUserID), "width=360,height=397,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
			if( popupWindowTest == null )
			{
				alert( "Your popup blocker stopped an IM window from opening" );
			}
		}
		
		function replaceAlpha( strIn )
		{
			var strOut = "";
			for( var i = 0 ; i < strIn.length ; i++ )
			{
				var cChar = strIn.charAt(i);
				if( ( cChar >= 'A' && cChar <= 'Z' )
					|| ( cChar >= 'a' && cChar <= 'z' )
					|| ( cChar >= '0' && cChar <= '9' ) )
				{
					strOut += cChar;
				}
				else
				{
					strOut += "_";
				}
			}
			
			return strOut;
		}
		
		function getLocaleData( cssID )
		{
			var data = new Object();
			data.historyNotificationMessage = "********** The messages above were sent before you arrived";
			data.whisperHowToMessage = "********** To send a private message, type: <nameOfUser> your message here";
			data.userJoinNotificationMessage = "********** at TIMESTAMP SCREEN_NAME joined the room";
			data.userLeaveNotificationMessage = "********** at TIMESTAMP SCREEN_NAME left the room";
			data.userNameChangeNotificationMessage = "********** SCREEN_NAME has changed their name to NEW_SCREEN_NAME";
			data.userMessageSentMessage = "SCREEN_NAME: MESSAGE";
			data.textAdvertisementMessage = "Check out our sponsored link:";
			data.userNotAuthorizedErrorMessage = "You could not be authorized.\n\nPlease re-login to the\nwebsite and try again.";
			data.serverLicenseErrorMessage = "The license for this\nUserplane app is no longer valid.\n\nYou should have your webmaster contact\nUserplane Support (support@userplane.com)\nto resolve this issue.";
			data.userBanNoticeErrorMessage = "You've been banned from this\napplication by a site administrator.\n\nYou'll need to get in touch with them\nfor more information.";
			data.clientVersionErrorMessage = "Your web browser is running an old\nversion of this application.\n\nYou should empty your browser's cache\nand log back in.";
			data.serverMaxUsersErrorMessage = "The chat has reached the max\nallowed number of users.\nPlease try again later.";
			data.serverNoAdminErrorMessage = "This chat requires that an Admin is\nlogged in at all times.\nCurrently none are connected.\nPlease try again later.";
			data.invalidDomainErrorMessage = "This chat is currently offline";
			data.whisperSentMessage = "You whispered to SCREEN_NAME";
			data.whisperNotSentMessage = "Your whisper wasn't sent. Please check the name and try again";
			data.whisperReceivedMessage = "SCREEN_NAME whispers";
			data.whisperPersonalMessage = "You whispered to yourself";
			data.floodControlSlowDownMessage = "********** Please slow down. You must wait a few seconds";
			data.floodControlResumeMessage = "********** You may now resume sending";

			if( cssID == "mc" )
			{
				data.userJoinNotificationMessage = "********** at TIMESTAMP SCREEN_NAME joined the Minichat";
				data.userLeaveNotificationMessage = "********** at TIMESTAMP SCREEN_NAME left the Minichat";
				data.userCountLabel = "chatting";
				data.watcherCountLabel = "observing";
				data.copyrightText = "©2007 Userplane";
			}
			return data;
		}

		function getPreferences( cssID )
		{
			var data = new Object();
			if( cssID == "mc" )
			{
				data.useTimestamps = false;
				data.branding = "Userplane Webchat";
				data.brandingOpacity = 0.50;
				data.chatButtonLabel = "Enter Chat";
				data.sendMessageButtonLabel = "Post Message";
				data.showMinichatFooter = true;
				data.minichatBuddyPicURL = "";
				data.showMinichatBuddyPic = false;
				data.showMinichatDescription = true;
				data.showMinichatRoomName = true;
				data.minichatBuddyPicMaxWidth = 160;
				data.minichatBuddyPicMaxHeight = 60;
				data.minichatBackgroundColor = "FFA500";
				data.minichatForegroundColor = "FFFFFF";
				data.minichatConversationBackgroundColor = "FFFFFF";
				data.minichatConversationBorderColor = "00D2FF";
				data.minichatConversationLinkColor = "";
				data.minichatConversationForegroundColor = "";
				data.minichatConversationWhisperColor = "";
				data.minichatConversationAnnouncementColor = "";
				data.onlineUserMessageColor = "";
				data.localUserMessageColor = "";
				data.scrollBarBorderColor = "";
				data.scrollbarTrackColor = "";
				data.scrollbarThumbColor = "";
				data.overrideCustomFontColors  = "false";
				data.useHistoryColor = "false";
				data.historyColor = "";
				data.roomUserlistWidth = "";
			}
			return data;
		}

/*
// -= Contact Importer =-
function SetAllCheckBoxes(FormName, FieldName, CheckValue) {
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}
function SendCheckboxListToParent(FormName, FieldName, Parent) {
	var EmailList = "";
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else {
		for(var i = 0; i < countCheckBoxes; i++) {
			if(objCheckBoxes[i].checked) {
				EmailList += objCheckBoxes[i].value + ", ";
			}
		}
	}	
			
	opener.document.getElementById(Parent).value = opener.document.getElementById(Parent).value + EmailList;
	window.close();	
}

var messages_selected = 0;

function submitMessagesAction(select,actionform,msg){
  if(select.options[select.selectedIndex].value!=-1 && select.options[select.selectedIndex].value!='delete' && messages_selected>0){
    actionform.submit();
  }
  else if(select.options[select.selectedIndex].value=='delete' && messages_selected>0){
  	if(confirm(msg)){
  	  actionform.submit();
  	}
  }
}

function mark(check){
  if(check.checked){
    messages_selected++;
  }
  else{
    messages_selected--;
  }
}

$.ready(function(){ 
	$('.condense').each(function(elm) { new Condensable(elm) });
});

 var Condensable = Class.create({
	initialize : function(elm){
		this.elm = elm = $(elm);		
		this.toggler = $(this.elm.getElementsByClassName('toggler')[0]);
		this.toggler.observe('click', this.toggle.bind(this));	

		//this.toggler.observe('mouseover', function() { this.addClassName('hover'); });
		//this.toggler.observe('mouseout', function() { this.removeClassName('hover'); });

		this.elm.hasClassName('isCondensed') ? this.condense() : null;

		return this;
 	},
	toggle: function() {
		return this.elm.hasClassName('isCondensed')? this.unCondense() : this.condense();
	},
	condense: function(value) {
		this.elm.addClassName('isCondensed');
		return this;
	},
	unCondense: function() {
		this.elm.removeClassName('isCondensed');
		return this;
	}
}); */
	
	/* -= Poller =- */
	ping_time = 3000;
	function startnextpoll() {
 		$.getScript("http://www.wearebreathless.org/poll", function(data){
			ping_time = Math.min(ping_time * 1.5, 180000);
			setTimeout(startnextpoll, ping_time);
		});
	}
	
	/* -= Tiny MCE =- */
	function init_tinymce(id, mode, tabindex) { 
		if(mode == 'compact') {
			buttons = "fontsizeselect,forecolor,bold,italic,underline,justifyleft,justifycenter,link,unlink,code,emotions";
		} else {
			buttons = "fontsizeselect,forecolor,bold,italic,underline,justifyleft,justifycenter,undo,redo,link,unlink,fontselect,code,emotions";
		}
		tinyMCE.init({
			mode : "exact",
			elements : id,
			theme : "advanced",
			plugins : "emotions",
			theme_advanced_buttons1 : buttons,
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			content_css : "/styles.css?mode=tinymce&v=2_4_5",
			relative_urls : false,
			tab_focus : ':prev,:next'
		}); 
	}
	
 	// Inline Thought Edit
	function makeThoughtEditable(e) {
		$(this).hide();
		$("#frame_thought_edit").show();
		$("#thought_value").focus();
	}
	function updateThought(e) {
		var new_thought_val = $(this).val();
		$("#frame_thought_edit").hide();
		$("#frame_thought_display").show();
		if(new_thought_val = $.trim(new_thought_val)) {
			$("#frame_thought_display").load('/rpc?action=thought_save', {'new_thought': new_thought_val});
		} else {
			$(this).val('');
		}
	}
	
	$(document).ready(function(){
		
	 	setTimeout(startnextpoll, ping_time);
		
		// Collapsible regions
/* 		$('.condense').each(function(){
			$(this).find('.toggler').bind('mousedown',function(){
				var condensable = $(this).siblings('.condensable');
				if(condensable.css('height') == '0px') condensable.css('height', 'auto');
				else condensable.css('height', '0px');
			});
		}); */
		
		// Modals
		$('ul.nav li.share a').modaload();
		$('a.sign_in').modaload();
		$('a.modaload').modaload();
		
		// Add hover class to nav elements.
		$('ul.nav.promo li').hover(function () {$(this).addClass("hover");},function () {$(this).removeClass("hover");});
	});
	
	function updateUserChatCount(count) {
		var msg_el = $('#sidebar-chat-count .msg');
		var current = $('#sidebar-chat-count .msg .count').html();
		if(current == count) return;
		if(count == 1) {
			msg_el.html("<span class='count'>"+count+"</span> <span class='user-inf'>person</span> Chatting");
		} else if(count != 0) {
			msg_el.html("<span class='count'>"+count+"</span> <span class='user-inf'>people</span> Chatting");
		} else {
			msg_el.html("Start a Chat");
		}
		if(count > current) {
			var pip_el = $('#pip');
			if(pip_el.length == 0) { 
				pip_el = $(document.createElement("div")).attr("id", "pip");
				$('body').append($(pip_el));
				pos = $('#sidebar-chat-count').offset();
				pip_el.css({top: (pos.top - 30), left: (pos.left-52)});
			}
			pip_el.fadeIn("1000", function(){
				setTimeout(function(){
					$('#pip').fadeOut("1000");
				}, 500);
			});
		}
	}

	function submit_flash() {
		var Flash;
		if(document.embeds && document.embeds.length>=1 && navigator.userAgent.indexOf("Safari") == -1)
			Flash = document.getElementById("EmbedFlashFilesUpload");
		else
			Flash = document.getElementById("FlashFilesUpload");
		var FormObj = document.getElementById("upload");

		var FormValues = '';
		for (var i = 0; i<FormObj.elements.length; i++)
			FormValues += escape(FormObj.elements[i].name) + '=' + escape(FormObj.elements[i].value) + ((i!=(FormObj.elements.length-1))?'&':'');
		Flash.SetVariable("SubmitFlash", FormValues); 
	}
	
	var t; 
	function initWYMeditor(id, height_val) {
		$('#'+id).wymeditor({ 
			toolsItems: [
			  {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
			  {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
			  {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
			  {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
			  {'name': 'InsertImage', 'title': 'Image', 'css': 'wym_tools_image'},
			  {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
			  {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
			  {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'}
			],  
			preInit: function(wym) {
			  $('#'+id+'_wrapper').css('visibility', 'hidden');
			},
			postInit: function(wym) {
				var parent_form = $('#'+id).parents('form').eq(0);
				var iframe = $(wym.box).find('iframe');
				var html_box = $(wym.box).find('.wym_html');
				
				$('#'+id).data('wym', wym);
				parent_form.bind('submit', function(){wym.update()});
				iframe.height(height_val);
				html_box.css('display', 'none');
				$('#'+id).css('display', 'none');
				$('#'+id+'_wrapper').css('visibility', 'visible');
				
				// Update every 3 sec after input.
				wym.bindKeypress(function(){
					clearTimeout(t);
					t = setTimeout(function(){
						wym.update();
						$(wym._element[0]).change();
					}, 1000);
				}); 
			}
		});
	}
	$.fn.extend({wVal: function(value){$(this).data('wym').html(value)}});
	
	// Populate tag field based on tag_suggest rpc response
	function tag_suggest_onchange (){
		var $tags_field = $('#tags_field');
		
		var all_tags = $tags_field.val().split(',');
			all_tags = $.makeArray(all_tags);
		$.each(all_tags, function(i,text) {
			all_tags[i] = $.trim(text);
		});
		all_tags = $.grep(all_tags.unique(), function (t) { return t != ''; });
		
		var generated_tags = $.makeArray($tags_field.data('generated_tags'));
		
		var user_tags = new Array();
		$.each(all_tags, function(i, tag){
			if($.inArray(tag, generated_tags) < 0) {
				user_tags.push(tag);
			}
		}); 
		$tags_field.data('user_tags', user_tags);
		
		var new_taglist = $.merge(generated_tags, user_tags);
		new_taglist = $.makeArray(new_taglist);
		$tags_field.val(new_taglist.join(', '));
	}
	
	// Populate tag field based on tag_suggest rpc response
	function tag_suggest_callback (data){
		if(data) {
			var $tags_field = $('#tags_field');
			var user_tags = $.makeArray($tags_field.data('user_tags'));			
			generated_tags = $.makeArray(data);
			$tags_field.data('generated_tags', generated_tags);
			
			var new_taglist = $.merge(user_tags, generated_tags);
			new_taglist = $.makeArray(new_taglist);
			new_taglist = $.grep(new_taglist.unique(), function (t) { return t != ''; });
			$tags_field.val(new_taglist.join(', '));
		}
	}
