/* Theme Pack 3.1.1+ DO NOT modify */

// Used by panels
CS.v3.updateContent = Class.create(CS.v3.Base.prototype, {
	initialize: function(target) {
	
		this.readInsertTarget = target.readAttribute('data-csInsertNodeTarget');
		this.insertTargets = $$(this.readInsertTarget);
		this.insertTargetsLength = this.insertTargets.length;
		this.insertTarget = this.insertTargets[0];
		
		this.readToInsert = target.readAttribute('data-csContentFromNode');
		this.InsertableNodes = $$(this.readToInsert);
		this.InsertableNodesLength = this.InsertableNodes.length;
	},
	_insert: function(content) {
		
	}
});

CS.v3.appendContent = Class.create(CS.v3.Base.prototype, {
	initialize: function(target) {
		
		this.updateNodes = new CS.v3.updateContent(target);
		
		this.prevInserted = this.updateNodes.insertTarget.select('.csInserted');
		this.prevInsertedLength = this.prevInserted.length;
		
		this.prevInsertedNum = this.prevInsertedLength;
		this.InsertableNode = $$(this.updateNodes.readToInsert)[this.prevInsertedNum];
		
		this.readToInsertTop = target.readAttribute('data-csInsertNodeTop');
		
		if (!this.InsertableNode) {
	
			this.InsertableNode = this.updateNodes.InsertableNodes[0];
		}
		
		if (this.readToInsertTop == 'true') {
			this.lastOrFirstElem = $$(this.updateNodes.readInsertTarget + " > *:first-child");
		
		} else {
			this.lastOrFirstElem = $$(this.updateNodes.readInsertTarget + " > *:last-child");
		}
	},
	_insert: function(content) {
		if (this.readToInsertTop == 'true') {
			this.updateNodes.insertTarget.insert({top: content});
		} else {
			this.updateNodes.insertTarget.insert({bottom: content});
		}
		new CS.v3.zIndex();
	}
});

CS.v3.addAddEntryContent = Class.create(CS.v3.Base.prototype, {
	initialize: function(target) {
	
		var aC = new CS.v3.appendContent(target);
	
		var form = CS.v3.getParentElement(target,'FORM');//target.up('form');
		form.addClassName('csHideAddEntryRow');
		if (aC.lastOrFirstElem[0].match('.csZebra')) {
				var innerCode = aC.InsertableNode.innerHTML;
				this.rowInnerWrap = '<tr class="csInserted csRowEm">' + innerCode + '</tr>';
			} else {
				var innerCode = aC.InsertableNode.innerHTML;
				this.rowInnerWrap = '<tr class="csInserted csZebra csRowEm">' + innerCode + '</tr>';
			}
		
		aC._insert(this.rowInnerWrap);
		
			var tr = CS.v3.down(form,'TR.csInserted');
			var textarea = CS.v3.down(tr,'TEXTAREA');
			textarea.addClassName('csVal-required');
			//alert(textarea);
		}
});

CS.v3.cancelAddEntryContent = Class.create(CS.v3.Base.prototype, {
	initialize: function(target) {
	
		var form = CS.v3.getParentElement(target,'FORM');//target.up('form');
		var errorBox = CS.v3.down(form,'.csFormStatus');
		
		if (errorBox) {
		
			errorBox.addClassName('csBoxHide');
		}
		
		form.removeClassName('csHideAddEntryRow');
	}
});


