function pop_im(z) {
	window.open('http://www.wearehd.org/im.php?dst='+z,'window'+z,'width=480,height=480,scrollbars=yes,status=yes');
}

function pop_chat(c) {
	window.open('http://www.wearehd.org/chat.php?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 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();	
}			
		// 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/common_2_0.js.php?";
			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 push_im		
		function x_push_im() {
			sajax_do_call("push_im",
				x_push_im.arguments);
		}
		
				
		// 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 save_thought		
		function x_save_thought() {
			sajax_do_call("save_thought",
				x_save_thought.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);
		}
		
		

	window.onload = function(){
    	timer = setTimeout('do_im_push()', 5000);
	}
	
	function exec_im_push(z) {
		if(z != 0) {
			eval(z);
		}
		else {
			timer = setTimeout('do_im_push()', 5000);
		}
	}
	
	function callback_acknowledge_im(z) {
		timer = setTimeout('do_im_push()', 5000);
	}
	
	function do_acknowledge_im(ident) {
		x_acknowledge_im(ident, callback_acknowledge_im);
	}
	
	function do_im_push() {
		x_push_im(0, exec_im_push);
	}
	
	function callback_finished_reading_admin_message() {
		var admin_message_div = document.getElementById("admin_message");
		admin_message_div.style.display = "none";
	}
	
	function do_finished_reading_admin_message() {
		x_finished_reading_admin_message(0, callback_finished_reading_admin_message);
	}
	
	function do_edit_thought() {
		var frame_thought_edit = document.getElementById("frame_thought_edit");
		var frame_thought_display = document.getElementById("frame_thought_display");
		var thought_value = document.getElementById("thought_value");
		
		frame_thought_display.style.display = "none";
		frame_thought_edit.style.display = "block";
		thought_value.focus();
	}
	
	function listen_enter_thought(event) {
		if(event.keyCode == 13) {
			do_save_thought();
		}
	}
	
	function callback_save_thought(z) {
		var frame_thought_edit = document.getElementById("frame_thought_edit");
		var frame_thought_display = document.getElementById("frame_thought_display");
		var thought_value = document.getElementById("thought_value");
		var thought_display = document.getElementById("thought_display");
		
		thought_display.innerHTML = z;
	}

	function do_save_thought() {
		var frame_thought_edit = document.getElementById("frame_thought_edit");
		var frame_thought_display = document.getElementById("frame_thought_display");
		var thought_value = document.getElementById("thought_value");

		if(thought_value.value.trim() != '') {
			x_save_thought(0, thought_value.value, callback_save_thought);
		}
		
		thought_value.value = "";
		frame_thought_display.style.display = "block";
		frame_thought_edit.style.display = "none";
	}
	
	function callback_get_video_preview(z) {
		var preview_window = document.getElementById("preview");
		var preview_indicator = document.getElementById("preview_indicator");
		preview_window.innerHTML = z;
		preview_indicator.style.display = "none";
	}
	function do_get_video_preview(url) {
		var preview_indicator = document.getElementById("preview_indicator");
		var preview_note = document.getElementById("preview_note");
		preview_note.style.display = "none";
		preview_indicator.style.display = "block";
		x_get_video_preview(url, callback_get_video_preview);
	}
	function clear_video_preview() {
		var preview_window = document.getElementById("preview");
		var preview_note = document.getElementById("preview_note");
		preview_note.style.display = "block";
		preview_window.innerHTML = "";
	}
	
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--;
  }
}

Event.observe(window,'load',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;
	}
});

var CSS={hasClass:function(element,className){if(element&&className&&element.className){return new RegExp('\\b'+trim(className)+'\\b').test(element.className);}
return false;},addClass:function(element,className){if(element&&className){if(!CSS.hasClass(element,className)){if(element.className){element.className+=' '+trim(className);}else{element.className=trim(className);}}}
return this;},removeClass:function(element,className){if(element&&className&&element.className){className=trim(className);var regexp=new RegExp('\\b'+className+'\\b','g');element.className=element.className.replace(regexp,'');}
return this;},setClass:function(element,className){element.className=className;return this;},toggleClass:function(element,className){if(CSS.hasClass(element,className)){return CSS.removeClass(element,className);}else{return CSS.addClass(element,className);}},getStyle:function(element,property){element=$(element);function hyphenate(property){return property.replace(/[A-Z]/g,function(match){return'-'+match.toLowerCase();});}
if(window.getComputedStyle){return window.getComputedStyle(element,null).getPropertyValue(hyphenate(property));}
if(document.defaultView&&document.defaultView.getComputedStyle){var computedStyle=document.defaultView.getComputedStyle(element,null);if(computedStyle)
return computedStyle.getPropertyValue(hyphenate(property));if(property=="display")
return"none";Util.error("Can't retrieve requested style %q due to a bug in Safari",property);}
if(element.currentStyle){return element.currentStyle[property];}
return element.style[property];},setOpacity:function(element,opacity){var opaque=(opacity==1);try{element.style.opacity=(opaque?'':''+opacity);}catch(ignored){}
try{element.style.filter=(opaque?'':'alpha(opacity='+(opacity*100)+')');}catch(ignored){}},getOpacity:function(element){var opacity=get_style(element,'filter');var val=null;if(opacity&&(val=/(\d+(?:\.\d+)?)/.exec(opacity))){return parseFloat(val.pop())/100;}else if(opacity=get_style(element,'opacity')){return parseFloat(opacity);}else{return 1.0;}},Cursor:{kGrabbable:'grabbable',kGrabbing:'grabbing',kEditable:'editable',set:function(element,name){element=element||document.body;switch(name){case CSS.Cursor.kEditable:name='text';break;case CSS.Cursor.kGrabbable:if(ua.firefox()){name='-moz-grab';}else{name='move';}
break;case CSS.Cursor.kGrabbing:if(ua.firefox()){name='-moz-grabbing';}else{name='move';}
break;}
element.style.cursor=name;}}};var has_css_class_name=CSS.hasClass;var add_css_class_name=CSS.addClass;var remove_css_class_name=CSS.removeClass;var toggle_css_class_name=CSS.toggleClass;var get_style=CSS.getStyle;var set_opacity=CSS.setOpacity;var get_opacity=CSS.getOpacity;

String.prototype.trim=function(){if(this==window){return null;}
return this.replace(/^\s*|\s*$/g,'');}
function trim(text){return String(text).trim();}
String.prototype.startsWith=function(substr){if(this==window){return null;}
return this.substring(0,substr.length)==substr;};String.prototype.split=(function(split){return function(separator,limit){var flags="";if(separator===null||limit===null){return[];}else if(typeof separator=='string'){return split.call(this,separator,limit);}else if(separator===undefined){return[this.toString()];}else if(separator instanceof RegExp){if(!separator._2||!separator._1){flags=separator.toString().replace(/^[\S\s]+\//,"");if(!separator._1){if(!separator.global){separator._1=new RegExp(separator.source,"g"+flags);}else{separator._1=1;}}}
separator1=separator._1==1?separator:separator._1;var separator2=(separator._2?separator._2:separator._2=new RegExp("^"+separator1.source+"$",flags));if(limit===undefined||limit<0){limit=false;}else{limit=Math.floor(limit);if(!limit)return[];}
var match,output=[],lastLastIndex=0,i=0;while((limit?i++<=limit:true)&&(match=separator1.exec(this))){if((match[0].length===0)&&(separator1.lastIndex>match.index)){separator1.lastIndex--;}
if(separator1.lastIndex>lastLastIndex){if(match.length>1){match[0].replace(separator2,function(){for(var j=1;j<arguments.length-2;j++){if(arguments[j]===undefined)match[j]=undefined;}});}
output=output.concat(this.substring(lastLastIndex,match.index),(match.index===this.length?[]:match.slice(1)));lastLastIndex=separator1.lastIndex;}
if(match[0].length===0){separator1.lastIndex++;}}
return(lastLastIndex===this.length)?(separator1.test("")?output:output.concat("")):(limit?output:output.concat(this.substring(lastLastIndex)));}else{return split.call(this,separator,limit);}}})(String.prototype.split);

function clear_tooltip(icon_link){var tooltip=icon_link.previousSibling;tooltip.style.display='none';}

function profile_icon_hover(icon_link){var tooltip=icon_link.previousSibling;tooltip.style.display='block';tooltip.style.zindex=1;if(has_css_class_name(tooltip,'loaded_tooltip')){visible_tooltip=tooltip;return;}
var offsetWidth=tooltip.childNodes[0].offsetWidth;tooltip.style.width=offsetWidth+'px';tooltip.style.left=-((offsetWidth-22)/2)+'px';tooltip.style.top=-32+'px';add_css_class_name(tooltip,'loaded_tooltip');visible_tooltip=tooltip;}