/***************** xmlToArray Start *********************/
//Parameters: xmlString, root name to start parse
//Returns Array of XML Data
//Requires admin/js/xmlparse.js
function xmlToArray(xmlString, root)
{
	var thisXmlArray= new Array();
	var res=new Array();
	res=XMLParse.xml2ObjArray(xmlString, root);
	for(var i in res[0])
	{
		thisXmlArray[i]=res[0][i];
	}
	return thisXmlArray;
}
/***************** xmlToArray End *********************/

/***************** Form Error Checking Start *********************/
function form_submit(FRM) {
	loading(true);
	// checks to see if errors... if yes disable submit -- change to error message popup
	var inp=document.getElementsByTagName('input');
	for(var i=0;i<inp.length;i++){
		if(document.getElementById("errorID"+inp[i].name))
		{
			if(confirm("There are errors on the page. Are you sure you want to submit this information?"))
			{
				window.document.forms[FRM].submit();
				loading(false);
			}
			else
				return false;
		}

	}
	loading(false);
}

function addError(FLD, text)
{
	removeError(FLD);

	var theNewParagraph = document.createElement('span');
	theNewParagraph.id="errorID"+FLD;
	theNewParagraph.className="displayError";
	var theTextOfTheParagraph = document.createTextNode(text);
	theNewParagraph.appendChild(theTextOfTheParagraph);
	document.getElementById(FLD).parentNode.appendChild(theNewParagraph);
	$(FLD).className="formError";
}
function removeError(FLD)
{
	if(document.getElementById("errorID"+FLD))
		document.getElementById(FLD).parentNode.removeChild(document.getElementById("errorID"+FLD));
	$(FLD).className="";
}

/***************** Form Error Checking End *********************/

/***************** Confirmation Start *********************/
//Also in /admin/js/functions.js
function confirmDisplay(str, okFunction, badFunction, title, iconDisplay) {
	YAHOO.namespace("widget");

	if(str==null)
		str='Do you want to continue?';
	if(title==null)
		title='Confirm';
	switch(iconDisplay)
	{
		case "warn":
			iconDisplay=YAHOO.widget.SimpleDialog.ICON_WARN;
			break 
		case 'help':
			iconDisplay=YAHOO.widget.SimpleDialog.ICON_HELP;
			break 
		case 'tip':
			iconDisplay=YAHOO.widget.SimpleDialog.ICON_TIP;
			break 
		case 'info':
			iconDisplay=YAHOO.widget.SimpleDialog.ICON_INFO;
			break 
		default:
			iconDisplay=YAHOO.widget.SimpleDialog.ICON_HELP;
	}
	// Define various event handlers for Dialog
	var handleYes = function() {
		this.hide();
		eval(okFunction);
		return false;
	};
	var handleNo = function() {
		this.hide();
		eval(badFunction);		
		return false;
	};
	YAHOO.namespace("container");
	// Instantiate the Dialog
	YAHOO.container.simpledialog1 = new YAHOO.widget.SimpleDialog("simpledialog1", { width: "300px", fixedcenter: true, modal:true, zIndex : 1000, visible: false, draggable: false, close: true, text: str, icon: iconDisplay, constraintoviewport: true, buttons: [ { text:"Yes", handler:handleYes, isDefault:true },{ text:"No",  handler:handleNo } ] } );
	YAHOO.container.simpledialog1.setHeader(title);
	// Render the Dialog
	YAHOO.container.simpledialog1.render(document.body);
	YAHOO.container.simpledialog1.show();

	YAHOO.util.Event.addListener("show", "click", YAHOO.container.simpledialog1.show, YAHOO.container.simpledialog1, true);
	YAHOO.util.Event.addListener("hide", "click", YAHOO.container.simpledialog1.hide, YAHOO.container.simpledialog1, true);

}
/***************** Confirmation End *********************/


/***************** Notes Popups Start *********************/
function note(noteID) {	
	var notePopUp= YAHOO.namespace("container");
	YAHOO.container.notePopUp = new YAHOO.widget.Panel("notePopUp",  {  context:["note"+noteID,"tr","br"], width:"150px",  visible:false, draggable:false, close:true } );
	YAHOO.container.notePopUp.setHeader('Certificate Notes');
	YAHOO.container.notePopUp.setBody($('noteText'+noteID).innerHTML);
	YAHOO.container.notePopUp.render(document.body);
	// Show the Panel
	YAHOO.container.notePopUp.show();

	return false;
}

/***************** Help Popups End *********************/
