window.onerror = hideErrors;
function hideErrors(){return true;}
//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");
*/
//plan type for critical illness
///*
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");
//*/
// plan type for Special Risk
/*
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)  {
							if (eval_obj.name == "First_Client_Plan_Type")
								setup_plan_type(document.wq["First_Client_Coverage_Type"].options[document.wq["First_Client_Coverage_Type"].selectedIndex].value);
							else if (eval_obj.name == "Second_Client_Plan_Type")
								setup_plan_type2(document.wq["Second_Client_Coverage_Type"].options[document.wq["Second_Client_Coverage_Type"].selectedIndex].value);
							eval_obj.value = cookie_form[1];
						}
					}
				}
			}
		}
		if (!NS4) {
// set coverage type help file link
// 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;
  }

  if (submitting)  {
  	return pageSetdown(obj);
  }
};

	function pageSetdown(obj)	{
	    s = val_ca_ct_ps();
    	if (s)  {
      	s = setCookie(obj);
    	}
	    return s;
	}

  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;
};

function suff_filter_ync(obj)	{
   	editWin = window.open("ssi/suff_filter_ync.htm",'','dependent=yes,scrollbars=yes,resizable=yes,width=500,height=350,screenX=10,screenY=10,Left=10,Top=10');
	editWin.focus();
}
function suff_filter(obj)	{
   	editWin = window.open("suff_filter.htm",'','dependent=yes,scrollbars=yes,resizable=yes,width=500,height=530,screenX=10,screenY=10,Left=10,Top=10');
	editWin.focus();
}
function suff_filter_ync2(obj)	{
   	editWin = window.open("ssi/suff_filter_ync2.htm",'','dependent=yes,scrollbars=yes,resizable=yes,width=500,height=350,screenX=10,screenY=10,Left=10,Top=10');
	editWin.focus();
}
function suff_filter2(obj)	{
   	editWin = window.open("suff_filter2.htm",'','dependent=yes,scrollbars=yes,resizable=yes,width=500,height=530,screenX=10,screenY=10,Left=10,Top=10');
	editWin.focus();
}
