  var quesloc = location.href.indexOf("?");
  var indivScores = '';
//  alert("Loading questionnaire with parameters " + quesloc);
  if (quesloc < 1) {
//	alert("No parameter found. Reloading Skills Test Form.");
    window.location = "Business-Analyst-Skills-Test.html";
  }
  IE4=(document.all)?1:0;
	  NS4=(document.layers)?1:0;
	  DOM=(document.getElementById)?1:0;
	  NS6=((DOM)&&(!IE4))?1:0;
	  ver4=(IE4||DOM||NS4)?1:0;
	  nav=navigator.appVersion;
	  nav=nav.toLowerCase();
	  isMac=(nav.indexOf("mac")!=-1)?1:0;
	  IEmac=((document.all)&&(isMac))?1:0;
  function getChoice(btns){
	    for (var i = 0; i < btns.length; i++) {
		      if (btns[i].checked) {
			        return i;
		      }
	    }
	    return 0;
  }
  function calcScores(){
//	alert("calcScores");	
    arTags = new Array("Business Analysis Planning and Monitoring", "Requirements Elicitation", "Requirements Management and Communication", "Enterprise Analysis", "Requirements Analysis", "Solution Assessment and Validation");
    arLinks = new Array("http://requirementssolutions.com/BABOK-Knowledge-Area-2-Business-Analysis-Planning-and-Monitoring.html", "http://requirementssolutions.com/How_to_Write_and_Analyze_Business_Stakeholder_and_Solution_Requirements.html", "http://requirementssolutions.com/How_to_Manage_Communicate_Business_System_Requirements.html", "http://requirementssolutions.com/BABOK-Knowledge-Area-3-Elicitation-and-5-Enterprise-Analysis.html", "http://requirementssolutions.com/How_to_Model_Analyze_Improve_Business_Processes.html", "http://requirementssolutions.com/BABOK-Knowledge-Area-7-Solution-Assessment-and-Validation.html");
    arTarget = new Array(192, 80, 64, 136, 200, 160);
    arQuestions = new Array(24, 10, 8, 17, 25, 20);
      arCurrent = new Array(0, 0, 0, 0, 0, 0);
        arCurrent[0] += getChoice(document.forms[0].Cur124);
        arCurrent[0] += getChoice(document.forms[0].Cur125);
        arCurrent[0] += getChoice(document.forms[0].Cur126);
        arCurrent[0] += getChoice(document.forms[0].Cur130);
        arCurrent[0] += getChoice(document.forms[0].Cur132);
        arCurrent[0] += getChoice(document.forms[0].Cur133);
        arCurrent[0] += getChoice(document.forms[0].Cur134);
        arCurrent[0] += getChoice(document.forms[0].Cur136);
        arCurrent[0] += getChoice(document.forms[0].Cur137);
        arCurrent[0] += getChoice(document.forms[0].Cur138);
        arCurrent[0] += getChoice(document.forms[0].Cur141);
        arCurrent[0] += getChoice(document.forms[0].Cur142);
        arCurrent[0] += getChoice(document.forms[0].Cur143);
        arCurrent[0] += getChoice(document.forms[0].Cur145);
        arCurrent[0] += getChoice(document.forms[0].Cur146);
        arCurrent[0] += getChoice(document.forms[0].Cur147);
        arCurrent[0] += getChoice(document.forms[0].Cur148);
        arCurrent[0] += getChoice(document.forms[0].Cur149);
        arCurrent[0] += getChoice(document.forms[0].Cur152);
        arCurrent[0] += getChoice(document.forms[0].Cur153);
        arCurrent[0] += getChoice(document.forms[0].Cur155);
        arCurrent[0] += getChoice(document.forms[0].Cur157);
        arCurrent[0] += getChoice(document.forms[0].Cur158);
        arCurrent[0] += getChoice(document.forms[0].Cur159);
        arCurrent[1] += getChoice(document.forms[0].Cur125);
        arCurrent[1] += getChoice(document.forms[0].Cur127);
        arCurrent[1] += getChoice(document.forms[0].Cur131);
        arCurrent[1] += getChoice(document.forms[0].Cur135);
        arCurrent[1] += getChoice(document.forms[0].Cur136);
        arCurrent[1] += getChoice(document.forms[0].Cur140);
        arCurrent[1] += getChoice(document.forms[0].Cur142);
        arCurrent[1] += getChoice(document.forms[0].Cur144);
        arCurrent[1] += getChoice(document.forms[0].Cur145);
        arCurrent[1] += getChoice(document.forms[0].Cur153);
        arCurrent[2] += getChoice(document.forms[0].Cur142);
        arCurrent[2] += getChoice(document.forms[0].Cur145);
        arCurrent[2] += getChoice(document.forms[0].Cur152);
        arCurrent[2] += getChoice(document.forms[0].Cur160);
        arCurrent[2] += getChoice(document.forms[0].Cur161);
        arCurrent[2] += getChoice(document.forms[0].Cur162);
        arCurrent[2] += getChoice(document.forms[0].Cur170);
        arCurrent[2] += getChoice(document.forms[0].Cur171);
        arCurrent[3] += getChoice(document.forms[0].Cur124);
        arCurrent[3] += getChoice(document.forms[0].Cur125);
        arCurrent[3] += getChoice(document.forms[0].Cur126);
        arCurrent[3] += getChoice(document.forms[0].Cur130);
        arCurrent[3] += getChoice(document.forms[0].Cur131);
        arCurrent[3] += getChoice(document.forms[0].Cur132);
        arCurrent[3] += getChoice(document.forms[0].Cur134);
        arCurrent[3] += getChoice(document.forms[0].Cur135);
        arCurrent[3] += getChoice(document.forms[0].Cur138);
        arCurrent[3] += getChoice(document.forms[0].Cur146);
        arCurrent[3] += getChoice(document.forms[0].Cur147);
        arCurrent[3] += getChoice(document.forms[0].Cur149);
        arCurrent[3] += getChoice(document.forms[0].Cur154);
        arCurrent[3] += getChoice(document.forms[0].Cur155);
        arCurrent[3] += getChoice(document.forms[0].Cur156);
        arCurrent[3] += getChoice(document.forms[0].Cur163);
        arCurrent[3] += getChoice(document.forms[0].Cur164);
        arCurrent[4] += getChoice(document.forms[0].Cur126);
        arCurrent[4] += getChoice(document.forms[0].Cur127);
        arCurrent[4] += getChoice(document.forms[0].Cur128);
        arCurrent[4] += getChoice(document.forms[0].Cur129);
        arCurrent[4] += getChoice(document.forms[0].Cur130);
        arCurrent[4] += getChoice(document.forms[0].Cur133);
        arCurrent[4] += getChoice(document.forms[0].Cur134);
        arCurrent[4] += getChoice(document.forms[0].Cur135);
        arCurrent[4] += getChoice(document.forms[0].Cur138);
        arCurrent[4] += getChoice(document.forms[0].Cur139);
        arCurrent[4] += getChoice(document.forms[0].Cur141);
        arCurrent[4] += getChoice(document.forms[0].Cur142);
        arCurrent[4] += getChoice(document.forms[0].Cur143);
        arCurrent[4] += getChoice(document.forms[0].Cur144);
        arCurrent[4] += getChoice(document.forms[0].Cur146);
        arCurrent[4] += getChoice(document.forms[0].Cur148);
        arCurrent[4] += getChoice(document.forms[0].Cur149);
        arCurrent[4] += getChoice(document.forms[0].Cur151);
        arCurrent[4] += getChoice(document.forms[0].Cur152);
        arCurrent[4] += getChoice(document.forms[0].Cur155);
        arCurrent[4] += getChoice(document.forms[0].Cur165);
        arCurrent[4] += getChoice(document.forms[0].Cur166);
        arCurrent[4] += getChoice(document.forms[0].Cur167);
        arCurrent[4] += getChoice(document.forms[0].Cur168);
        arCurrent[5] += getChoice(document.forms[0].Cur123);
        arCurrent[5] += getChoice(document.forms[0].Cur126);
        arCurrent[5] += getChoice(document.forms[0].Cur128);
        arCurrent[5] += getChoice(document.forms[0].Cur129);
        arCurrent[5] += getChoice(document.forms[0].Cur130);
        arCurrent[5] += getChoice(document.forms[0].Cur132);
        arCurrent[5] += getChoice(document.forms[0].Cur133);
        arCurrent[5] += getChoice(document.forms[0].Cur134);
        arCurrent[5] += getChoice(document.forms[0].Cur136);
        arCurrent[5] += getChoice(document.forms[0].Cur140);
        arCurrent[5] += getChoice(document.forms[0].Cur141);
        arCurrent[5] += getChoice(document.forms[0].Cur142);
        arCurrent[5] += getChoice(document.forms[0].Cur143);
        arCurrent[5] += getChoice(document.forms[0].Cur146);
        arCurrent[5] += getChoice(document.forms[0].Cur147);
        arCurrent[5] += getChoice(document.forms[0].Cur148);
        arCurrent[5] += getChoice(document.forms[0].Cur153);
        arCurrent[5] += getChoice(document.forms[0].Cur154);
        arCurrent[5] += getChoice(document.forms[0].Cur156);
        arCurrent[5] += getChoice(document.forms[0].Cur169);
        indivScores = '';
        indivScores += getChoice(document.forms[0].Cur123) + ';';
        indivScores += getChoice(document.forms[0].Cur124) + ';';
        indivScores += getChoice(document.forms[0].Cur125) + ';';
        indivScores += getChoice(document.forms[0].Cur126) + ';';
        indivScores += getChoice(document.forms[0].Cur127) + ';';
        indivScores += getChoice(document.forms[0].Cur128) + ';';
        indivScores += getChoice(document.forms[0].Cur129) + ';';
        indivScores += getChoice(document.forms[0].Cur130) + ';';
        indivScores += getChoice(document.forms[0].Cur131) + ';';
        indivScores += getChoice(document.forms[0].Cur132) + ';';
        indivScores += getChoice(document.forms[0].Cur133) + ';';
        indivScores += getChoice(document.forms[0].Cur134) + ';';
        indivScores += getChoice(document.forms[0].Cur135) + ';';
        indivScores += getChoice(document.forms[0].Cur136) + ';';
        indivScores += getChoice(document.forms[0].Cur137) + ';';
        indivScores += getChoice(document.forms[0].Cur138) + ';';
        indivScores += getChoice(document.forms[0].Cur139) + ';';
        indivScores += getChoice(document.forms[0].Cur140) + ';';
        indivScores += getChoice(document.forms[0].Cur141) + ';';
        indivScores += getChoice(document.forms[0].Cur142) + ';';
        indivScores += getChoice(document.forms[0].Cur143) + ';';
        indivScores += getChoice(document.forms[0].Cur144) + ';';
        indivScores += getChoice(document.forms[0].Cur145) + ';';
        indivScores += getChoice(document.forms[0].Cur146) + ';';
        indivScores += getChoice(document.forms[0].Cur147) + ';';
        indivScores += getChoice(document.forms[0].Cur148) + ';';
        indivScores += getChoice(document.forms[0].Cur149) + ';';
        indivScores += getChoice(document.forms[0].Cur151) + ';';
        indivScores += getChoice(document.forms[0].Cur152) + ';';
        indivScores += getChoice(document.forms[0].Cur153) + ';';
        indivScores += getChoice(document.forms[0].Cur154) + ';';
        indivScores += getChoice(document.forms[0].Cur155) + ';';
        indivScores += getChoice(document.forms[0].Cur156) + ';';
        indivScores += getChoice(document.forms[0].Cur157) + ';';
        indivScores += getChoice(document.forms[0].Cur158) + ';';
        indivScores += getChoice(document.forms[0].Cur159) + ';';
        indivScores += getChoice(document.forms[0].Cur160) + ';';
        indivScores += getChoice(document.forms[0].Cur161) + ';';
        indivScores += getChoice(document.forms[0].Cur162) + ';';
        indivScores += getChoice(document.forms[0].Cur163) + ';';
        indivScores += getChoice(document.forms[0].Cur164) + ';';
        indivScores += getChoice(document.forms[0].Cur165) + ';';
        indivScores += getChoice(document.forms[0].Cur166) + ';';
        indivScores += getChoice(document.forms[0].Cur167) + ';';
        indivScores += getChoice(document.forms[0].Cur168) + ';';
        indivScores += getChoice(document.forms[0].Cur169) + ';';
        indivScores += getChoice(document.forms[0].Cur170) + ';';
        indivScores += getChoice(document.forms[0].Cur171) + ';';
  document.getElementById("RawScores").value = indivScores;

//        alert(arTarget[0]);
		    HAdrawChart();
		    return true;
  }
 
  // dynamically build the output string
  function HAdrawChart(){
  //    alert("HAdrawChart");
    var cwidth;
    var twidth;
    imBlue = new Image();
    imGreen = new Image();
    imBlue = "images/BarCurrentGreen.jpg";
    imGreen = "images/BarCurrentGreen.jpg";
    strBack1 = "images/BASkillDark2009.jpg";
    strBack2 = "images/BASkillLight2009.jpg"
    intHeight = 10
    strDefaultColor = "#33FF00";
    strColor = strDefaultColor;
    strToWrite = "";
    chartWidth = 450;
    maxWidth = 450;
    strToWrite += '<table width="720" border="0" align="center" cellpadding="0" cellspacing="0">';
    strToWrite += "  <tr>";
    strToWrite += "    <td>";
    strToWrite += '      <table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#000000">';
    strToWrite += '        <tr height="35">';
    strToWrite += '          <td  width="210"><font face="Comic Sans MS, Trebuchet MS, sans-serif" size="+1" color="#FFCC00">IIBA<sup>&reg;</sup> Knowledge Area</font></td>';
    strToWrite += '          <td width="60" class="alignBottom"><font face="Comic Sans MS, Trebuchet MS, sans-serif" size="+1" color="#FFCC00">Type</font></td>';
    strToWrite += '          <td  width="' + chartWidth + '" align="center" class="alignBottom"><font face="Comic Sans MS, Trebuchet MS, sans-serif" size="+1" color="#FFCC00">Level</font></td>';
    strToWrite += '        </tr>';
    strToWrite += '      </table>';
    strToWrite += "    </td>";
    strToWrite += "  </tr>";
    strToWrite += "  <tr>";
    strToWrite += "    <td>";
    document.getElementById("KA_Scores").value = "";
    for(i = 0; i< arTags.length; i++){
      document.getElementById("KA_Scores").value += "(" + Math.round(arCurrent[i]/(arQuestions[i]*10)*100) + ")";
  strColor = strDefaultColor;
	      imBlue = "images/BarCurrentGreen.jpg";
	      if(arCurrent[i]/(arQuestions[i]*10)*100<79) {
	        strColor = "#FFFF00";
	        imBlue="images/BarCurrentYellow.jpg";
	      }  
       if(arCurrent[i]/(arQuestions[i]*10)*100<54) {
	        strColor = "#FF0000";
	        imBlue="images/BarCurrentRed.jpg";
	      }
       if(arCurrent[i]==0) {
	        strColor = "#FF0000";
	        imBlue="images/BarCurrentRed.jpg";
	      }
      cwidth=parseInt(arCurrent[i])/(arQuestions[i]*10);
      cwidth=Math.round(cwidth*chartWidth*Math.pow(10,0))/Math.pow(10,0);
      arTarget[i]=arQuestions[i]*8;
      twidth=parseInt(arTarget[i])/(arQuestions[i]*10);
      twidth=Math.round(twidth*chartWidth*Math.pow(10,0))/Math.pow(10,0);
      if(i % 2 == 0)
        strBack = strBack1;
      else
        strBack = strBack2;
      strToWrite += '      <table width="720" border="0" cellpadding="2" cellspacing="0" background ="' + strBack + '">';
      strToWrite += "        <tr>";
      strToWrite += '          <td rowspan="2">';
      strToWrite += '            <table width="100%" cellpadding="3">';
      strToWrite += '              <tr>';
      strToWrite += '                <td><a href = "' + arLinks[i] + '" class="graph">' + arTags[i] + '</a></td>';
      strToWrite += '              </tr>';
      strToWrite += '            </table>';
      strToWrite += '          </td>';
      strToWrite += '          <td width="60" height="22" align="center" valign="bottom" class="BASkillYel1" background ="' + strBack + '"><font color="' + strColor + '">Self</font></td>';
      strToWrite += '          <td width="450" valign="bottom"><img src="' + imBlue + '" width="' + cwidth + '" height="' + intHeight + '" vspace="3" /></td>';
      strToWrite += "        </tr>";
      strToWrite += "        <tr>";
      strToWrite += '          <td height="22" align="center" valign="top" class="BASkillGold1">Target</td>';
      strToWrite += '          <td valign="top"><img src="' + imGreen + '" width="' + twidth + '" height="' + intHeight + '" vspace="4" /></td>';
      strToWrite += "        </tr>";
      strToWrite += "      </table>";
    }
    strToWrite += "    </td>";
    strToWrite += "  </tr>";
    strToWrite += "</table>";
    strToWrite += "<br /><br />";
    //	alert(document.getElementById("theChart").style.visibility);
    if(IE4) {
      if((IEmac) && (DOM)) return;
      winInnerWidth = document.body.clientWidth;
      winInnerHeight = document.body.clientHeight;
      screenWidth = screen.availWidth;
      screenHeight = screen.availHeight;
      window.offscreenBuffering = true;
      theChart.innerHTML=strToWrite;
      theChart.innerHTML=strToWrite;
    }
    if(NS4) {
      with(document.theChart) {
        document.open();
        document.write(strToWrite);
        document.close();
      }
   }
    if(NS6) {
      document.getElementById("theChart").innerHTML=strToWrite;
    }

	    document.getElementById("Questionnaire").style.visibility = "hidden";
	    document.getElementById("fixed").style.visibility = "hidden";
	    document.getElementById("SkillsGraph").style.visibility = "visible";
  }
  function decode(q) {
	  // Decode the email address// the following code goes into both pages to encode and decode the email;
  var f = '0123456789-()~.,/abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var g = 'rPW)ChO5(VczGwSLv~QnlHa9BX6-,MTkE27dyD/ZxUobKJ8uYe01_tg3Fqs4jAm.IpiRfN';
    var j;
    var k;
    var u = '';
    var i;
//alert("encoded value = " + q);
    if(f.indexOf("a") == "~") {
      for(j = 0;j<q.length;j++) {
        k = g.indexOf(q[j]) - q.length - j;
	    while(k<0) k+=g.length;
	    u += f[k];
      }
    }
    else {
      for(j = 0;j<q.length;j++){
        for(i = 0;i<g.length;i++) {
		  if(g.substr(i,1) == q.substr(j,1)) break;
	    }
//		alert(i);
		k = i - q.length - j;
	    while(k<0) k+=g.length;
	    u += f.substr(k, 1);
	  }
    }
//alert("Decoded value = " + u);
    while(u.indexOf('~')> 0) u = u.replace("~"," ");
    return u;
  }

function extractParams() {
//  Extract all parameters
  var y = location.href.split("?");
  var h = y[1].split('&amp%3b');
	  if(h.length != 9) window.location = "Business-Analyst-Skills-Test.html";
//  alert("There are a total of " + h.length + " variables in the parameter.");
  document.getElementById("leadID").value = unescape(h[0]);
  document.getElementById("BA_Experience").value=decode(unescape(h[1]));
  document.getElementById("realname").value = decode(h[2]);
  document.getElementById("telephone").value = decode(h[3]);
  document.getElementById("company").value = decode(h[4]);
  document.getElementById("position").value = decode(h[5]);
  document.getElementById("manager").value = decode(h[6]);
//  alert("coded " + h[7] + " = decoded " + decode(h[7]));
  var eMailCode = decode(h[7]);
  var b = eMailCode.split("/");
  var c = b[3].split(",");
  var k = 0;
  var v = '';
  var w = '';
  var u = decode(h[8]);
//  alert("Unprocessed email = " + eMail);
// Decode the email address
//  Insert the '.' at the appropriate positions
  var a = 0;
  k = 0;
  for(i = 0;i<b[2];i++) {
//  alert("Insert . at " + c[i]);
	    if(i < b[2]) {
		      a = k + (+c[i]);
		      v += u.substring(k, a) + ".";
	} 
	k = a; 
  };
//  Insert the email indicator at the appropriate location
  v += u.substring(k);
  u = v.substring(0, b[1]) + "@" + v.substring(b[1]);
//  alert('Final email = ' + u);
  document.getElementById("email").value = u;
}
