﻿/**
*  SimpleContent Hide/Show Class
*  Reveals content when header is clicked
*  Simplified version of Content class => no deep linking
*  Usually used as a secondary content area 
*
*  @param  blockId         content blocks container ID
*  @param  blockClass      content block Classname
*  @param  heardersId      headers container ID
*/

var SimpleContent = {

	blockId: '',
	blockClass: '',
	headersId: '',
	controlId: '',
	tabId: 0,
	lmode: null,

	blocks: new Array(),
	headers: new Array(),

	initialize: function(args) {

		var caller = this;

		this.blockId = args[0];
		this.blockClass = args[1];
		this.headersId = args[2];
		this.controlId = args[3];
		this.tabId = args[4];
		this.lmode = args[5];

		/** Build info blocks objects **/
		//var block = $(this.blockId);
		//var el = block.getElementsByTagName('div');
		var el = $("#" + this.blockId + " div");
		var el_length = el.length;
		for (i = 0; i < el_length; i++) {
			if (el[i].className == this.blockClass) {
				this.blocks.push(el[i]);
			}
		};

		/** Disable headers links & add click events **/
		//var block = $(this.headersId);
		//var aTags = block.getElementsByTagName('a');
		var aTags = $("." + this.headersId + " a");
		var aL = aTags.length;
		for (i = 0; i < aL; i++) {
			aTags[i].onclick = function() {
				caller.showBlock(this);
				return false;
			}
			this.headers.push(aTags[i]);
		};

		/** Show correct block **/
		// check tabId isNumeric
		if (!isNumeric(this.tabId)) {
			this.tabId = 0;
		} else if (this.tabId >= el_length) {
			this.tabId = 0;
		};

		this.showBlock(this.headers[this.tabId]);

		// Hack to display hidden page numbers
		//$('.pG1').css('display', 'block');
		if (aL > 1) {
			$('.pG2').css('display', 'block');
		};
		

	},

	showBlock: function(el) {
		var l = this.blocks.length;
		var activeEl = null;
		if (typeof (el) == 'object') { // Action triggered by a click event
			var obj = el.id;
			obj = obj.substring(2);
		} else {
			var obj = el;
		}
		for (i = 0; i < l; i++) {
			if (this.blocks[i].id.substring(1) == obj) {
				this.display(this.blocks[i]);
				activeEl = obj;
			} else {
				this.hide(this.blocks[i]);
			}
		}

		// Set Previous and Next Controls
		this.setControls(el);

		// Activate active header
		if (activeEl != null) this.activate(activeEl);
	},

	display: function(el) {
		el.style.display = 'block';
	},

	hide: function(el) {
		el.style.display = 'none';
	},

	activate: function(el) {
		var l = this.headers.length;
		if (typeof (el) == 'object') { // Action triggered by a click event
			var obj = el.id;
		} else {
			var obj = el;
		}
	},

	setParam: function(e, param, value) {
		e[param] = value;
	},

	setControls: function(el) {

		var l = this.headers.length;
		if (typeof (el) == 'object') { // Action triggered by a click event
			var obj = el.id;
			obj = obj.substring(2);
		} else {
			var obj = el;
		}

		var c = obj * 1;
		var aPrevious = $("." + this.controlId + " a:first");
		var aNext = $("." + this.controlId + " a:last");


		/* SET NEXT ID */
		var n;
		if (l > c) {
			n = c + 1;
			$(aNext).css('display', 'block');
		} else {
			n = c;
			$(aNext).css('display', 'none');
		};

		/* SET PREVIOUS ID */
		var p;
		if (c > 1) {
			p = c - 1;
			$(aPrevious).css('display', 'block');
		} else {
			p = c;
			$(aPrevious).css('display', 'none');
		};



		$(aPrevious).attr('id', 'pl' + p).unbind('click').click(function() {
			SimpleContent.showBlock(p);
			return false;
		});
		$(aNext).attr('id', 'pl' + n).unbind('click').click(function() {
			SimpleContent.showBlock(n);
			return false;
		});
	}

};

function isNumeric(form_value) 
{ 
    if (form_value.match(/^\d+$/) == null) 
        return false; 
    else 
        return true; 
}