/***************************************************************************
    MODULE:   /js/rhwForm.js
    PURPOSE:  js lib to MANAGE form management.
	CREATED:	08-7-09
	AUTHOR:		Mike Hutchins
	COPYRIGHT:	(c) 2001 Fred Flintstone for slateconsulting.com, Inc.
	CHANGE HISTORY: 
	
	Notes:
	
	This lib uses jquery and is included as a part of the file.
***************************************************************************/
var __rhwIndex = 0;
// *** ******************************************************************
// ***	Object Init
// *** ******************************************************************
function __rhwForm()
{
	
}
var __titles = new Array();
__titles["default"] = "click to expand";
var __defaultStates = new Array();
__titles["default"] = "open";

// *** ******************************************************************
// ***	setTitle - sets the title of a message
// *** ******************************************************************
__rhwForm.prototype.setTitle = function(key, title)
{
	__titles[key] = title;
}

// *** ******************************************************************
// ***	setDefaultState - sets the title of a message
// *** ******************************************************************
__rhwForm.prototype.setDefaultState = function(key, state)
{
	__defaultStates[key] = state;
}

// *** ******************************************************************
// ***	getDefaultState - 
// *** ******************************************************************
__rhwForm.prototype.getDefaultState = function(key)
{
	var val = "";
	try
	{
		val = __defaultStates[key];
	}
	catch(ex)
	{
		val = __defaultStates["default"];
	}
	return val;
}

// *** ******************************************************************
// ***	getTitle - gets the saved title
// *** ******************************************************************
__rhwForm.prototype.getTitle = function(key)
{
	var val = "";
	try
	{
		val = __titles[key];
	}
	catch(ex)
	{
		val = __titles["default"];
	}
	return val;
}

// *** ******************************************************************
// ***	attach - attaches to a message box
// *** ******************************************************************
__rhwForm.prototype.attach = function(obj)
{

	var id = "#"+obj.id;
	var idx = __rhwIndex++;
	var h = $(id).html();
	var header = 
		"<div class='messageheader'><div id='" + obj.id + "_title' class='messagetitle'></div>" + 
			"<div class='messageopen' id='" + obj.id + "_close'><img src=\"/images/rhwmin.jpg\"></img></div>" + 
			"<div class='messageclose' id='" + obj.id + "_open'><img src=\"/images/rhwmax.jpg\"></img></div>";
	var clear = "<div id='" + obj.id + "_clear' style='display:none;clear:both;'></div>";
	
	$(id).html(header + clear + "</div><div id=\"" + obj.id + "_body\" style='background: none;'>" + h + "</div>");
	
	$(id + "_close").bind("click", 
		function(e)
		{
			obj.className = "messagestandoutdiscreet";
			$(this).toggle();
			$("#" + this.id.replace("_close", "_open")).toggle();
			$("#" + this.id.replace("_close", "_title")).text(RhwForm.getTitle(obj.id));
			$("#" + this.id.replace("_close", "_title")).show();
			$("#" + this.id.replace("_close", "_body")).slideUp("fast");
			$("#" + this.id.replace("_close", "_clear")).slideDown("fast");
			
			
		});
	
	$(id + "_open").bind("click", 
		function(e)
		{
			obj.className = "messagestandout";
			$(this).toggle();
			$("#" + this.id.replace("_open","_close")).toggle();
			$("#" + this.id.replace("_open", "_title")).hide();
			$("#" + this.id.replace("_open", "_title")).text("");
			$("#" + this.id.replace("_open", "_body")).slideDown("fast");
			$("#" + this.id.replace("_open", "_clear")).toggle();
			
		});
		
	if (this.getDefaultState(obj.id)=="closed")
	{
		obj.className = "messagestandoutdiscreet";
		$("#" + obj.id + "_close").toggle();
		$("#" + obj.id + "_open").toggle();
		$("#" + obj.id + "_title").text(this.getTitle(obj.id));
		$("#" + obj.id + "_title").show();
		$("#" + obj.id + "_body").slideUp("fast");
		$("#" + obj.id + "_clear").slideDown("fast");
	}
}


// create instance if one doesn't
if (RhwForm==null)
{
	var RhwForm = new __rhwForm();
}

// setup the attach to the message 
$(document).ready(
	function (obj)
	{

		$(".messagestandout").each(function(i){RhwForm.attach(this);});

	});

 