//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// List of functions  "stepselector.js"
/*
function StepFunction (nme,act) 	Object: name, action

function Step (nm,ttl,mtype) 		Object: name, action
	this.changelocking = function (nm) 
	this.addfunction = function (nme,act)
	this.UpdateSelectedFunctionIndex = function (ind)
	this.addnextbuttonfunction = function (ddt)
	this.createStepBody = function (bodystring) 

function AddStep (nm,ttl,mtype) 
function UpdateStepStatus (num) 
function ReturnStepDisplayelements () 
function ReturnStepTitle () 
function UpdateFunctionIndex (i,j) 
function ReturnStepFunctions () 
function DisplayStepSELECTOR() 
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



var StepStatus = 0;
var Steps = new Array ();
function StepFunction (nme,das,act) {
	this.name = nme;
	this.displayActionSettins = das;
	this.action = act;
}

//-----------------------------------------------------------------------------------------------------------

function Step (nm,ttl,BeforeNextStep,mtype) {
	this.name = nm;
	this.title = ttl;
	this.locked = 0;
	this.menutype = mtype;
	this.BeforeNextStepFunction = BeforeNextStep;
	this.BeforeNextStepFunctionCompleted = false;
	
	this.changelocking = function (nm) {
		this.locked = nm;
	}
	this.functions = new Array();
	this.addfunction = function (nme,das,act) {
		this.functions[this.functions.length] = new StepFunction (nme,das,act);
	}
	this.SelectedFunctionIndex = 0;
	this.UpdateSelectedFunctionIndex = function (ind) {
		this.SelectedFunctionIndex = ind;
	}
	this.StepBody = "";
	this.createStepBody = function (bodystring) {
		this.StepBody = bodystring;
	}
}


function AddStep (nm,ttl,BeforeNextStep,mtype) {
if(!mtype) emtyp = "inline";
if(!BeforeNextStep) BeforeNextStep = "";
	Steps[Steps.length] = new Step (nm,ttl,BeforeNextStep,mtype);
}


//-----------------------------------------------------------------------------------------------------------
function UpdateStepStatus (num) {
	if (num==Steps.length)	num=0;
		
	for (i=0; i<Steps.length; i++) {
		if (i<=num)	Steps[i].changelocking(1);
		else		Steps[i].changelocking(0);
	}
	StepStatus = num;
	DisplayStepSELECTOR();
}


//-----------------------------------------------------------------------------------------------------------
function ReturnStepDisplayelements () {
var STR = "";
	for (i=0; i<Steps.length; i++ ) {
		if(!Steps[i].locked) {
			STR = STR + "<div class ='";
				if (i==0) STR = STR + "firstelement ";
				if (i==StepStatus) STR = STR + "selected ";
			STR = STR + "'>" + Steps[i].name + "</div>"
		}
		else {
			STR = STR + "<a  href='javascript://'  onclick='UpdateStepStatus("+i+"); ";
				if (i==0)
					STR = STR + "Start();"
				if (Steps[i].functions.length>0) {
					STR = STR + "UpdateFunctionIndex("+i+","+Steps[i].SelectedFunctionIndex+"); ";
					if(Steps[i].functions[Steps[i].SelectedFunctionIndex].displayActionSettins!="")
						STR = STR + Steps[i].functions[Steps[i].SelectedFunctionIndex].displayActionSettins + "; ";
					if(Steps[i].functions[Steps[i].SelectedFunctionIndex].action!="")
						STR = STR + Steps[i].functions[Steps[i].SelectedFunctionIndex].action + "; ";
				}	
			STR = STR + "' ";
				STR = STR + "class ='";
				if (i==0) STR = STR + "firstelement ";
				if (i==StepStatus) STR = STR + "selected ";
			STR = STR + "'>" + Steps[i].name + "</a>"
			
		}
	}
return STR;
}

//-----------------------------------------------------------------------------------------------------------
function ReturnStepTitle () {
var STR = "";
	for (i=0; i<Steps.length; i++ ) {
		if (i==StepStatus) STR = STR + Steps[i].title;
	}
return STR;
}

//-----------------------------------------------------------------------------------------------------------
function UpdateFunctionIndex (i,j) {
//alert(i+ " : " + j)
	Steps[i].UpdateSelectedFunctionIndex(j);
	document.getElementById("stepdisplay").innerHTML 		= ReturnStepDisplayelements();	
	document.getElementById("stepfunctions").innerHTML 		= ReturnStepFunctions();
}

//-----------------------------------------------------------------------------------------------------------
function ReturnStepFunctions () {
var STR = "";
	for (i=0; i<Steps.length; i++ ) {
		if (StepStatus>=i) {
			STR = STR + "<div class ='functionblock"
			if (i==0) STR = STR + " firstelement"
			STR = STR + "'>"
			
			
			if(Steps[i].functions.length>0) {
				for (j=0; j<Steps[i].functions.length; j++ ) {
					STR = STR + "<a href='javascript://' onclick='";
					STR = STR + "UpdateFunctionIndex(\""+i+"\",\""+j+"\");";
					
					if ((Steps[i].functions[j].displayActionSettins!="") && (i==StepStatus))
						STR = STR + Steps[i].functions[j].displayActionSettins + ";";
					if(Steps[i].functions[j].action!="")
						STR = STR + Steps[i].functions[j].action + ";";
					STR = STR + "'";
					if (Steps[i].SelectedFunctionIndex==j) 		STR = STR + "class='selected'";	
						STR = STR + ">" +Steps[i].functions[j].name + "</a>";
				}
			}	
			STR = STR + "</div>";
		}	
	}
return STR;
}


//-----------------------------------------------------------------------------------------------------------
function ReturnStepBody() {
	return Steps[StepStatus].StepBody;
}


 var NextStepFunctionString = "";
 
 function NextStep() {
 			
	if (Steps[StepStatus].BeforeNextStepFunction!="")  
		eval(Steps[StepStatus].BeforeNextStepFunction);
 			
	if ((Steps[StepStatus].BeforeNextStepFunction!="") && (Steps[StepStatus].BeforeNextStepFunctionCompleted))
		eval(NextStepFunctionString);
	else if	(Steps[StepStatus].BeforeNextStepFunction=="")
		eval(NextStepFunctionString);
 }

//-----------------------------------------------------------------------------------------------------------
function ReturnLinktoNextStep(){
var ss="";
NextStepFunctionString = "";
	if (StepStatus<(Steps.length-1)) {
		var temp = 	StepStatus +1;
			//ss = ss + StepStatus +" - "+ Steps[StepStatus].title +" - "+ Steps[StepStatus].BeforeNextStepFunction;
			ss = ss + "<a href='javascript://' class='next' onclick='";
			ss = ss + "NextStep(); "
			ss = ss + "'>";
			ss = ss + "next";
			ss = ss + "</a>";
			
		
			if (Steps[temp].functions[Steps[temp].SelectedFunctionIndex].displayActionSettins!="") 
				NextStepFunctionString = NextStepFunctionString + Steps[temp].functions[Steps[temp].SelectedFunctionIndex].displayActionSettins + " ;";
				
			if (Steps[temp].functions[Steps[temp].SelectedFunctionIndex].action!="") 
				NextStepFunctionString = NextStepFunctionString + Steps[temp].functions[Steps[temp].SelectedFunctionIndex].action + " ;";
				
			NextStepFunctionString = NextStepFunctionString + "UpdateStepStatus("+temp+") ;";
				
			if(Steps[temp].functions.length>0)
				NextStepFunctionString = NextStepFunctionString + "UpdateFunctionIndex("+temp+","+Steps[temp].SelectedFunctionIndex+") ;";	
			
	}
return ss;
}

//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------

function DisplayStepSELECTOR() {
	document.getElementById("steptitle").innerHTML 			= ReturnStepTitle();
	document.getElementById("stepdisplay").innerHTML 		= ReturnStepDisplayelements();
	document.getElementById("stepfunctions").innerHTML 		= ReturnStepFunctions();
	document.getElementById("nextstepBodyArea").innerHTML 	= ReturnLinktoNextStep();
	if (0==StepStatus)
		document.getElementById("workingArea").innerHTML	= "";
}

//-----------------------------------------------------------------------------------------------------------


//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------

function testFunctionstepBodyArea(num) {
	document.getElementById("stepBodyArea").innerHTML 		= num;
}
function testFunctionworkingArea(num) {
	document.getElementById("workingArea").innerHTML 		= num;
}