/**
 * Message Board Class.
 * 
 * CHANGELOG:
 * 
 * 		2009-01-10: Modified ShowConfirmation();
 * 		-- Added third parameter (xAnchor) to define whether the interface
 * 		   calls the anchor based on true/false values.  If true, then the
 *  	   	   online visitor will be taken to the message. If false, then the
 *	  	   page either loads or functionality continues. Either way, the
 *  		   message board displays it's given confirmation string.
 *
 *  		2009-01-29 :: Added @param messageBoardId
 *  		-- Allows the use of multiple MessageBoards on one page. By default,
 *  		   and to support all other users, the param will assign itself as 
 *  		   'MessageBoard'.
 *
 *  		   USAGE:
 *
 *  		   	MessageBoard1 = new MessageBoard('leftdiv');
 *  		   	MessageBoard2 = new MessageBoard('rightdiv');
 *  		
 *  		2009-02-20 :: Added DisplayIn(element_id) function.
 *  		-- Allows the MessageBoard to be moved around elements. NOTE: Whether you're using
 *  		   a div, span, or container type element, the ID must be passed as the parameter.
 *
 *  		   USAGE:
 *
 *  		   	MessageBoard.DisplayIn('Different_Div_Id');
 *
 *  		2009-03-04 :: Added try { } catch(err) {} statements for setting attributes that might not be supported
 *  			      by some browsers (e.g. IE.)
 *
 *  		2009-05-04 :: Added support for custom loading images.
 *			      USAGE: 
 *  			      		var MsgBoard = new MessageBoard();
 *  			      		MsgBoard.SetLoadBarImage('/images/custom-image.gif');
 *  			      		MsgBoard.ShowLoadBar();
 *
 *  		2009-05-04 :: Added Setter & Getter Methods for specifying custom loading images.
 *
 *  		2009-05-04 :: Changed how LoadBar.innerHTML is set.  Because we now allow custom loading images - we can continue to set a default of
 *  			      "/images/loading.gif", but LoadBar.innerHTML can no longer be static.  We must continuously set it when showing the 
 *  			      LoadBar (e.g. MessageBoard.ShowLoadBar(); ).
 * 
 * @version 1.3.1
 * @author Josue Orozco
 * @license http://www.orozcovision.com/legal/ipr.php
 * @copyright (c) 2009 OrozcoVision Technologies. All rights reserved.
 */

var MessageBoard = function(messageBoardId){
	
	//----------------------------------
	// Create MessageBoard Container Div
	if(messageBoardId == '' || messageBoardId == undefined){
		
		//------------------------------------------------------
		// Manually set ID
		this.MessageBoardId = 'MessageBoard';
		
		XBrowser.Log('MessageBoardID = ' + messageBoardId + ' | Manually setting it to "MessageBoard"');
	} else {

		this.MessageBoardId = messageBoardId;

		XBrowser.Log('MessageBoardID = ' + messageBoardId);
	}

	this.MessageBoardContainer = document.getElementById(this.MessageBoardId);
	
	//----------------------------------
	// Configure ID Attribute
	try {

		this.MessageBoardContainer.setAttribute('id', this.MessageBoardId);

		XBrowser.Log('Setting MessageBoardContainer.id via "setAttribute()"');
	} catch(err) {

		this.MessageBoardContainer.id = this.MessageBoardId;
	}
		
	//----------------------------------
	// Create LoadBar Container
	this.LoadBar = document.createElement('div');
	
	//----------------------------------
	// Set ID Attribute
	try {

		this.LoadBar.setAttribute('id', 'loadBar');
	} catch (err) {

		this.LoadBar.id = 'loadBar';
	}
	
	//----------------------------------
	// Set Style
	try {

		this.LoadBar.setAttribute('style', 'display:none;');
	} catch (err) {
		
		this.LoadBar.style.display = 'none';
	}

	//------------------------------------------------------
	// Set Default Loading Image
	this.LoadBarImage = '/images/loading.gif';

	//----------------------------------
	// Set HTML
	// See ChangeLog - 2009-05-04 :: LoadBar.innerHTML
	this.LoadBar.innerHTML = '';	//'<strong>Processing&#8230;</strong><br /><img src="' + this.GetLoadBarImage() + '" alt="Processing request..." title="Processing request" />';
	
	//----------------------------------
	// Create Confirmation Container
	this.Confirmation = document.createElement('div');
	
		//----------------------------------
		// Set ID Attribute
		try {
			this.Confirmation.setAttribute('id', 'displayConfirmation');
		} catch (err) {

			this.Confirmation.id = 'displayConfirmation';
		}

		
		//----------------------------------
		// Set Style
		try {
			
			this.Confirmation.setAttribute('style', 'display:none;');
		} catch (err) {

			this.Confirmation.style.display = 'none';
		}
		
	//----------------------------------
	// Build Containers
	this.MessageBoardContainer.appendChild(this.LoadBar);
	this.MessageBoardContainer.appendChild(this.Confirmation);
}

MessageBoard.prototype = {
	
	ShowLoadBar: function(){
		
		//----------------------------------
		// Hide Confirmation
		this.HideConfirmation();
		
		//----------------------------------
		// Show the LoadBar
		this.SetLoadBarInnerHtml();
		this.MessageBoardContainer.style.display = 'block';
		this.LoadBar.style.display = 'block';
	},
	
	HideLoadBar: function(){
		
		this.LoadBar.style.display = 'none';
	},
	
	ShowConfirmation: function(xColor, xConfirmation, xAnchor){
		
		if(xAnchor !== undefined){
			this.mAnchor = xAnchor;
		} else {
			this.mAnchor = true;
		}
		
		this.HideLoadBar();
		
		var msg = '<a name="' + this.MessageBoardId + '" href="javascript:void(0);"></a>';
		msg += '<div style="padding:12px; background-color:#f5f3d6; border:#ffc78f 1px solid;">';
		
		if(xColor == 'red'){

			msg += '<table class="tblMessageBoard">';
				msg += '<tr>';
					msg += '<td>';

						msg += '<img alt="Error: " src="http://www.ovwebsolutions.com/images/icons/error_msg_icon.gif" border="0" align="absmiddle" />';
					msg += '</td>';
					msg += '<td style="padding-left:10px;">';
		}
		
		msg += '<strong style="color:'+xColor+';">';
			msg += xConfirmation;
		msg += '</strong>';

		if(xColor == 'red'){
					msg += '</td>';
				msg += '</tr>';
			msg += '</table>';
		}

		msg += '</div><br />';
		
		this.MessageBoardContainer.style.display = 'block';
		this.Confirmation.style.display = 'block';
		this.Confirmation.innerHTML = msg;
		
		// Take online visitor to the top of the
		// message board so they can see the message.
		//if(xAnchor !== undefined && xAnchor == true){
		//	window.location = '#MessageBoard';
		//}
		if(this.mAnchor){
			window.location = '#' + this.MessageBoardId;
		}
	},
	
	HideConfirmation: function(){
		this.Confirmation.style.display = 'none';
	},

	DisplayIn: function(element_id){
		
		document.getElementById(element_id).appendChild(this.MessageBoardContainer);
	},

	SetLoadBarImage: function(img){
		this.LoadBarImage = img;
	},

	GetLoadBarImage: function(img){
		return this.LoadBarImage;
	},
	
	SetLoadBarInnerHtml:function(){

		this.LoadBar.innerHTML = '<strong>Processing&#8230;</strong><br /><img src="' + this.GetLoadBarImage() + '" alt="Processing request..." title="Processing request" />';
	}
};
