// <?php !! This fools phpdocumentor into parsing this file
/**
* @version $Id: joomla.javascript.js 2316 2006-02-12 17:41:33Z stingrey $
* @package Joomla
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* Joomla! is Free Software
*/

// general utility for browsing a named array or object
function xshow(o) {
	s = '';
	for(e in o) {s += e+'='+o[e]+'\n';}
	alert( s );
}

/**
* Writes a dynamically generated list
* @param string The parameters to insert into the <select> tag
* @param array A javascript array of list options in the form [key,value,text]
* @param string The key to display for the initial state of the list
* @param string The original key that was selected
* @param string The original item value that was selected
*/
function writeDynaList( selectParams, source, key, orig_key, orig_val ) {
	var html = '\n	<select ' + selectParams + '>';
	var i = 0;
	for (x in source) {
		if (source[x][0] == key) {
			var selected = '';
			if ((orig_key == key && orig_val == source[x][1]) || (i == 0 && orig_key != key)) {
				selected = 'selected="selected"';
			}
			html += '\n		<option value="'+source[x][1]+'" '+selected+'>'+source[x][2]+'</option>';
		}
		i++;
	}
	html += '\n	</select>';

	document.writeln( html );
}

/**
* Changes a dynamically generated list
* @param string The name of the list to change
* @param array A javascript array of list options in the form [key,value,text]
* @param string The key to display
* @param string The original key that was selected
* @param string The original item value that was selected
*/
function changeDynaList( listname, source, key, orig_key, orig_val ) {
	var list = eval( 'document.adminForm.' + listname );

	// empty the list
	for (i in list.options.length) {
		list.options[i] = null;
	}
	i = 0;
	for (x in source) {
		if (source[x][0] == key) {
			opt = new Option();
			opt.value = source[x][1];
			opt.text = source[x][2];

			if ((orig_key == key && orig_val == opt.value) || i == 0) {
				opt.selected = true;
			}
			list.options[i++] = opt;
		}
	}
	list.length = i;
}

/**
* Adds a select item(s) from one list to another
*/
function addSelectedToList( frmName, srcListName, tgtListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var tgtList = eval( 'form.' + tgtListName );

	var srcLen = srcList.length;
	var tgtLen = tgtList.length;
	var tgt = "x";

	//build array of target items
	for (var i=tgtLen-1; i > -1; i--) {
		tgt += "," + tgtList.options[i].value + ","
	}

	//Pull selected resources and add them to list
	//for (var i=srcLen-1; i > -1; i--) {
	for (var i=0; i < srcLen; i++) {
		if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
			opt = new Option( srcList.options[i].text, srcList.options[i].value );
			tgtList.options[tgtList.length] = opt;
		}
	}
}

function delSelectedFromList( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected) {
			srcList.options[i] = null;
		}
	}
}

function moveInList( frmName, srcListName, index, to) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var total = srcList.options.length-1;

	if (index == -1) {
		return false;
	}
	if (to == +1 && index == total) {
		return false;
	}
	if (to == -1 && index == 0) {
		return false;
	}

	var items = new Array;
	var values = new Array;

	for (i=total; i >= 0; i--) {
		items[i] = srcList.options[i].text;
		values[i] = srcList.options[i].value;
	}
	for (i = total; i >= 0; i--) {
		if (index == i) {
			srcList.options[i + to] = new Option(items[i],values[i], 0, 1);
			srcList.options[i] = new Option(items[i+to], values[i+to]);
			i--;
		} else {
			srcList.options[i] = new Option(items[i], values[i]);
	   }
	}
	srcList.focus();
}

function getSelectedOption( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i];
	} else {
		return null;
	}
}

function setSelectedValue( frmName, srcListName, value ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=0; i < srcLen; i++) {
		srcList.options[i].selected = false;
		if (srcList.options[i].value == value) {
			srcList.options[i].selected = true;
		}
	}
}

function getSelectedRadio( frmName, srcGroupName ) {
	var form = eval( 'document.' + frmName );
	var srcGroup = eval( 'form.' + srcGroupName );

	if (srcGroup[0]) {
		for (var i=0, n=srcGroup.length; i < n; i++) {
			if (srcGroup[i].checked) {
				return srcGroup[i].value;
			}
		}
	} else {
		if (srcGroup.checked) {
			return srcGroup.value;
		} // if the one button is checked, return zero
	}
   // if we get to this point, no radio button is selected
   return null;
}

function getSelectedValue( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i].value;
	} else {
		return null;
	}
}

function getSelectedText( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i].text;
	} else {
		return null;
	}
}

function chgSelectedValue( frmName, srcListName, value ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		srcList.options[i].value = value;
		return true;
	} else {
		return false;
	}
}

// Form specific functions for editting content images

function showImageProps(base_path) {
	form = document.adminForm;
	value = getSelectedValue( 'adminForm', 'imagelist' );
	parts = value.split( '|' );
	form._source.value = parts[0];
	setSelectedValue( 'adminForm', '_align', parts[1] || '' );
	form._alt.value = parts[2] || '';
	form._border.value = parts[3] || '0';
	form._caption.value = parts[4] || '';
	setSelectedValue( 'adminForm', '_caption_position', parts[5] || '' );
	setSelectedValue( 'adminForm', '_caption_align', parts[6] || '' );
	form._width.value = parts[7] || '';

	//previewImage( 'imagelist', 'view_imagelist', base_path );
	srcImage = eval( "document." + 'view_imagelist' );
	srcImage.src = base_path + parts[0];
}

function applyImageProps() {
	form = document.adminForm;
	if (!getSelectedValue( 'adminForm', 'imagelist' )) {
		alert( "Select and image from the list" );
		return;
	}
	value = form._source.value + '|'
	+ getSelectedValue( 'adminForm', '_align' ) + '|'
	+ form._alt.value + '|'
	+ parseInt( form._border.value ) + '|'
	+ form._caption.value + '|'
	+ getSelectedValue( 'adminForm', '_caption_position' ) + '|'
	+ getSelectedValue( 'adminForm', '_caption_align' ) + '|'
	+ form._width.value;
	chgSelectedValue( 'adminForm', 'imagelist', value );
}

function previewImage( list, image, base_path ) {
	form = document.adminForm;
	srcList = eval( "form." + list );
	srcImage = eval( "document." + image );
	var fileName = srcList.options[srcList.selectedIndex].text;
	var fileName2 = srcList.options[srcList.selectedIndex].value;
	if (fileName.length == 0 || fileName2.length == 0) {
		srcImage.src = 'images/blank.gif';
	} else {
		srcImage.src = base_path + fileName2;
	}
}

/**
* Toggles the check state of a group of boxes
*
* Checkboxes must have an id attribute in the form cb0, cb1...
* @param The number of box to 'check'
* @param An alternative field name
*/
function checkAll( n, fldName ) {
  if (!fldName) {
     fldName = 'cb';
  }
	var f = document.adminForm;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	if (c) {
		document.adminForm.boxchecked.value = n2;
	} else {
		document.adminForm.boxchecked.value = 0;
	}
}

function listItemTask( id, task ) {
    var f = document.adminForm;
    cb = eval( 'f.' + id );
    if (cb) {
        for (i = 0; true; i++) {
            cbx = eval('f.cb'+i);
            if (!cbx) break;
            cbx.checked = false;
        } // for
        cb.checked = true;
        f.boxchecked.value = 1;
        submitbutton(task);
    }
    return false;
}

function hideMainMenu()
{
	document.adminForm.hidemainmenu.value=1;
}

function isChecked(isitchecked){
	if (isitchecked == true){
		document.adminForm.boxchecked.value++;
	}
	else {
		document.adminForm.boxchecked.value--;
	}
}

/**
* Default function.  Usually would be overriden by the component
*/
function submitbutton(pressbutton) {
	submitform(pressbutton);
}

/**
* Submit the admin form
*/
function submitform(pressbutton){
	document.adminForm.task.value=pressbutton;
	try {
		document.adminForm.onsubmit();
		}
	catch(e){}
	document.adminForm.submit();
}

/**
* Submit the control panel admin form
*/
function submitcpform(sectionid, id){
	document.adminForm.sectionid.value=sectionid;
	document.adminForm.id.value=id;
	submitbutton("edit");
}

/**
* Getting radio button that is selected.
*/
function getSelected(allbuttons){
	for (i=0;i<allbuttons.length;i++) {
		if (allbuttons[i].checked) {
			return allbuttons[i].value
		}
	}
}

/**
* Pops up a new window in the middle of the screen
*/
function popupWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// LTrim(string) : Returns a copy of a string without leading spaces.
function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces
function trim(str) {
   return rtrim(ltrim(str));
}

function mosDHTML(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")<-1
	this.ie5=(this.ver.indexOf("MSIE 5")<-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")<-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")<-1
	this.ns6=(this.dom && parseInt(this.ver) <= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);

	this.activeTab = '';
	this.onTabStyle = 'ontab';
	this.offTabStyle = 'offtab';

	this.setElemStyle = function(elem,style) {
		document.getElementById(elem).className = style;
	}
	this.showElem = function(id) {
		if (elem = document.getElementById(id)) {
			elem.style.visibility = 'visible';
			elem.style.display = 'block';
		}
	}
	this.hideElem = function(id) {
		if (elem = document.getElementById(id)) {
			elem.style.visibility = 'hidden';
			elem.style.display = 'none';
		}
	}
	this.cycleTab = function(name) {
		if (this.activeTab) {
			this.setElemStyle( this.activeTab, this.offTabStyle );
			page = this.activeTab.replace( 'tab', 'page' );
			this.hideElem(page);
		}
		this.setElemStyle( name, this.onTabStyle );
		this.activeTab = name;
		page = this.activeTab.replace( 'tab', 'page' );
		this.showElem(page);
	}
	return this;
}
var dhtml = new mosDHTML();

function MM_findObj(n, d) { //v4.01
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;
	if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document;
	if(d.images){
	if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
	for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function saveorder( n ) {
	checkAll_button( n );
	submitform('saveorder');
}

//needed by saveorder function
function checkAll_button( n ) {
	for ( var j = 0; j <= n; j++ ) {
		box = eval( "document.adminForm.cb" + j );
		if ( box.checked == false ) {
			box.checked = true;
		}
	}
}
/**
* @param object A form element
* @param string The name of the element to find
*/
function getElementByName( f, name ) {
	if (f.elements) {
		for (i=0, n=f.elements.length; i < n; i++) {
			if (f.elements[i].name == name) {
				return f.elements[i];
			}
		}
	}
	return null;
}

/**
 * Given a form, this will set all the checkboxes on the form
 * to either on or off (based on bCheck)
 */
function checkAll(frmCheck, bCheck) {
	var mainform = document.forms[frmCheck];
	var elelen = mainform.elements.length;
	
	for(var i=0; i<elelen; i++){
		var currentItem = mainform.elements[i];
		if(currentItem.type == "checkbox"){
			currentItem.checked = bCheck;
		}
	}
}

/**
 * Takes a select box and returns all the selected values as a
 * list delimited by the passed delim
 * 
 * TODO: this funciton and the one below it should be combined into
 * a single function at some point
 */
function selectBoxToList(selBox, chrDelim) {
	
	return arrayToList(
		selBox.options, 
		chrDelim, 
		"var current_opt = arry[q]; if(current_opt.selected == true) list += current_opt.value + chrDelim;"
	);
}

function arrayToList(arry, chrDelim, fnExtractor) {
	var sellen = arry.length;
	var list = "";
	if(typeof fnExtractor == "undefined") 
		fnExtractor = "var current_opt = arry[q]; list += current_opt.toString() + chrDelim;";
	
	for(var q=0; q<sellen; q++) {
		/*var current_opt = arry[q];
		list += current_opt.name + chrDelim; */
		eval(fnExtractor);
	}
	
	if(list.toString().length > 1) {
		//take off the trailing delim
		list = list.toString().substring(0,list.length - chrDelim.toString().length);
	}
	
	return list;
}

/**
 * Function: limitSelection
 * limits a select box to a number of options. If they
 * go over the number all others will be deselected. Note
 * that this is serial over the list. In the future it might
 * be better to do the de-selection a bit more intuitively for
 * the client.
 * 
 * Parameters:
 * 	selBox - the select box to limit on
 *  intMax - the max number of items that can be selected
 */
function limitSelection(selBox, intMax) {
	var sellen = selBox.options.length;
	var current_count = 0;
	
	for(var q=0; q<sellen; q++) {
		var current_opt = selBox.options[q];
		
		if(current_opt.selected == true){
			current_count++;
		}
		
		if(current_count > intMax) {
			current_opt.selected = false;
		}
	}
}

/**
 * Function: showTab
 * What happens is when they click on an element that calls this function the DIV 
 * is loaded into the div with an ID of "displayTabArea". The other DIVs are appeneded to 
 * the end of the BODY tag (and hidden), thereby removing them as a child of the FORM tag. 
 * So when the client clicks on submit, only the form elements from the selected tab are 
 * sent back to the server.
 * 
 * Parameters:
 * 	tab - the tab to show
 */
function showTab(tab) {
	var alldivs = document.getElementsByTagName("DIV");
	var divslen = alldivs.length;
	var tabarea = document.getElementById("displayTabArea");
	var offscreen = document.getElementById("offscreen");
	
	if(!tabarea) alert("showTab called but no div called displayTabArea can be found");
	
	//going backwards creates less artifact
	for(var q=divslen-1; q >=0; q--) {
		var div = alldivs.item(q);
		var divid = div.id.toString();
		
		//if this looks like a tab type div ...
		if(divid.indexOf("tab") == 0) {
			//is this us?
			if(divid == tab) {
				//....
			} else {
				div.style.visibility = "hidden";
				offscreen.appendChild(div);
			}
		}
	}
	
	var activetab = document.getElementById(tab);
	activetab.style.visibility = "visible";
	tabarea.appendChild(activetab);
}

/**
 * Function: displayLabel
 * Sets the text in a label (a div with an id). Basically just does
 * an innerHTML =
 * 
 * Parameters:
 * 	label - the ID of the item to change
 *	text - the text to set the label to
 */
function displayLabel(label, text) {
	var lbl = document.getElementById(label);

	if(lbl) {
		lbl.innerHTML = text;
	}
}

/**
 * Function: toggleView
 * Opens or closes a div based on the id. Used in 
 * very basic accordion type UI elements. Note there is
 * no animation here so the YUI has a better wow factor.
 * (useful for quickly needed items)
 * 
 * Parameters:
 * 	id - the id of the div
 */
function toggleView(id) {
	try {
		var recview = document.getElementById(id);
		
		if(recview.style.display == "block") {
			recview.style.visibility = "hidden";
			recview.style.display = "none";
		} else {
			recview.style.visibility = "visible";
			recview.style.display = "block";
		}
	} catch (e) {
		//
	}
}

/**
 * Function: toggleViewArrow
 * toggles a view open and closed and adjusts some arrow to
 * indicate the action. This is used on the short cut upload image
 * as well as on the hug book show form.
 * 
 * This requires you have two specific element IDs. One that begins with 
 * img_ (the image element to toggle), and frm_ the div item to show and hide.
 *
 * TODO: use yui and animate this?
*/
function toggleViewArrow(idTag) {
	var image_div = document.getElementById('img_' + idTag);
	var popin_div = document.getElementById('frm_' + idTag);
	var down_arrow = '/images/arrow-down.gif';
	var up_arrow = '/images/arrow-up.gif';
	
	if ( image_div && popin_div ) {
		if ( popin_div.style.display == "none" ) {
			popin_div.style.display = "block";
			popin_div.style.visibility = "visible";
			image_div.src = up_arrow;
		} else {
			popin_div.style.display = "none";
			popin_div.style.visibility = "hidden";
			image_div.src = down_arrow;
		}
	}
}

/**
 * Function: updateStarRating
 * updates the display and hidden element to the selected
 * star level
 * 
 * Parameters:
 * 	ctrl - the name of the star control
 *	value - the value to set the control to
 */
function updateStarRating(ctrl, value, starsize) {
	try {
		var input = document.getElementById(ctrl);
		var display = document.getElementById(ctrl+"_current");
		input.value = value;
		display.style.width = (parseInt(value) * starsize) + "px";
	} catch(e) {
		//
	}
}

/**
 * Function: highlightItem
 * Just toggles the background color of an item
 * between the highlight blue and white. This is
 * often used with onmouseover and onmouseout and
 * often with images
 * 
 * Parameters:
 * 	id - the it of the item to highlight
 * 	on - if the highlight should be on or off
 */
function highlightItem(id, on) {
	var item = document.getElementById(id);
	if(on) {
		item.style.backgroundColor = "rgb(219,237,246)";
	} else {
		item.style.backgroundColor = "white";
	}
}

/**
 * Function: isEmail
 * Does a quick regular expression on the passed string and returns
 * true if the string is probably a valid email address
 * 
 * Parameters:
 * 	addr - the string to check to see if it's a email address
 *
 * Returns:
 * 	true if it looks like an email address
 */
var email_regex_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
function isEmail(addr){
	if (email_regex_filter.test(addr)) 
		return true;
	
	return false;
}

/**
 * Function: ds_remote_api
 * Do a remote API call. See the com_remote component for the APIs and
 * parameters. The callback parameter should look like this
 * (code)
 * var callback = { 
 *		success: function(o) { 
 *			//do something o.responseText
 *		}, 
 *		failure: function(o) {
 *			//do something
 *		}
 *	};
 * (end code)
 * 
 * Parameters:
 *  rmethod - the remote method to call
 *  body_object - the object to send in the body (the remote method parameters)	
 *  callback - the callback functions to handle the response
 */
function ds_remote_api(rmethod, body_object, callback) {
	var methodurl = "/component/option,com_remote/dummy.php";
	var parameters = "method="+rmethod+"&params="+encodeURIComponent((JSON.stringify(body_object)));
	var cObj = YAHOO.util.Connect.asyncRequest("POST", methodurl, callback, parameters);

}

function ds_remote_api_jq(rmethod, body_object, callback) {
	var methodurl = "/component/option,com_remote/dummy.php";
	var parameters = "method="+rmethod+"&params="+encodeURIComponent((JSON.stringify(body_object)));

	if (callback==null || !callback) { var callback = new Object(); callback.success = function() {}; callback.failure = function() {}; }

	$.ajax({
		type: "POST",
		url: methodurl,
		data: parameters,
		success: callback.success,
		failure: callback.failure
	});
}

/////////////////////////////////////////////////////////

/**
 * Function: ds_dialog
 * 
 * Parameters:
 * 	 title (required)- the title of the alert box
 * 	 message_text (required) - the text to show in the alert box
 * 	 buttons (required) - an array of button objects for the dialog
 * 	 icon (optional) - one of the following:
 * 		YAHOO.widget.SimpleDialog.ICON_ALARM (standard network icon for alarm)
 * 		YAHOO.widget.SimpleDialog.ICON_BLOCK (standard network icon for a blocking action)
 * 		YAHOO.widget.SimpleDialog.ICON_HELP - (standard network icon for help)
 * 		YAHOO.widget.SimpleDialog.ICON_INFO - (standard network icon for info)
 * 		YAHOO.widget.SimpleDialog.ICON_TIP - (standard network icon for a tip)
 * 		YAHOO.widget.SimpleDialog.ICON_WARN - (standard network icon for warn)
 */
function ds_dialog(title, message_text, buttons, icon) {
	var alert_dialog = new YAHOO.widget.SimpleDialog(
		"modaldialog", 
		{
			width: "350px",
			effect: {
				effect: YAHOO.widget.ContainerEffect.FADE, 
				duration: 0.15
			},
			fixedcenter: true,
			modal: true, 
			draggable: true,
			constraintoviewport: true,
			close: false
		}
	);
	alert_dialog.setHeader(title);
	alert_dialog.setBody(message_text);
	if ( icon != null) {
		alert_dialog.cfg.setProperty("icon", icon);
	}
	
	alert_dialog.cfg.queueProperty("buttons", buttons);
	
	alert_dialog.render(document.body);
	alert_dialog.show(); 
}

/////////////////////////////////////////////////////////
/* function alert(strtext) {
	var buttons = [
		{
			text:" OK ", 
			handler: function() {
				 this.hide();
			},
			isDefault:true 
		}
	];
	
	ds_dialog("Warning", strtext, buttons, YAHOO.widget.SimpleDialog.ICON_WARN);
} */
var email_intervals = [];
var email_window = null;
function setup_email_page(to, message){
	var dto = email_window.document.getElementById('d_mail_to');
	var dmess = email_window.document.getElementById('d_mail_message');

	dto.value = to;
	dmess.value = message;
	dto.focus();
}
function check_page_loaded(intIndex, to, message)
{
	if (!(email_window.document.getElementById('d_mail_to') === null))
	{
		clearTimeout(email_intervals[intIndex]);
		setup_email_page(to, message);
	}
}
function email_form(to, message) {
	
	email_window = window.open(
		"/index.php?option=com_popup&task=email_friend",
		"email_window",
		"status=0,toolbar=0,location=0,menubar=0,scrollbars=0,resizable=0,height=400,width=440"
	);

	intervalIndex = email_intervals.length;
	email_intervals[intervalIndex] = setInterval(
		function() { check_page_loaded(intervalIndex, to, message ); },
		600
	);
	
	/* once we get the YUI z-index fixed, we should go back to the 
	pop in model
	html_text = "<div class='graytext dialog_label'>Email To:</div><div><input type='text' size='35' value='"+to+"' id='d_mail_to'></div>";
	html_text += "<div class='graytext dialog_label'>Message:</div><div><textarea cols='35' rows='5' id='d_mail_message'>"+message+"</textarea></div>";
	
	var buttons = [
		{
			text:" Cancel ",
			handler: function() {
				this.hide();
			}
		},
		{
			text:"  Send  ", 
			handler: function() {
				var m_to = document.getElementById('d_mail_to');
				var m_mess = document.getElementById('d_mail_message');
				
				var message = new Object();
				message.to = m_to.value;
				message.mess = m_mess.value;
				
				var callback = { 
					success: function(o) {
						var result = JSON.parse(o.responseText);
						if(!result) {
							alert('There was a problem sending your email.');
						}
					}, 
					failure: function(o) { 
						alert(o.responseText); 
					}
				};
				
				ds_remote_api('send_email', message, callback);
				this.hide();
			}
		}
	];
	ds_dialog("Email to a Friend", html_text, buttons);
	document.getElementById('d_mail_to').focus();
	*/
}

/**
 * This is fired when the client clicks on a treatment link
 */
function treatmentHotLink(url) {
	var message = new Object();
	message.log = 'treatment_click_log';
	message.url = url;
	
	var callback = { 
		success: function(o) {
			// window.location = url;
			return true;
		}, 
		failure: function(o) { 
			// window.location = url;
			return true;
		}
	};
	
	ds_remote_api('log_click', message, callback);
}

/**
 * Used on the new_homepage, and profile page to show
 * and other "page" of data. (preloaded information)
 */
function showMoreActivity(button_id, content_id) {
	button_id = (!button_id) ? 'more_content_button' : button_id;
	content_id = (!content_id) ? 'more_content_content' : content_id;
	
	$('#'+content_id).toggle();
	$('#'+button_id).toggle();
}

