// edd code starting here, old code left below - will probably modify most of it . . .
// this is not how I would usually code things but under the circumstances it is not practical to recode from scratch . . .


function topSwitch(dropDown){

/*

  if (selected == '' || selected == 'No') {
	  document.getElementById('thenewcalculator').style.display = "";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "none";
  } else if (selected == "No, I am not applying from the UK or from India") { // bosolete, leaving in case things chan
      document.getElementById('thenewcalculator').style.display = "none";
      document.getElementById('message1').style.display = "";
      document.getElementById('message2').style.display = "none";
  } else if (selected == "Yes, I am in the UK as an HSMP (or Tier 1) (seeking an extension)") {
      // extra bit here!!
      document.getElementById('5a').disabled = true;
      document.getElementById('5a').checked = false;
      document.getElementById('5amessage').innerHTML = "<b>This option is not open to those already holding HSMP / Tier 1 status</b><br>";
      document.getElementById('thenewcalculator').style.display = "";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "none";
      // added in may for bugfixes sacha wanted . . .
      document.hsmp.country_bands.selectedIndex = 1;
      document.hsmp.country_bands.disabled = true;
  } else if (selected == "Yes, I am in the UK as a Work Permit holder (or Tier 2)" || selected == "Yes, I am in the UK as a Student - (or Tier 4)" || selected == "Yes, I am in the UK as a Post Study Work Visa/IGS/SEGS/Fresh Talent"
              || selected == "Yes, I am in the UK as an Innovator" || selected == "Yes, I am in the UK as a Post Graduate Doctor or Dentist provisions" || selected == "Yes, I am in the UK as a Student Nurse") {
      document.getElementById('thenewcalculator').style.display = "";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "none";
  } else if (selected == "Yes, I am applying from India") {
      document.getElementById('thenewcalculator').style.display = "";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "none";
      document.getElementById('7a').disabled = true;
      document.getElementById('7b').disabled = false;
  } else if (selected == "Yes, I am in the UK as a Visitor" || selected == "Yes, I am in the UK as a Working Holiday maker" || selected == "Yes, I am in the UK as a Spouse, Marriage or unmarried partner visa"
              || selected == "Yes, I am in the UK as a Dependents visa") {
      document.getElementById('thenewcalculator').style.display = "none";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "";
  }
  
<option value="">Select... </option>
<option value="No">No</option>
<option value="Yes and I am here as a HSMP (or Tier 1) (seeking an extension)">Yes and I am here as a HSMP (or Tier 1) (seeking an extension)</option>
<option value="Yes and I am here as a Work Permit holder (or Tier 2)">Yes and I am here as a Work Permit holder (or Tier 2)</option>
<option value="Yes and I am here as a Student - (or Tier 4)">Yes and I am here as a Student - (or Tier 4)</option>
<option value="Yes and I am here as a Post Study Work Visa / IGS / SEGS / Fresh Talent">Yes and I am here as a Post Study Work Visa / IGS / SEGS / Fresh Talent</option>
<option value="Yes and I am here as an Innovator">Yes and I am here as an Innovator</option>
<option value="Yes and I am here as a Post Graduate Doctor or Dentist provisions">Yes and I am here as a Post Graduate Doctor or Dentist provisions</option>
<option value="Yes and I am here as a Student Nurse">Yes and I am here as a Student Nurse</option>
<option value="Yes and I am here as a Visitor">Yes and I am here as a Visitor</option>
<option value="Yes and I am here as a Working Holiday maker">Yes and I am here as a Working Holiday maker</option>
<option value="Yes and I am here as a Spouse, Marriage or unmarried partner visa">Yes and I am here as a Spouse, Marriage or unmarried partner visa</option>
<option value="Yes and I am here as a Dependents visa">Yes and I am here as a Dependents visa</option>

*/

  var selected = dropDown.value;

  document.getElementById('5a').disabled = false;

  document.getElementById('7a').disabled = false;
  document.getElementById('7b').checked = false;
  document.getElementById('7b').disabled = true;

  document.getElementById('5amessage').innerHTML = "";

  ageNormal();



// havce currenly told this not to mess with 5b
  document.hsmp.country_bands.disabled = false;

  document.getElementById('earningpower').style.color = "#000000";
  document.getElementById('earningpower2').style.color = "#000000";
  document.getElementById('man_req1').style.background = "#ffffff";
  document.getElementById('man_req2').style.background = "#ffffff";
  document.getElementById('5bmessage').style.background = "#ffffff";
  document.hsmp.Button.disabled = false;
  
  document.getElementById('languagerequirement').style.display = "";
  document.getElementById('languagerequirement2').style.display = "none";
  document.getElementById('countrymessage').style.display = "none";
  document.getElementById('englishauto').checked = false;
  


  if (selected == "Yes I am here as a HSMP participant (seeking an extension)" || selected == "Yes I am a Tier 1 (General) participant (seeking an extension)") {
      if (selected == "Yes I am here as a HSMP participant (seeking an extension)") {
          ageHSMP();
      }
      if (selected == "Yes I am a Tier 1 (General) participant (seeking an extension)") {
          ageTier1();
      }
      // extra bit here!!
      document.getElementById('5a').disabled = true;
      document.getElementById('5a').checked = false;
      document.getElementById('5b').disabled = false; // we know this is uk .. .
      document.getElementById('5amessage').innerHTML = "<b>This option is not open to those already holding HSMP / Tier 1 status</b><br>";
      document.getElementById('5bmessage').style.background = "#E7E7E7";
      document.getElementById('thenewcalculator').style.display = "";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "none";
      // added in may for bugfixes sacha wanted . . .
      //document.getElementById('earningpower').style.color = "#AAAAAA";
      document.getElementById('earningpower2').style.color = "#AAAAAA";
      document.hsmp.country_bands.selectedIndex = 1;
      setBands(dropDown);
      document.hsmp.country_bands.disabled = true;
      document.hsmp.Button.disabled = true;
      document.getElementById('man_req2').style.background = "#E7E7E7";
      document.getElementById('countrymessage').style.display = ""; // help message for hat the code above does . .

      // sort out the language requirement
      englishOff();
      document.getElementById('languagerequirement').style.display = "none";
      document.getElementById('languagerequirement2').style.display = "";
      document.getElementById('englishauto').checked = true;

      // show bachelors degree question + earning bits
      document.getElementById('degreediv1').style.display = "";
      document.getElementById('degreediv2').style.display = "";
      document.getElementById('earningdiv1').style.display = "";
      document.getElementById('earningdiv2').style.display = "";
      document.getElementById('earningdiv3').style.display = "";
      document.getElementById('earningdiv4').style.display = "";



  } else if (selected == "Yes, I am here as a Visitor (including Business Visitor)" || selected == "Yes, I am here as a Working Holiday Maker" || selected == "Yes, I am here on a Spouse, Marriage or Unmarried Partner visa"
              || selected == "Yes, I am here on a Dependents visa") {
      //document.getElementById('thenewcalculator').style.display = "none";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "";
      document.getElementById('7a').checked = false;
      document.getElementById('7a').disabled = true;
      document.getElementById('7b').disabled = false;
      newEarningBechelorBitsOff();
  } else  if (selected == "No"){ // default
      document.getElementById('thenewcalculator').style.display = "";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "none";
      //document.getElementById('5b').disabled = false; // why would this be here . . .? 5b shopuld be contorlled by the country selector ? maybe add back latet if nescessary. Don't like this whole bit . . .
      document.getElementById('man_req1').style.background = "#E7E7E7";
      document.getElementById('7a').checked = false;
      document.getElementById('7a').disabled = true;
      document.getElementById('7b').disabled = false;
      newEarningBechelorBitsOff();
  } else { // default
      document.getElementById('thenewcalculator').style.display = "";
      document.getElementById('message1').style.display = "none";
      document.getElementById('message2').style.display = "none";
      //document.getElementById('5b').disabled = false;// why would this be here . . .? 5b shopuld be contorlled by the country selector
      // hide bachelors degree question and ensure it's unticked . . . (same for earning bits)
      document.getElementById('degreediv1').style.display = "none";
      document.getElementById('degreediv2').style.display = "none";
      document.getElementById('2c').checked = false;
      newEarningBechelorBitsOff();
  }
  return true;
}

function newEarningBechelorBitsOff(){
    document.getElementById('earningdiv1').style.display = "none";
    document.getElementById('earningdiv2').style.display = "none";
    document.getElementById('earningdiv3').style.display = "none";
    document.getElementById('earningdiv4').style.display = "none";
    document.getElementById('earning1').checked = false;
    document.getElementById('earning2').checked = false;
}

function ageHSMP(){
    document.getElementById('age1').innerHTML = "29  or under";
    document.getElementById('age2').innerHTML = "30 or 31 years old ";
    document.getElementById('age3').innerHTML = "32 or 33 years old";
    document.getElementById('age4').innerHTML = "34 or over";
}

function ageTier1(){
    document.getElementById('age1').innerHTML = "30 or under";
    document.getElementById('age2').innerHTML = "31 or 32 years old";
    document.getElementById('age3').innerHTML = "33 or 34 years old";
    document.getElementById('age4').innerHTML = "35 or over";
}

function ageNormal(){
    document.getElementById('age1').innerHTML = "27 or under";
    document.getElementById('age2').innerHTML = "28 or 29 years old";
    document.getElementById('age3').innerHTML = "30 or 31 years old";
    document.getElementById('age4').innerHTML = "32 or over";
}



function englishOff(){
    document.getElementById('english1').checked = false;
    document.getElementById('english2').checked = false;
    document.getElementById('english3').checked = false;
    document.getElementById('english4').checked = false;
    document.getElementById('english1').disabled = true;
    document.getElementById('english2').disabled = true;
    document.getElementById('english3').disabled = true;
    //document.getElementById('english4').disabled = true;
}

function englishSwitch1(dropDown){

  var selected = dropDown.value;

 englishOff();

  if (selected != 'none') {
	  document.getElementById('english1').disabled = false;
      document.getElementById('english1').checked = true;
  }
  return true;
}

function englishSwitch2(dropDown){

  var selected = dropDown.value;

 englishOff();

  if (selected != 'none') {
	  document.getElementById('english2').disabled = false;
      document.getElementById('english2').checked = true;
  }
  return true;
}

function englishSwitch3(dropDown){

  var selected = dropDown.value;

 englishOff();

  if (selected != 'none') {
	  document.getElementById('english3').disabled = false;
      document.getElementById('english3').checked = true;
  }
  return true;
}

// modified old code . .

// declare arrays
var BandsSalary = new Array;

// define price bands
BandsSalary['A'] = new Array ( '16,000', '16,000', '17,999', '18,000', '19,999', '20,000', '22,999', '23,000', '25,999', '26,000', '28,999', '29,000', '31,999', '32,000', '34,999', '35,000', '39,999', '40,000' );
BandsSalary['B'] = new Array ( '6,957', '6,957', '7,825', '7,826', '8,695', '8,696', '9,999', '10,000', '11,303', '11,304', '12,608', '12,609', '13,912', '13,913', '15,216', '15,217', '17,390', '17,391' );
BandsSalary['C'] = new Array ( '5,000', '5,000', '5,624', '5,625', '6,249', '6,250', '7,187', '7,188', '8,124', '8,125', '9,062', '9,063', '9,999', '10,000', '10,937', '10,938', '12,499', '12,500' );
BandsSalary['D'] = new Array ( '3,019', '3,019', '3,395', '3,396', '3,773', '3,774', '4,339', '4,340', '4,905', '4,906', '5,471', '5,472', '6,037', '6,038', '6,603', '6,604', '7,546', '7,547' );
BandsSalary['E'] = new Array ( '1,404', '1,404', '1,578', '1,579', '1,753', '1,754', '2,017', '2,018', '2,280', '2,281', '2,543', '2,544', '2,806', '2,807', '3,069', '3,070', '3,508', '3,509' );


// END USER SETTINGS 

//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-+

// main 

// error message if no total field exists
var Err_Fields = 'The form does not contain required fields. ';


// get start points
var hsmpPoints = gethsmpPoints(); // leaving in for the mo . . .


// state of buttons
var disabledState = true;

//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-+

// functions 

// get the points from query - I shall leave this in grudgingly . . . why is it here??
function gethsmpPoints() {
  //anything n the query?
  var sQuery = location.search;
  if (sQuery == '') return 0;
  // remove '?p=' to leave an integer
  if (sQuery.indexOf(ky) > -1) sQuery = sQuery.substring(ky.length, sQuery.length);
  if (isNaN(sQuery)) return 0
  else sQuery = parseInt(sQuery);
  // return integer
  return sQuery;
}

// Calculate the points and eligibility
function hsmpCalculate1(hsmp_btn) {


  // get the containing form  
  var hsmp = hsmp_btn.form;



// right time to be a smartarse with q3 to make an earnings variable for the email . . .

    var earningIndex = getPoints(hsmp.q3) / 5;

    var band = hsmp.country_bands.value.substr(0,1);


    if (earningIndex != '') {
        if (earningIndex == 0) {
            hsmp.earnings.value = "Under &pound;" + BandsSalary[band][0];
        } else if (earningIndex == 9) {
            hsmp.earnings.value = "Over &pound;" + BandsSalary[band][17];
        } else {
            hsmp.earnings.value = "Between &pound;" + BandsSalary[band][(2 * earningIndex) - 1] + " and &pound;" + BandsSalary[band][2 * earningIndex];
        }
    }






  // default values
  var total_points = hsmpPoints;
  var eligibility = true;

  //questions
  total_points += getPoints(hsmp.q1);
  total_points += getPoints(hsmp.q2);
  total_points += getPoints(hsmp.q3);
  total_points += getPoints(hsmp.q4);

// first point of logic, hopefully gonna zap tha crap below . . .

  if (total_points < 75) {
      location.href = "http://www.uk-wp.com/pbsg-r3.php?p=" + total_points;
      return false;
  }
  total_points += getPoints(hsmp.q5);
  total_points += getPoints(hsmp.q6);

  if (!hsmp.total) alert(Err_Fields)
  else hsmp.total.value = total_points;


  var countryname = document.hsmp.country_bands.selectedIndex;
  countryname = document.hsmp.country_bands.options[countryname].text;



  if (getPoints(hsmp.q5) == 0) { // no english . . .
  // pbsg-r6
      hsmp.action = "http://www.uk-wp.com/pbsg-r6.php?countryname=" + countryname;
      document.hsmp.country_bands.disabled = false;
      hsmp.submit();
  } else if (getPoints(hsmp.q6) == 0) { // no maintenance . . . . .
  // pbsg-r6
      hsmp.action = "http://www.uk-wp.com/pbsg-r7.php?countryname=" + countryname;
      document.hsmp.country_bands.disabled = false;
      hsmp.submit();
  } else if (getPoints(hsmp.o1) == 0 || getPoints(hsmp.o2) == 0 || getPoints(hsmp.o3) == 0) {
      hsmp.action = "http://www.uk-wp.com/pbsg-r8.php?countryname=" + countryname;
      document.hsmp.country_bands.disabled = false;
      hsmp.submit();
  } else { // all is fine we assume . . .
      hsmp.action = "http://www.uk-wp.com/pbsg-r4.php?countryname=" + countryname;
      document.hsmp.country_bands.disabled = false;
      hsmp.submit();
  }
  return false;
}


// add points for question object q
function getPoints(q) {
  var points = 0;
  var question = q;
  if (question) {
    // whats the value of the checked answer?
    // if one checkbox...
    if (question.length)
    if (question.length == 1)
      points = (question.value); 
    else {
      // many checkboxes
      for(var i=0;i<question.length;i++){
        if (question[i].checked) {
          points = (question[i].value); 
          break;
        } //if 
      } //for
    } //(question.length == 1)
    else {
      points = (question.value); 
    }
  } //(question)
  //return integer
  points = parseInt(points);
  return points;
}

//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-+

function turn5bonifUK(){
    var bnd = document.hsmp.country_bands.selectedIndex;
    bnd = document.hsmp.country_bands.options[bnd].value;
    if (bnd == 'A UK') { // on and enable
        document.getElementById('5b').disabled = false;
        document.getElementById('5b').checked = true;
    }
}

// depending on the band chosen, display 6 values on the page
function setBands(obj){
  // get the selected band
  var band = getBand(obj);
 // uk check here . . .

  if (band == 'A UK') {
      document.getElementById('5b').disabled = false;
      //document.getElementById('5b').checked = true; // don't auto check, they need the earnings. . . .
      //alert("true");
  } else {
      // if not uk then need to uncheck and diable 5b, makes sense . . .
      document.getElementById('5b').checked = false;
      document.getElementById('5b').disabled = true;
      //alert("false");
  }

  band = band.substr(0,1);

  // show the country name and age
  var cb = document.hsmp.country_bands;
  if (band != '') 
    cb = cb.options[cb.selectedIndex].text;

  document.getElementById('span_country_name').innerHTML = cb;

  if (band == '') return;

  // unDISABLE the fields
  obj.form.q3[0].disabled = false;
  obj.form.q3[1].disabled = false;
  obj.form.q3[2].disabled = false;
  obj.form.q3[3].disabled = false;
  obj.form.q3[4].disabled = false;
  obj.form.q3[5].disabled = false;
  obj.form.q3[6].disabled = false;
  obj.form.q3[7].disabled = false;
  obj.form.q3[8].disabled = false;
  obj.form.q3[9].disabled = false;

  // ENABLE the buttons?
  //obj.form.btnCalculate.disabled = false;
  obj.form.btnContinue.disabled = false;

  //clr message
  // get the corresponding 17 values
  if (band) {
	  document.getElementById('span_band0').innerHTML = BandsSalary[band][0];
	  document.getElementById('span_band1').innerHTML = BandsSalary[band][1];
	  document.getElementById('span_band2').innerHTML = BandsSalary[band][2];
	  document.getElementById('span_band3').innerHTML = BandsSalary[band][3];
	  document.getElementById('span_band4').innerHTML = BandsSalary[band][4];
	  document.getElementById('span_band5').innerHTML = BandsSalary[band][5];
	  document.getElementById('span_band6').innerHTML = BandsSalary[band][6];
	  document.getElementById('span_band7').innerHTML = BandsSalary[band][7];
	  document.getElementById('span_band8').innerHTML = BandsSalary[band][8];
	  document.getElementById('span_band9').innerHTML = BandsSalary[band][9];
	  document.getElementById('span_band10').innerHTML = BandsSalary[band][10];
	  document.getElementById('span_band11').innerHTML = BandsSalary[band][11];
	  document.getElementById('span_band12').innerHTML = BandsSalary[band][12];
	  document.getElementById('span_band13').innerHTML = BandsSalary[band][13];
	  document.getElementById('span_band14').innerHTML = BandsSalary[band][14];
	  document.getElementById('span_band15').innerHTML = BandsSalary[band][15];
	  document.getElementById('span_band16').innerHTML = BandsSalary[band][16];
	  document.getElementById('span_band17').innerHTML = BandsSalary[band][17];
  } else {
		//nothing;
  }
}
//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-+

// return the band chosen
function getBand(that){
  // get the band
  var hsmp = that.form;
  var bnd = '';
  if (hsmp.country_bands) {
    bnd = hsmp.country_bands.selectedIndex;
    bnd = hsmp.country_bands.options[bnd].value;
  }
  return bnd;
}

