
	function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
	}
	 
	function ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	 
	function rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	
	// ----------
	// These two work together...
	// ----------
	function clearHTML(element){
		document.getElementById(element).innerHTML = '';	
	}
	function clearHTMLTimed(element, seconds){
		setTimeout("clearHTML('"+element+"')", seconds);
	}
	// ----------
	
	function popUp(url,width,height) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=no,scrollbars=auto,location=0,statusbar=no,menubar=no,resizable=0,width="+width+",height="+height+",left = 540,top = 312');");
	}

	function toggle_login(){
		if(document.getElementById('login').style.display == 'none'){
			document.getElementById('login').style.display = 'block';
			document.getElementById('imlogin').style.display = 'none';
			//document.getElementById('login_username').focus();
		}else{
			document.getElementById('login').style.display = 'none';
			document.getElementById('imlogin').style.display = 'block';
		}
	}
	
	function loader(return_id) {
		document.getElementById(return_id).innerHTML = "<img src='images/loader.gif' />";
	}
	
	function runSavedSearch(){
		var dropdownIndex = document.getElementById('saved_search_dropdown').selectedIndex;
		var dropdownValue = document.getElementById('saved_search_dropdown')[dropdownIndex].value;
		document.location.href= dropdownValue;	
	}
	
	function runSavedSearch_az(id){
		document.location.href= id;	
	}
	
	
	function append_div(id){
		var div_tag = document.createElement("div");
		div_tag.id = "user_"+id;
		document.getElementById('csma_multiple').appendChild(div_tag);
		document.getElementById('csma_select').innerHTML = '';
		document.getElementById('csma_select').style.display = 'none';
		document.getElementById('csma_friend').value = '';
		get_data('classes/messaging/messaging_ajax.php?action=lookup&id='+id,'user_'+id);
	} 
	
	function remove_element(who) {
		 if(typeof who== 'string') who=document.getElementById(who);
		 if(who && who.parentNode)who.parentNode.removeChild(who);
	}
	
	function menu(menu_id){
		var element = document.getElementById(menu_id);
		if(element.style.display == 'none') element.style.display = 'block';
		else element.style.display = 'none';
		element.blur();
		return false;
	}
	
	function fontSmall() {
		var p = document.getElementsByTagName('div');
		for(i=0;i<p.length;i++) {
		  if(p[i].style.fontSize) {
			 var s = parseInt(p[i].style.fontSize.replace("px",""));
		  } else {
			 var s = 12;
		  }
			s -= 2;
		  p[i].style.fontSize = s+"px"
		}
	}
	
	function fontLarge() {
		var p = document.getElementsByTagName('div');
		for(i=0;i<p.length;i++) {
		  if(p[i].style.fontSize) {
			 var s = parseInt(p[i].style.fontSize.replace("px",""));
		  } else {
			 var s = 12;
		  }
			s += 2;
		  p[i].style.fontSize = s+"px"
		}   
	}
	
	function switch_profile_pic(url){
		document.getElementById('main_image').src = url;
	}
	
	function tooltip_on(id){
		if(document.getElementById(id)){
			document.getElementById(id).style.display='block';	
		}
	}
	
	function tooltip_off(id){
		if(document.getElementById(id)){
			document.getElementById(id).style.display='none';	
		}
	}
	
	function expand_content(){
		document.getElementById('content').style.height='';
		document.getElementById('content').style.overflow='';
	}
	
	function toggle_left(div,a){
		var name = document.getElementById(div);
		var a = document.getElementById(a);
		this.innerHTML = "<img src=\"images/btn_minus.png\" />";
		if(name.style.display == 'none'){
			get_data('ajax/widgets_update.php?action=on&wid='+div,'');
			//get_data('ajax/widgets_update.php?action=on&wid='+div,div);
			name.style.display = 'block';
			//alert(name.style.display);
			a.innerHTML = "<img src=\"images/btn_minus.png\" />";
			a.blur();
		}else{
			get_data('ajax/widgets_update.php?action=off&wid='+div,'');
			//get_data('ajax/widgets_update.php?action=off&wid='+div,div);
			name.style.display = 'none';
			a.innerHTML = "<img src=\"images/btn_plus.png\" />";
			a.blur();
		}
	}
	
	
	
	
	/*      MAIL FUNCTIONS          */
	
	function addRecipient(){
		var recipient = document.getElementById('add').value;
		var array = recipient.split("#");
		
		user_id = array[0];
		username = array[1];
		
		var double = document.getElementById('user_id_'+user_id);
		if(double){
			alert('This recipient is already in your list');
			return false;
		}
		
		var recipients = document.getElementById('recipients');
		recipients.innerHTML += createRecipient(user_id,username);
	}
	
	function createRecipient(user_id,username){
		var string="";
		string += "<div class=\"recipient_box\" id=\"user_id_"+user_id+"\">";
		string += "<input type=\"hidden\" name=\"user_id[]\" value=\""+user_id+"\" />";
		string += username;
		string += "<a class=\"remove_box\" href=\"#\" onclick=\"removeRecipient('"+user_id+"');return false;\">X</a>";
		string += "</div>";
		return string;
	}
	
	function removeRecipient(user_id) {
	  var outerDiv = document.getElementById('recipients');
	  var removeDiv = document.getElementById('user_id_'+user_id);
	  outerDiv.removeChild(removeDiv);
	}
	
	
	/*			OVERLAY FUNCTIONS			*/
	
	function showOverlay(div_id){
		document.getElementById(div_id).style.display = 'block';
	}
	function hideOverlay(div_id){
		document.getElementById(div_id).style.display = 'none';
	}
	
	var b = 2;
var i = 2;
var u = 2;
var q = 2;
var c = 2;
var url = 2;
var img = 2;
var url_selStart = 0;
var url_selEnd = 0;
var img_selStart = 0;
var img_selEnd = 0;
var is_selected = false;

var isIE = (document.attachEvent)? true : false;

	function add(open, end) {
			
	var tArea = document.write_message.post;
	
	var sct = tArea.scrollTop;
	var open = (open)? open : "";
	var end = (end)? end : "";
	var sl;	
	if(isIE){
		tArea.focus();
		var curSelect = document.selection.createRange();
		//if(arguments[2]){
		//	curSelect.text = open + arguments[2] + "]" + curSelect.text + end;
		//} else {
			curSelect.text = open + curSelect.text + end;
		//}
	} else if(!isIE && typeof tArea.selectionStart != "undefined"){
		var selStart = tArea.value.substr(0, tArea.selectionStart);
		var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length);
		var curSelection = tArea.value.replace(selStart, "").replace(selEnd, "");
		//if(arguments[2]){
		//	sl = selStart + open + arguments[2] + "]" + curSelection + end;
		//	tArea.value = sl + selEnd;
		//} else {
			sl = selStart + open + curSelection + end;
			tArea.value = sl + selEnd;
		//}
		tArea.setSelectionRange(sl.length, sl.length);
		tArea.focus();
		tArea.scrollTop = sct;
	} else {
		//tArea.value += (arguments[2])? open + arguments[2] + "]" + end : open + end;
		tArea.value += open + end;
	}
	return;
}

