<!--
//<![CDATA[
//Class Functions   
function Functions()
{
	//properties
	
	//private methods
	
	//public methods
	this.init = Functions_init;
	this.ltrim = Functions_ltrim;
	this.rtrim = Functions_rtrim;
	this.trim = Functions_trim;
	this.isEmpty = Functions_isEmpty;
	this.whatAmI = Functions_whatAmI;
	this.init();
}

function Functions_init()
{

};	

function Functions_trim(s) {
	s = this.ltrim(s);
	s = this.rtrim(s);
	return s;
}

function Functions_isEmpty(s) {
	var test = s;
	test = this.trim(test);
	if(test.length==0)
		return true;
	else
		return false;
}

function Functions_ltrim(s)
{
	while (s.substring(0,1) == ' ')
	{
		s = s.substring(1,s.length);
	}
	return s
}

function Functions_rtrim(s)
{
	while (s.substring(s.length-1,s.length) == ' ')
	{
		s = s.substring(0,s.length-1);
	}
	return s
}

function Functions_whatAmI(o)
{
	alert('I am a: '+o);
};
//]]>
//--><!--
//<![CDATA[
// Class DateFunctions
function DateFunctions(_sDate, _pattern)
{
	//properties
	this._functions = new Functions();
	this._sDate = this._functions.trim(_sDate);
	this._pattern = this._functions.trim(_pattern.toUpperCase());
	this._isDate = true;
	this._date = "";
	this._unixDate = 0;
	this._year = "";
	this._month = "";
	this._day = "";
	
	//private methods
	
	//public methods
	this.init = DateFunctions_init;
	this.getYear = DateFunctions_getYear;
	this.getMonth= DateFunctions_getMonth;
	this.getDay = DateFunctions_getDay;
	this.getDate = DateFunctions_getDate;
	this.getUnixDate = DateFunctions_getUnixDate;
	this.isDate = DateFunctions_isDate;
	
	this.init();
}

function DateFunctions_init()
{
	var strArray = new Array();
	this._isDate = true;
	if(this._pattern == "YYYY-MM-DD")
	{
		strArray = this._sDate.split("-");
		this._year = strArray[0];
		this._month = strArray[1];
		this._day = strArray[2];
	}
	else if(this._pattern == "YYYY/MM/DD")
	{
		strArray = this._sDate.split("/");
		this._year = strArray[0];
		this._month = strArray[1];
		this._day = strArray[2];
	}
	else if(this._pattern == "MM-DD-YYYY")
	{
		strArray = this._sDate.split("-");
		this._year = strArray[2];
		this._month = strArray[0];
		this._day = strArray[1];
	}
	else if(this._pattern == "MM/DD/YYYY")
	{
		strArray = this._sDate.split("/");
		this._year = strArray[2];
		this._month = strArray[0];
		this._day = strArray[1];
	}
	else if(this._pattern == "DD-MM-YYYY")
	{
		strArray = this._sDate.split("-");
		this._year = strArray[2];
		this._month = strArray[1];
		this._day = strArray[0];
	}
	else if(this._pattern == "DD/MM/YYYY")
	{
		strArray = this._sDate.split("/");
		this._year = strArray[2];
		this._month = strArray[1];
		this._day = strArray[0];
	};
	this._date = new Date(this._year, this._month, this._day);
	this._unixDate = Date.parse(this._date.toString());
	if((this._date.toString()=="Invalid Date")||(this._date.toString()=="NaN"))
		this._isDate = false;
}

function DateFunctions_getYear()
{
	return this._year;
}
function DateFunctions_getMonth()
{
	return this._month;
}
function DateFunctions_getDay()
{
	return this._day;
}
function DateFunctions_getDate()
{
	return this._date;
}
function DateFunctions_getUnixDate()
{
	return this._unixDate;
}
function DateFunctions_isDate()
{
	return this._isDate;
}
//]]>
//--><!--
//<![CDATA[
//Class CharCount   
function CharCount(_count, _textAreaId, _charCountId)
{
	//properties
	this._functions = new Functions();
	this._count = _count;
	this._textArea = document.getElementById( _textAreaId );
	this._charCount = document.getElementById( _charCountId );
	
	//private methods
	
	//public methods
	this.init = CharCount_init;
	this.doCount = CharCount_doCount;
	
	this.init();
}

function CharCount_init()
{
	this._charCount.value = this._count;;
};	

function CharCount_doCount()
{
	var numChars = this._textArea.value.length - this._count;
	if(numChars > 0)
	{
		this._textArea.value = this._textArea.value.substring(0, this._count);
	}
	this._charCount.value = (this._count - this._textArea.value.length);
};
//]]>
//--><!--
//<![CDATA[
//Class Concertina   
function Concertina(folder_contentIn, folder_content_openIn, folder_newsIn, folder_news_openIn, table_nameIn, root_tableIdIn, root_table_typeIn)
{
	//properties
	this.folder_content = new Image();
	this.folder_content_open = new Image();
	this.folder_news = new Image();
	this.folder_news_open = new Image();
	this.folder_content.src = folder_contentIn;
	this.folder_content_open.src = folder_content_openIn;
	this.folder_news.src = folder_newsIn;
	this.folder_news_open.src = folder_news_openIn;
	this.table_name = table_nameIn;
	this.root_tableId = root_tableIdIn;
	this.root_table_type = root_table_typeIn;
	
	//private methods
	
	//public methods
	this.init = Concertina_init;
	this.doConcertina = Concertina_doConcertina;
	this.doHide = Concertina_doHide;
	this.doShow = Concertina_doShow;
	this.doClose = Concertina_doClose;
	this.doOpen = Concertina_doOpen;
	this.doCloseAll = Concertina_doCloseAll;
	this.getTypeFromId = Concertina_getTypeFromId;
	
	this.init();
}

function Concertina_init()
{
	
}

function Concertina_doConcertina(_tablelId, _imgId, _type)
{
	var _table = document.getElementById( _tablelId );
	var _img = document.getElementById( _imgId );
	if(_table.style.display=='none')
		this.doShow(_table,_img,_type);
	else
		this.doHide(_table,_img,_type);
}

function Concertina_doHide(_table, _img, _type) 
{
	var i = 0;
	var j = 0;
	_table.style.display = 'none';
	if(_type=='folder_content')
		_img.src = this.folder_content.src;
	else
		_img.src = this.folder_news.src;
}

function Concertina_doShow(_table, _img, _type) 
{
	_table.style.display = 'table';
	if(_type=='folder_content')
		_img.src = this.folder_content_open.src;
	else
		_img.src = this.folder_news_open.src;
}

function Concertina_doClose(_tablelId, _imgId, _type)
{
	var _table = document.getElementById( _tablelId );
	var _img = document.getElementById( _imgId );
	this.doHide(_table,_img,_type);
}

function Concertina_doOpen(_tablelId, _imgId, _type)
{
	var _table = document.getElementById( _tablelId );
	var _img = document.getElementById( _imgId );
	this.doShow(_table,_img,_type);
}

function Concertina_doCloseAll()
{
	var _tables = document.getElementsByName(this.table_name);
	var i=0;
	for(i=0;i<_tables.length;i++)
	{
		_type = this.getTypeFromId(_tables[i].id);
		this.doClose(_tables[i].id,'img_'+_tables[i].id,_type);
	}
	this.doOpen(this.root_tableId,'img_'+this.root_tableId,this.root_table_type);
}

function Concertina_getTypeFromId(_id)
{
	var _typeArray = _id.split('_');
	var _type = _typeArray[0] + '_' + _typeArray[1];
	return _type;
}
//]]>
//--><!--
//<![CDATA[
// Class Validate
function Validate(_formId)
{
	//properties
	this._functions = new Functions();
	this._returnValidOnValidate = false;
	this._form = document.getElementById(_formId);
	this._isNotEmptyElementArray = new Array();
	this._isNotDateElementArray = new Array();
	this._isDateAgtDateBElementArray = new Array();
	this._isValid = true;
	this._output = "";
	
	//private methods
	this._doSubmit = Validate_doSubmit;
	
	//public methods
	this.init = Validate_init;
	this.isValid = Validate_isValid;
	this.setValid = Validate_setValid;
	this.setReturnValidOnValidate = Validate_setReturnValidOnValidate;
	this.validate = Validate_validate;
	
	this.isNotEmpty = Validate_isNotEmpty;
	this.isNotDate = Validate_isNotDate;
	this.isDateAgtDateB = Validate_isDateAgtDateB;
	
	this.init();
}

function Validate_setReturnValidOnValidate(_returnValidOnValidateIn)
{
	this._returnValidOnValidate = _returnValidOnValidateIn;
};

function Validate_doSubmit()
{
	this._form.submit();
};	

function Validate_init()
{
	this._isValid = true;
	this._output = "";
};	

function Validate_isValid()
{
	return this._isValid;
}

function Validate_setValid(_valid)
{
	this._isValid = _valid;
}

function Validate_isNotEmpty(_label, _id)
{
	var isNotEmptyElement = new IsNotEmptyElement(_label, _id);
	var newLength = this._isNotEmptyElementArray.push(isNotEmptyElement);
}

function Validate_isNotDate(_label, _id)
{
	var isNotDateElement = new IsNotDateElement(_label, _id);
	var newLength = this._isNotDateElementArray.push(isNotDateElement);
}

function Validate_isDateAgtDateB(_labelA, _idA, _labelB, _idB )
{
	var isDateAgtDateBElement = new IsDateAgtDateBElement(_labelA, _idA, _labelB, _idB);
	var newLength = this._isDateAgtDateBElementArray.push(isDateAgtDateBElement);
}

function Validate_validate()
{
	var i = 0;
	var msg = "";
	var v = "";	
	this.init();
	
	for(i=0;i<this._isNotEmptyElementArray.length;i++)
	{
		v = this._isNotEmptyElementArray[i].validate();
		if(!v.isValid())
		{
			this._output += v.getMessage();
			this.setValid(false);
		}
	}
	
	for(i=0;i<this._isNotDateElementArray.length;i++)
	{
		v = this._isNotDateElementArray[i].validate();
		if(!v.isValid())
		{
			this._output += v.getMessage();
			this.setValid(false);
		}
	}
	
	for(i=0;i<this._isDateAgtDateBElementArray.length;i++)
	{
		v = this._isDateAgtDateBElementArray[i].validate();
		if(!v.isValid())
		{
			this._output += v.getMessage();
			this.setValid(false);
		}
	}
	
	if(!this.isValid())
	{
		msg = "";
		msg += "Please address the following errors:\n";
		msg += "____________________________________\n";
		msg += "\n";
		msg += this._output;
		alert(msg);
		return this.isValid();
	}
	else if((!this._returnValidOnValidate)&&(this.isValid()))
	{
		this._doSubmit();
	}
	else
		return this.isValid(); 
};
//]]>
//--><!--
//<![CDATA[
// Class Validation
function Validation()
{
	//properties
	this._functions = new Functions();
	this._isValid = true;
	this._message = "";
	
	//private methods
	
	//public methods
	this.init = Validation_init;
	this.isValid = Validation_isValid;
	this.getMessage = Validation_getMessage;
	this.setValid = Validation_setValid;
	this.setMessage = Validation_setMessage;
	
	this.init();
}

function Validation_init()
{
	this._isValid = true;
	this._message = "";
}

function Validation_isValid()
{
	return this._isValid;
}

function Validation_getMessage()
{
	return this._message;
}

function Validation_setValid(_valid)
{
	this._isValid = _valid;
}

function Validation_setMessage(_message)
{
	this._message = _message;
}
//]]>
//--><!--
//<![CDATA[
// Class IsDateAgtDateBElement
function IsDateAgtDateBElement(_labelA, _idA, _labelB, _idB)
{
	//properties
	this._functions = new Functions();
	this._selfA = document.getElementById(_idA);
	this._selfB = document.getElementById(_idB);
	this._labelA = _labelA;
	this._idA = _idA;
	this._labelB = _labelB;
	this._idB = _idB;
	this._validation = new Validation();
	
	//private methods
	
	//public methods
	this.init = IsDateAgtDateBElement_init;
	this.getValidation = IsDateAgtDateBElement_getValidation;
	this.validate = IsDateAgtDateBElement_validate;
	
	this.init();
}

function IsDateAgtDateBElement_init()
{
	this.getValidation().setValid(true);
	this.getValidation().setMessage("");
}

function IsDateAgtDateBElement_getValidation()
{
	return this._validation;
}

function IsDateAgtDateBElement_validate()
{
	var isValid = true;
	if((this._functions.isEmpty(this._selfA.value))&&(!this._functions.isEmpty(this._selfB.value)))
		isValid = true;
	else if((this._functions.isEmpty(this._selfA.value))&&(this._functions.isEmpty(this._selfB.value)))
		isValid = true;
	else if((!this._functions.isEmpty(this._selfA.value))&&(this._functions.isEmpty(this._selfB.value)))
		isValid = false;
	else
	{
		var dA = new DateFunctions(this._selfA.value, "YYYY-MM-DD");
		var dB = new DateFunctions(this._selfB.value, "YYYY-MM-DD");
		if(dA.getUnixDate() > dB.getUnixDate())
			isValid = false;
	}
	
	if(!isValid)
	{
		this.getValidation().setValid(false);
		this.getValidation().setMessage("'"+this._labelA+"' cannot be greater than '"+this._labelB+"'.\n");
	}
	else
	{
		this.getValidation().setValid(true);
		this.getValidation().setMessage("");
	}
	return this.getValidation();
}
//]]>
//--><!--
//<![CDATA[
// Class IsNotDateElement
function IsNotDateElement(_label, _id)
{
	//properties
	this._functions = new Functions();
	this._self = document.getElementById(_id);
	this._label = _label;
	this._id = _id;
	this._validation = new Validation();
	
	//private methods
	
	//public methods
	this.init = IsNotDateElement_init;
	this.getValidation = IsNotDateElement_getValidation;
	this.validate = IsNotDateElement_validate;
	
	this.init();
}

function IsNotDateElement_init()
{
	this.getValidation().setValid(true);
	this.getValidation().setMessage("");
}

function IsNotDateElement_getValidation()
{
	return this._validation;
}

function IsNotDateElement_validate()
{
	var isValid = true;
	if(!this._functions.isEmpty(this._self.value))
	{
		var d = new DateFunctions(this._self.value, "YYYY-MM-DD");
		if(!d.isDate())
			isValid = false;
	}
	if(!isValid)
	{
		this.getValidation().setValid(false);
		this.getValidation().setMessage("'"+this._label+"' is not a valid date.\n");
	}
	else
	{
		this.getValidation().setValid(true);
		this.getValidation().setMessage("");
	}
	return this.getValidation();
}
//]]>
//--><!--
//<![CDATA[
// Class IsNotEmptyElement
function IsNotEmptyElement(_label, _id)
{
	//properties
	this._functions = new Functions();
	this._self = document.getElementById(_id);
	this._label = _label;
	this._id = _id;
	this._validation = new Validation();
	
	//private methods
	
	//public methods
	this.init = IsNotEmptyElement_init;
	this.getValidation = IsNotEmptyElement_getValidation;
	this.validate = IsNotEmptyElement_validate;
	
	this.init();
}

function IsNotEmptyElement_init()
{
	this.getValidation().setValid(true);
	this.getValidation().setMessage("");
}

function IsNotEmptyElement_getValidation()
{
	return this._validation;
}

function IsNotEmptyElement_validate()
{
	var isValid = !this._functions.isEmpty(this._self.value);
	
	if(!isValid)
	{
		this.getValidation().setValid(false);
		this.getValidation().setMessage("'"+this._label+"' cannot be empty.\n");
	}
	else
	{
		this.getValidation().setValid(true);
		this.getValidation().setMessage("");
	}
	return this.getValidation();
}
//]]>
//--><!--
//<![CDATA[
//Class SwapTextAreaSelect  
function SwapTextAreaSelect(_formId, _textAreaId, _selectBoxId)
{
	// properties
	this._functions = new Functions();
	this._form = document.getElementById(_formId);
	this._textArea = document.getElementById(_textAreaId); 
	this._selectBox = document.getElementById(_selectBoxId);
	
	//private methods
	
	//public methods
	this.addRight = SwapTextAreaSelect_addRight;
	this.removeRight = SwapTextAreaSelect_removeRight;
	this.addOption = SwapTextAreaSelect_addOption;
	this.removeOption = SwapTextAreaSelect_removeOption;
	this.getUnSelectedItems = SwapTextAreaSelect_getUnSelectedItems;
	this.checkIfExists = SwapTextAreaSelect_checkIfExists;
	this.selectAllRightOptions = SwapTextAreaSelect_selectAllRightOptions;
}

function SwapTextAreaSelect_addRight()
{
	var strValue=this._textArea.value;
	var strArray=strValue.split('\n');
	var optArray=new Array();
	var i=0;
	var count=0;
	var str = "";
	for(i=0; i<strArray.length;i++)
	{
		str=this._functions.trim(strArray[i]);
		if(str!='')
		{
			optArray[count] = new Option(str, str, true);
			count++;
		}
	}
	if(optArray.length>0)
		this.addOption(optArray, this._selectBox);
}

function SwapTextAreaSelect_removeRight()
{
	this.removeOption(this._selectBox);
}

function SwapTextAreaSelect_addOption(a, sb)
{
	var i = 0;
	for(i=0;i<a.length;i++)
	{
		if(this.checkIfExists(a[i], sb.options)==false)
		{
			sb.options[sb.length] = new Option(a[i].text, a[i].value, true);
		}
	}
}

function SwapTextAreaSelect_removeOption(sb)
{
	var a = this.getUnSelectedItems(sb);
	sb.length = 0;
	this.addOption(a, sb);
}

function SwapTextAreaSelect_getUnSelectedItems(sb)
{
	var i = 0;
	var a = new Array();
	for(i=0;i<sb.length;i++)
	{
		if(!sb.options[i].selected)
		{
			a[a.length] = sb.options[i];
		};
	}
	return a;
}

function SwapTextAreaSelect_checkIfExists(o, a)
{
	var i = 0;
	var test = false;
	for(i=0;i<a.length;i++)
	{
		if(o.value == a[i].value)
			test = true;
	}
	return test;
}

function SwapTextAreaSelect_selectAllRightOptions()
{
	var i=0;
	for(i=0;i<this._selectBox.length;i++)
		this._selectBox.options[i].selected = true;
};
//]]>
//--><!--
//<![CDATA[
// Class Tab
function Tab(_tabName, _divName)
{
	//properties
	this._tabName = _tabName;
	this._divName = _divName;
	this._functions = new Functions();
	
	//private methods
	
	//public methods
	this.init = Tab_init;
	this.deactivateTabs = Tab_deactivateTabs;
	this.hideAll = Tab_hideAll;
	this.show = Tab_show;
	
	this.init();
}

function Tab_init()
{
	this.deactivateTabs();
	this.hideAll();
}

function Tab_deactivateTabs()
{
	var e = document.getElementsByName(this._tabName);
	for(var i=0;i<e.length;i++)
	{
		e[i].className = '';
	}
	
}

function Tab_hideAll()
{
	var e = document.getElementsByName(this._divName);
	for(var i=0;i<e.length;i++)
	{
		e[i].style.display = 'none';
	}
	
}

function Tab_show(_id)
{
	var href_id = "href_" + _id;
	var href = document.getElementById(href_id);
	var div_id = "div_" + _id;
	var div = document.getElementById(div_id);
	this.deactivateTabs();
	this.hideAll();
	href.className = 'active';
	div.style.display = 'block';
}
//]]>
//-->
