var qnum=0;  //current question number
var anum=0;  //number of questions answered

var totallinks=100;
var question=new Array(totallinks);
var answeryes=new Array(totallinks);
var answerno=new Array(totallinks);
var answeredq=new Array(20); // question numbers answered
var answeredyn=new Array(20); // yes or no answered to question

	function setquestions() {
	// question is the question
		// answeryes is next question if answer yes
		// answerno is next question if answer no
		// if answeryes=999 then answerno is the answer number
		question[1]="Is your company currently experiencing problems with cashflow?"
		answeryes[1]=11
		answerno[1]=12

		question[11]="Is the company's turnover less than expected?"
		answeryes[11]=21
		answerno[11]=22

		question[12]="Is the companies balance sheet negative?"
		answeryes[12]=23
		answerno[12]=24

		question[21]="Do creditors insist on immediate payment?"
		answeryes[21]=41
		answerno[21]=42

		question[22]="Are costs higher than anticipated?"
		answeryes[22]=42
		answerno[22]=32

		question[23]="Is the balance sheet negative due to large loans?"
		answeryes[23]=33
		answerno[23]=34

		question[24]="Do you think the nature of your business is currently viable?"
		answeryes[24]=35
		answerno[24]=36

		question[32]="Is the company curently making loses?"
		answeryes[32]=43
		answerno[32]=44

		question[33]="Are creditors willing to support the company?"
		answeryes[33]=45
		answerno[33]=46

		question[34]="Is the balance sheet negative due to losses brought forward?"
		answeryes[34]=47
		answerno[34]=11

		question[35]="Do you want to continue to run your business?"
		answeryes[35]=49
		answerno[35]=50

		question[36]="Are you willing to liquidate the company?"
		answeryes[36]=51
		answerno[36]=52

		question[41]="Can you afford the required payments?"
		answeryes[41]=61
		answerno[41]=62

		question[42]="Do you still believe in the viability of the business?"
		answeryes[42]=63
		answerno[42]=64

		question[43]="Can you afford to pay your creditors?"
		answeryes[43]=65
		answerno[43]=66

		question[44]="Are taxes (Corporation Tax, VAT, PAYE) affordable?"
		answeryes[44]=45
		answerno[44]=66

		question[45]="From the answers you have given it seems that your business is viable"
		answeryes[45]=999
		answerno[45]=1

		question[46]="You may opt for Phoenixing"
		answeryes[46]=999
		answerno[46]=2

		question[47]="Is the company currently profitable?"
		answeryes[47]=67
		answerno[47]=11

		question[48]="You appear to be solvent - start from the beginning"
		answeryes[48]=999
		answerno[48]=3

		question[49]="From the answers you have given it seems that your business is viable"
		answeryes[49]=999
		answerno[49]=1

		question[50]="You may consider selling the company"
		answeryes[50]=999
		answerno[50]=4

		question[51]="You may opt for Members Voluntary Liquidation (MVL)"
		answeryes[51]=999
		answerno[51]=5

		question[52]="You must review your business plan"
		answeryes[52]=999
		answerno[52]=9

		question[61]="You may opt for Administration"
		answeryes[61]=999
		answerno[61]=6

		question[62]="Have you received court summons or judgement?"
		answeryes[62]=71
		answerno[62]=72

		question[63]="Do you think the company could continue to trade if historic debts were rescheduled?"
		answeryes[63]=73
		answerno[63]=74

		question[64]="You may opt Creditor Voluntary Liquidation (CVL)"
		answeryes[64]=999
		answerno[64]=7

		question[65]="From the answers you have given it seems that your business is viable"
		answeryes[65]=999
		answerno[65]=1

		question[66]="You may opt for Administration"
		answeryes[66]=999
		answerno[66]=6

		question[67]="Do you feel excessive pressure from creditors?"
		answeryes[67]=75
		answerno[67]=76

		question[71]="Do you still believe in the viability of the business?"
		answeryes[71]=81
		answerno[71]=82

		question[72]="Do you believe in the companies better future?"
		answeryes[72]=83
		answerno[72]=84

		question[73]="You may opt for Company Voluntary Arrangement (CVA)"
		answeryes[73]=999
		answerno[73]=8

		question[74]="You may opt for Creditors Voluntary Liquidation (CVL)"
		answeryes[74]=999
		answerno[74]=7

		question[75]="You may opt for Phoenixing"
		answeryes[75]=999
		answerno[75]=2

		question[76]="From the answers you have given it seems that your business is viable"
		answeryes[76]=999
		answerno[76]=1

		question[81]="Do you think the company could continue to trade if historic debts were rescheduled?"
		answeryes[81]=91
		answerno[81]=92

		question[82]="Your company qualifies for Compulsory Liquidation"
		answeryes[82]=999
		answerno[82]=10

		question[83]="You may opt for a Company Voluntary Arrangement"
		answeryes[83]=999
		answerno[83]=8

		question[84]="You may opt for Creditor Voluntary Liquidation"
		answeryes[84]=999
		answerno[84]=7

		question[91]="You may opt for CVA"
		answeryes[91]=999
		answerno[91]=8

		question[92]="You may opt for Phoenixing"
		answeryes[92]=999
		answerno[92]=2
	}

	function startagain()
	{
		//start again - refresh page
		qnum=1;
		window.location.hash = "#questions";
		var sURL = (window.location.pathname);
		window.location.href = sURL;
		window.location.reload( 0 );
	};

	function changeLink(yep)
	{
		var i=qnum;
		answeredq[anum]=qnum;//set question number answered
		answeredyn[anum]=yep; // set yes/no answered to question
		anum++;
		if (yep) 
			{
			qnum = answeryes[i];
			}
		else 
			{
			qnum = answerno[i];
			}
		changeQuestion(qnum,i,yep);
	};

	function changeQuestion(num,i,yep) //num=next question, i=current question, yep= yes or no answer 
	{
		//setup new question TextNode
		var newSpan = document.createElement("p");
		var newText = document.createTextNode(question[num]);
		newSpan.appendChild(newText);
		var oldSpan = document.createElement("div");
		oldSpan.setAttribute("class","greytext")
		oldSpan.className="greytext";

		// append yes or no text answer to last question
		if (yep)
			{
			var oldText = document.createTextNode(question[i]+" Yes");
			}
		else
			{
			var oldText = document.createTextNode(question[i]+" No");
			}
		oldSpan.appendChild(oldText);
//		var codelayer = document.getElementById("codelayer");
		var spanq = document.getElementById("question");
		if (qnum!=1)
			{
			//if not first question remove previous question and append question with answer
			spanq.removeChild(spanq.lastChild);
			var throwaway = spanq.appendChild(oldSpan);
			}
		if (answeryes[num] == 999)
			{
			// if result then show correct result
			document.getElementById('finish'+answerno[num]).style.display = 'block' ; 
			document.getElementById('finishall').style.display = 'block' ; 
			window.location.hash = "#summary";
			writeanswers(); // put answers into form field
			document.forms.theForm1.finishnum.value = answerno[num];
			document.forms.theForm1.finishbox.value = num;
			initdefaultevents();
			focusCursor();
			}
		else
			{
			// show next question
			var throwaway = spanq.appendChild(newSpan);
			}
		//show start again if not first question
		document.getElementById('back').style.display = (num == 1) ? 'none' : 'block'; 
		// hide buttons if end
		document.getElementById('buttons').style.display = (answeryes[num] == 999) ? 'none' : 'block'; 
	};

	function writeanswers() {
		var i=0;
		var newline = "\n";
		var localresponses = '';
		for (i=0;i < anum; i++) {
			localresponses += question[answeredq[i]];
			if (answeredyn[i])
				{ 
				localresponses += ' Yes'; 
				}
			else
				{ 
				localresponses += ' No'; 
				}
			localresponses += newline;
		}
		document.forms.theForm1.qresponses.value=localresponses;
		
	}
	
	function init() {
	  // start first question - remove click to start button
		document.getElementById('start1').style.display = 'none' ; 
		changeQuestion(qnum,1,1);
		window.location.hash = "#questions";
	};


/* for other browsers */
/*window.onload = init;*/
qnum=1;
setquestions();
document.getElementById('start1').style.display = 'block' ; 
