// JavaScript Document

/*

PanelViewer is a set of javascript functions to handle panel transtions for form completion

it does not explicitly handle verification but gives a method to provide such an option

Here is how this javascript library is intended to be used:

<form>
	...
	<div ID="SomePanelSet">
		...
		<div ID="PANEL_1" class="panel">...panel 1 content goes here...</div>
		<div ID="PANEL_2">...panel 1 content goes here...</div>
		<div ID="PANEL_3">...panel 1 content goes here...</div>
		...
	</div>
		
</form>
		



*/

var panelArray = new Array();
var currentPanel = 0;

/*********************************
*This initializes the panelArray, 
* finding all div tags with class
* "panel"
* Makes the first panel visible 
* while leaving the others hidden
**********************************/
function initializePanel(elm_Id){
	//elm_Id is the id of the panel wrapper (called "SomePanelSet" above)


	var panelWrapper = document.getElementById(elm_Id);
	var childArray = new Array();
	childArray = panelWrapper.childNodes;
	
	//find all panel div tags
	for(var i= 0; i < childArray.length; i++){
		if(childArray[i].className == "panel" ){
			panelArray = panelArray.concat(childArray[i]);
		}
	}
	
	//initialize first panel to be visible and the rest to be hidden
	if(panelArray[0] != null && panelArray.length != 0){
		panelArray[0].style.visibility = "visible";
		for(var j = 1; j < panelArray.length; j++){
			panelArray[j].style.display = "none";
		}
	}
}


function nextPanel(){
	if( (currentPanel + 1) < panelArray.length){
		panelArray[currentPanel].style.display = "none";
		currentPanel++;
		panelArray[currentPanel].style.display = "block";
	}
}



function prevPanel(){
	if( (currentPanel - 1) >= 0){
		panelArray[currentPanel].style.display = "none";
		currentPanel--;
		panelArray[currentPanel].style.display = "block";
	}
}


function verify(ver_func, ver_obj){
	return ver_func.call(ver_obj); // runs the method of the object being passed in
}

function noenter() {
	return !(window.event && window.event.keyCode == 13); 
}

