/*---------------------------------/*
/*	Ceros Error JavaScript:
/*---------------------------------/*

/*	Please call the function, or output errors on the page with the class, "ssError"
/*	These will then be picked up. Use the CSS below as a default
/*---------------------------------/*
	#error{
		background: #F9E7BD;
		color: #A56633;
		display: none;
		font-size: 120%;
		text-align:center;
		width: auto;
		line-height: 1.5em;
		overflow: hidden;
		border-bottom: solid #EAC46A 3px;
	}
	#error p {
		padding-top: 0.5em;
	}
	#error a {
		display: block;
		float: right;
		padding: 0.5em 2em 0 0;
		color: #A56633;
		font-weight: bold;
	}
/*---------------------------------/*

Include these files on Ceros:
You may also want to use the YUI loader instead. If so, make sure this file comes after it!
/*---------------------------------/*	
	<!-- Dependencies -->
	<script src="/js/yui/build/yahoo/yahoo-min.js" 					type="text/javascript" ></script>
	<script src="/js/yui/build/yahoo-dom-event/yahoo-dom-event.js" 	type="text/javascript" ></script> 
	
	<!-- Source file -->
	<script src="/js/yui/build/dom/dom-min.js" 					type="text/javascript" ></script>
	<script src="/js/yui/build/animation/animation-min.js" 		type="text/javascript" ></script> 
	<script src="/js/yui/build/event/event-min.js" 				type="text/javascript" ></script>
/*---------------------------------/*


If you are using this and don't have the YUI locally accessiable:
/*---------------------------------/*
<!-- Dependencies -->
<script src="http://yui.yahooapis.com/2.4.0/build/yahoo/yahoo-min.js" 					type="text/javascript" ></script>
<script src="http://yui.yahooapis.com/2.4.0/build/yahoo-dom-event/yahoo-dom-event.js" 	type="text/javascript" ></script> 

<!-- Source file -->
<script src="http://yui.yahooapis.com/2.4.0/build/dom/dom-min.js" 					type="text/javascript" ></script>
<script src="http://yui.yahooapis.com/2.4.0/build/animation/animation-min.js" 		type="text/javascript" ></script> 
<script src="http://yui.yahooapis.com/2.4.0/build/event/event-min.js" 				type="text/javascript" ></script>
/*---------------------------------*/


YAHOO.util.Event.onDOMReady(errorInitialisation);
 
function errorInitialisation() {
   	// Place functions to call once the page had loaded here:
	displayErrors( null );
}

/*---------------------------------/*
/*   Display any server side errors printed out using the class ssError
/* 	 Put your divs in a relevent place using this class and they will be added to the error message at the top of the page
/*---------------------------------*/

function displayErrors( jsError ){
	var errorDivs = YAHOO.util.Dom.getElementsByClassName( 'ssError' );		// Any errors on the page
	var div;
	if( jsError != null || errorDivs.length > 0 ){						// ** We have error(s) to display. So here we create the error div in the dom.
		var toHeight;
		if( document.getElementById('error') ){ 							// If there is alreay an error div
			div = document.getElementById('error');							// Get the element
			for( var i = 0; div.childNodes.length > i; i++){
				div.removeChild( div.lastChild );							// Remove any content it already has from before
			}
		}else{
			div = document.createElement('div');							// We create an error div at the top of the DOM
			div.setAttribute('id','error');									// Set up it's id so it has style
			var body = document.getElementsByTagName('body');				// Get the body tag
			var firstChild = body[0].firstChild;							
			body[0].insertBefore(div,firstChild);							// Insert it as the first element in the body
		}
		
		var closeTxt = document.createTextNode( '[x]' );				// Create elements in the DOM
		var close = document.createElement('a');
		close.setAttribute('href','#');
		close.setAttribute('id','errorClose');
		close.appendChild( closeTxt );
		div.appendChild( close );
		YAHOO.util.Event.addListener( close, "click", closeError);
		
		if( jsError != null ){ 												// ** We are creating an error message from JavaScript
			var newtxt = document.createTextNode( jsError );					// Create a new text node
			var para = document.createElement('p');								// New paragraph for the error
			para.appendChild( newtxt );
			div.appendChild( para );											// Add the paragraph to our error element
			toHeight = 3;
		}else if( errorDivs.length > 0 ){ 									// ** We are styling an error message already in the HTML
			for( var i=0; i < errorDivs.length; i++){							// For each error on the page with the class 'ssError'
				var errorText = errorDivs[i].firstChild.data;					// Get the error string from the ssError	
				errorDivs[i].setAttribute("style","display: none;");			// Set the style
				errorDivs[i].style.cssText = "display: none;";					// Set the style for Internet Exploder
				var newtxt = document.createTextNode( errorText );				// Create elements in the DOM
				var para = document.createElement('p');
				para.appendChild( newtxt );
				div.appendChild( para );										// Add the error to the error div
			}																
			toHeight = (errorDivs.length * 1.5);							// Calculate the estimated height for the div where 1.5 is your line height in ems
			if( toHeight < 3 ){
				toHeight = 3;													// Add a min height so it's noticable
			}

		}
		div.style.cssText = "style','height: 1em; display: block; ";
		div.setAttribute( 'style','height: 1em; display: block;' );
		var attributes = { height: { from: 1, unit: 'em', to: toHeight, unit: 'em' } };
		var animation = new YAHOO.util.Anim( div , attributes, 3);
		animation.method = YAHOO.util.Easing.elasticOut;
		animation.animate();
	}
}
var hideError = function(){
	// Hides the error via CSS
	var div = document.getElementById('error');
	div.style.cssText = "style','display: hidden; ";
	div.setAttribute( 'style','display: hidden;' );
}
var closeError = function (e){
	// Blind-ups the error and then calls the hide above
	var div = document.getElementById('error');
	var attributes = { height: { from: 3, unit: 'em', to: 0, unit: 'em' } };
	var animation = new YAHOO.util.Anim( div , attributes, 0.3);
	animation.onComplete.subscribe( hideError );
	animation.animate();
}

