//plan type access data array for term
term = new Array();
term[0] = new Array("1A","1 Year");
term[1] = new Array("1B","5 Year");
term[2] = new Array("1C","10 Year");
term[3] = new Array("1D","15 Year");
term[4] = new Array("1E","20 Year");
term[5] = new Array("1F","30 Year");
term[6] = new Array("1I","Level Term to 65");
term[7] = new Array("1J","Level Term to 70");
term[8] = new Array("1K","Level Term to 75");
term[9] = new Array("1M","Mortgage Plans");
//plan type access data array for term100
term100 = new Array();
term100[0] = new Array("2A","Guaranteed Term 100");
//plan type access data array for wholelife
wholelife = new Array();
wholelife[0] = new Array("3A","Whole Life/Guar. Life Pay");
wholelife[1] = new Array("3B","Whole Life/Guar. Payable to 65");
wholelife[2] = new Array("3C","Whole Life/Guar. 25");
wholelife[3] = new Array("3D","Whole Life/Guar. 20");
wholelife[4] = new Array("3E","Whole Life/Guar. 15");
wholelife[5] = new Array("3Q","Whole Life/Guar. Quick Pay");
//plan type access data array for speciality
add = new Array();
add[0] = new Array("5A","Accidental Dealth & Dismemberment");
ci = new Array();
ci[0] = new Array("5C","Comb Liv Ben/25%");
ci[1] = new Array("5D","Comb Liv Ben/50%");
ci[2] = new Array("5E","Comb Liv Ben/75%");
ci[3] = new Array("5F","Decr Liv Ben");
ci[4] = new Array("5L","Living Benefits");
ci[5] = new Array("5M","Living Ben/T10");
ci[6] = new Array("5N","Living Ben/T20");
ci[7] = new Array("5O","Living Ben/T65");
ci[8] = new Array("5P","Living Ben/T70");
ci[9] = new Array("5Q","Living Ben/T75");
ci[10] = new Array("5R","Living Ben/T100");
sr = new Array();
sr[0] = new Array("5S","Special Risk");

function pageSetup(obj) {
  obj.reset();
  statmsg(0);
  setFocus(obj);
  var ca_analysis_matched = false;
  var ca_analysis2_matched = false;  
  if (document.cookie)  {
// get the cookie
    var cookie_value = document.cookie;
// parse cookie values non-printing chars
    cookie_value = unescape(cookie_value);
// split cookie name from all form name/value pairs
    var cookie_stuff = cookie_value.split("=");
    var cookie_nameValue = cookie_stuff[1].split("&");
    found_cookie = false;
// check quote type - if different skip cookie populate form
// check coverage amount and compare to ca_analysis value
    for (x = 0; x < cookie_nameValue.length; x++)  {
      cookie_form = cookie_nameValue[x].split(":");
      if (cookie_form[0] == "type" && cookie_form[1] == obj["type"].value)
        found_cookie = true;
      else if (cookie_form[0] == "First Client Premium")
        fcp = cookie_form[1];
      else if (cookie_form[0] == "ca_analysis")  {	
        if (cookie_form[1] == "$"+fcp)
          ca_analysis_matched = true;
      }      
      else if (cookie_form[0] == "Second Client Premium")
        fcp2 = cookie_form[1];
      else if (cookie_form[0] == "ca_analysis2")  {	
        if (cookie_form[1] == "$"+fcp2)
          ca_analysis2_matched = true;
      }            
    }
    if (found_cookie)  {
      cookie_form = "";
      var cookie_nameValue = cookie_stuff[1].split("&");
// check quote type - if different skip cookie populate form
      for (x = 0; x < cookie_nameValue.length; x++)  {
        cookie_form = cookie_nameValue[x].split(":");
// see if a radio object - check
        if (cookie_form[0] == "First Client Gender" || cookie_form[0] == "First Client Health" || cookie_form[0] == "First Client Tobacco Use" ||
            cookie_form[0] == "Second Client Gender" || cookie_form[0] == "Second Client Health" || cookie_form[0] == "Second Client Tobacco Use")  {
// if a radio, check it (check value in cookie - check matching radio)
          if (cookie_form[1] == "M" || cookie_form[1] == "R" || cookie_form[1] == "N")  {
            eval_obj = eval('obj["' + cookie_form[0] + '"][0]');
            if (eval_obj)  eval_obj.checked = true;
          }
          else if (cookie_form[1] == "F" || cookie_form[1] == "P" || cookie_form[1] == "Y")  {
            eval_obj = eval('obj["' + cookie_form[0] + '"][1]');
            if (eval_obj)  eval_obj.checked = true;
          }
        }
// see if a select object - select
        else  {
          eval_obj = eval('obj["' + cookie_form[0] + '"]');
          if (eval_obj)  {
            eval_obj.value = cookie_form[1];            
          }
        }
      }
    }
  }

  if (!NS4) {  
// set plan type help file link
    make_a_change_pt();
    if (typeof obj["Second_Client_Coverage_Type"] != "undefined")
      make_a_change_pt2();
// set payment schedule help file link
    make_a_change_ps();
// set joint type help file link
    if (typeof obj["Joint Type"] != "undefined")
      make_a_change_jt();
  }
// check if value from needs analysis used  
  if (ca_analysis_matched)
    check_needs_value();    
   else
    document.wq.ca_analysis.value = "";
  if (typeof obj["ca_analysis2"] != "undefined")  {
    if (ca_analysis2_matched)
      check_needs_value2();    
     else
      document.wq.ca_analysis2.value = "";
  }
}

function setFocus(obj) {
  obj[0].focus();
  return;
};

function validate_page(obj) {
  return true;
};

// obj = form name
// startIndex = where DOB fields start in the form
function val_date(obj, startIndex)  {
// number of days in each month Jan - Dec
  var months = new Array ("31","29","31","30","31","30","31","31","30","31","30","31");
// month
  tmpMonthIndex=obj[startIndex].selectedIndex;//selected item in option list
  tmpMonthName=obj[startIndex].name;//selection field name
  tmpMonthText=obj[startIndex].options[tmpMonthIndex].text;//selection value
// day
  tmpDayIndex=obj[startIndex+1].selectedIndex;//selected item in option list
  tmpDayName=obj[startIndex+1].name;//selection field name
  tmpDayText=obj[startIndex+1].options[tmpDayIndex].text;//selection value
  tmpDayIndex += 1;//add one for array offset
// year
  tmpYearIndex=obj[startIndex+2].selectedIndex;//selected item in option list
  tmpYearName=obj[startIndex+2].name;//selection field name
  tmpYearText=obj[startIndex+2].options[tmpYearIndex].text;//selection value
  tmpYearIndex += 1;//add one for array offset
//check proper month to day value (jan ==max 31 days, feb = max 29 days)
  if (tmpDayIndex > months[tmpMonthIndex])  {
    tmpString1="The number of days in " + tmpMonthText + "\nhas been incorrectly set.\nPlease Re-select.";
    alert(tmpString1);
    obj[startIndex+1].focus();
    return false;
  }
//check proper year to day value (leap year feb = max 29 days || max 28 days)
//formula:  yr/4 ==0 && yr/100 !=0 || yr/400 ==0
//February && 29
  if (tmpMonthIndex == 1 && tmpDayIndex == 29)  {
    if ( (tmpYearText % 4 ==0 && tmpYearText % 100 != 0) || ( tmpYearText % 400 == 0) )    {
    }
    else    {
      tmpString1="The number of days in " + tmpMonthText + "\nhas been incorrectly set.\nPlease Re-select.";
      alert(tmpString1);
      obj[startIndex+1].focus();
      return false;
    }
  }
//birthdate range validation (no older than 95, no younger than today)
  var today = new Date();
  var m = today.getMonth(today);
  var d = today.getDate();
  var tmpYear19 = "19";
  yy = new String(today.getYear());
  var y;
//add first 2 digits from year returned if year <= 1999
  if (yy <= 99)  {
    y = tmpYear19+yy;
  }
  else  {
    y = yy.replace(/^1/, "20");
  }
//check against todays date to ensure proper birthdate entered
  if (tmpMonthIndex > m)  {
    if (tmpYearText >= y)    {
      alert("Your Birthdate has been set incorrectly.\nPlease Re-enter.");
      obj[startIndex].focus();
      return false;
    }
  }
  if (tmpMonthIndex == m)  {
    if (tmpDayIndex > d)    {
      if (tmpYearText >= y)      {
        alert("Your Birthdate has been set incorrectly.\nPlease Re-enter.");
        obj[startIndex].focus();
        return false;
      }
    }
  }
  if (tmpYearText >= y)  {
    alert("Your Birthdate has been set incorrectly.\nPlease Re-enter.");
    obj[startIndex].focus();
    return false;
  }
//check for maximum age (95)
  if ( (y-tmpYearText) > 95)  {
    alert("The maximum age is 95.\nPlease Re-enter.");
    obj[startIndex+1].focus();
    return false;
  }
// make sure items have been selected for
// Coverage Amount, Coverage Type, Payment Schedule
  if (submitting)  {
    submitting = val_ca_ct_ps();
    if (submitting)  {
// save a cookie
      submitting = setCookie(obj);
    }
// submit
    return submitting;
  }
};

  function setCookie(obj)  {
    if (NS4) return true;  	
    var cookie_name = "wq";
    var cookie_value = "";
    for (x = 0; x < obj.length; x++)  {
      if ( (obj[x].name == "First Client Gender" && obj[x].checked) ||
           (obj[x].name == "Second Client Gender" && obj[x].checked) ||
           (obj[x].name == "First Client Health" && obj[x].checked) ||
           (obj[x].name == "Second Client Health" && obj[x].checked) ||
           (obj[x].name == "First Client Tobacco Use" && obj[x].checked) ||
           (obj[x].name == "Second Client Tobacco Use" && obj[x].checked) ||
            obj[x].name != "First Client Gender" && obj[x].name != "Second Client Gender" &&
            obj[x].name != "First Client Health" && obj[x].name != "Second Client Health" &&
            obj[x].name != "First Client Tobacco Use" && obj[x].name != "Second Client Tobacco Use")  {
        if (obj[x].name == "First Client Premium" || obj[x].name == "Second Client Premium")  {
          tmp_value = obj[x].value;        
          tmp_value = tmp_value.replace(/\$/g, "")
          cookie_value += obj[x].name +":"+tmp_value + "&";
        }
        else
          cookie_value += obj[x].name +":"+obj[x].value + "&";
      }
    }
    expireDate = new Date;
    expireDate.setDate(expireDate.getDate()+60);
    document.cookie = cookie_name +"=" + escape(cookie_value) + "expires=" + expireDate.toGMTString() ;
    return true;
  }

function upperCase(number) {
};

function upperCaseText(obj) {
};


function upperCasePostal(obj) {
};

//this function is from winquote.js
//here it calls the older routine
function fc_val_date(obj)  {
// find 'First Client Month' form field
  var ret = "false";
  for (form_index = 0; form_index < obj.length; form_index++)  {
    if (obj[form_index].name == "month")  {
      return val_date(obj, form_index);
    }
  }
  return ret;
};
//this function is from winquotes.js
//here it calls the older routine
function sc_val_date(obj)  {
// find 'Second Client Birth Month' form field
  var ret = "false";
  for (form_index = 0; form_index < obj.length; form_index++)  {
    if (obj[form_index].name == "Birth month")  {
      ret = val_date(obj, form_index);
    }
  }
  return ret;
};
