function popupWindow(page) 
{
  window.open('popups/trusts/' + (page),'popup','width=400,height=400,scrollbars=1');
}

function married(what)
{
  if (what != "")
  {
    document.all("marriedqs").style.display = "block";
    var mv = (what == "Yes" ? "block" : "none");
    var nv = (what == "Yes" ? "none" : "block");
    document.all("nomarried").style.display = nv;
    document.all("yesmarried1").style.display = document.all("yesmarried2").style.display = document.all("husbandbens").style.display = document.all("husbandbens2").style.display = mv;
  }
  else
  {
    document.all("marriedqs").style.display = "none";
  }
}

function isStateOk(what)
{
  if (what.value == "Louisiana")
  {
    alert("Unfortunately, the laws of Louisiana will not allow us to create a will or trust for you.  You will need to contact a lawyer in your area to form a will or trust");
    what.value = "";
  }
  else if (what.value == "Arkansas" || what.value == "Maine" || what.value == "Michigan" || what.value == "New Jersey" || what.value == "North Carolina" || what.value == "Virginia")
  {
    document.all("kidsstates1").style.display = "block";
    document.all("kidsstates2").style.display = "inline";
    document.all("kidsstates3").style.display = "none";
  }
  else if (what.value == "Alaska" || what.value == "California" || what.value == "Nevada")
  {
    document.all("kidsstates1").style.display = "block";
    document.all("kidsstates2").style.display = "none";
    document.all("kidsstates3").style.display = "inline";
  }
  else
    document.all("kidsstates1").style.display = "none";
}

function hasKids(what)
{
  if (what != "")
  {
    document.all("nkq").style.display = (what == "Yes" ? "block" : "none");
    document.all("afterkids").style.display = (what == "Yes" ? "none" : "block");
  }
}

function nkids(what)
{
  if (what != "")
  {
    what = parseInt(what);
    for (var i = 1; i <= what; i++)
      document.all("k" + i).style.display = "block";
    for (i = what + 1; i <= 10; i++)
      document.all("k" + i).style.display = "none";
    document.all("kq").style.display = "block";
  }
}

function doneKids()
{
  var nk = parseInt(document.all("numkids").value);
  var bob = false;
  for (var i = 1; i <= nk; i++)
    if (document.MyForm("childname" + i).value == "")
      bob = true;
  if (!bob)
  {
    document.all("afterkids").style.display = "block";
  }
}

function showsuccessors(what)
{
  if (what != "")
  {
    document.all("successors").style.display = "block";
    document.all("single1").style.display = document.all("single2").style.display = document.all("single3").style.display = (what == "single" ? "inline" : "none");
    document.all("multi1").style.display = document.all("multi4").style.display = document.all("multi5").style.display = (what == "multi" ? "inline" : "none");
    document.all("multi2").style.display = document.all("multi3").style.display = document.all("multi6").style.display = document.all("multi7").style.display = (what == "multi" ? "block" : "none");
  }
}

var gfilledout = false;
function propDist(what,where)
{
  if (where == null)
    where = "";
  var smbenqs, gbenqs, s_hasmultiben, r_hasmultiben, hasmultipercent, s_hassingleben, r_hassingleben, hasmultieven, residuaryqs;
  if (what == "onebenygetsall")
  {
    smbenqs = "block";
    gbenqs = "none";
    s_hasmultiben = "none";
    r_hasmultiben = "none";
    hasmultipercent = "none";
    s_hassingleben = "inline";
    r_hassingleben = "block";
    hasmultieven = "none";
    residuaryqs = "block";
  }
  else if (what == "multieven")
  {
    smbenqs = "block";
    gbenqs = "none";
    s_hasmultiben = "inline";
    r_hasmultiben = "block";
    hasmultipercent = "none";
    s_hassingleben = "none";
    r_hassingleben = "none";
    hasmultieven = "block";
    residuaryqs = "block";
  }
  else if (what == "multipercent")
  {
    smbenqs = "block";
    gbenqs = "none";
    s_hasmultiben = "inline";
    r_hasmultiben = "block";
    hasmultipercent = "block";
    s_hassingleben = "none";
    r_hassingleben = "none";
    hasmultieven = "none";
    residuaryqs = "block";
  }
  else if (what == "gifts")
  {
    smbenqs = "none";
    gbenqs = "block";
    s_hasmultiben = "none";
    r_hasmultiben = "none";
    hasmultipercent = "none";
    s_hassingleben = "none";
    r_hassingleben = "none";
    hasmultieven = "none";
    if (gfilledout)
      residuaryqs = "block";
    else
      residuaryqs = "none";
  }
  document.all(where+"smbenqs").style.display = smbenqs;
  document.all(where+"gbenqs").style.display = gbenqs;
  for (var i = 1; i < 4; i++)
    document.all(where+"hasmultipercent" + i).style.display = hasmultipercent;
  document.all(where+"hassingleben1").style.display = s_hassingleben;
  if (document.MyForm.ismarried.value == "No")
    document.all(where+"hassingleben2").style.display = r_hassingleben;
  else if (where != "w")
    document.all(where+"hassingleben2").style.display = "none";
  document.all(where+"hasmultiben1").style.display = s_hasmultiben;
  for (i = 2; i < 4; i++)
    document.all(where+"hasmultiben"+i).style.display = r_hasmultiben;
  document.all(where+"hasmultieven").style.display = hasmultieven;
  document.all(where+"residuaryqs").style.display = residuaryqs;
}

function showResid(what, where)
{
  if (where == null)
    where = "";
  var one, multi, mpercent;
  if (what == "one")
  {
    one = "block";
    multi = "none";
    mpercent = "none";
  }
  else if (what == "allequal")
  {
    one = "none";
    multi = "block";
    mpercent = "none";
  }
  else if (what == "allpercent")
  {
    one = "none";
    multi = "block";
    mpercent = "block";
  }
  for (var i = 1; i < 3; i++)
    document.all(where+"one"+i).style.display = one;
  for (i = 1; i < 4; i++)
    document.all(where+"cmulti"+i).style.display = multi;
  for (i = 1; i < 4; i++)
    document.all(where+"mpercent"+i).style.display = mpercent;
    
  if (document.MyForm.ismarried.value == "No" || document.MyForm.ismarried.value == "Yes" && where == "w")
  {
    if (document.MyForm.kidsyorn.value == "No")
      document.all("submitty").style.display = "block";
    else
      document.all("haskids").style.display = "block";
  }
  else
  {
    document.all("wifeqs").style.display = "block";
  }
}

function showKidsGifts(what, where)
{
  var v = (what == "Yes" ? "block" : "none");
  if (where == 1)
  {
    document.all("kgq").style.display = v;
    if (what == "No")
      document.all("submitty").style.display = "block";
    else
      document.all("submitty").style.display = "none";
  }
  else if (what == "Yes")
  {
    document.all("submitty").style.display = "none";
    document.all("kidshavegifts").style.display = "block";
    var nk = parseInt(document.MyForm.numkids.value);
    for (var i = 1; i <= nk; i++)
    {
      document.all("kgk" + i).style.display = "block";
      document.all("kgkn" + i).innerText = document.MyForm("childname" + i).value;
    }
  }
  else
  {
    document.all("kidshavegifts").style.display = "none";
    document.all("submitty").style.display = "block";
  }
}

function kidscustodian(what, where)
{
  document.all("kgc" + where).style.display = (what == "Yes" ? "block" : "none");
}

function checkNum(what)
{
  var v = parseInt(what.value);
  if (isNaN(v))
  {
    alert("Please enter an integer value");
    what.focus();
  }
}

function doneKidsGifts()
{
  var mb = new Array();
  var mc = new Array();
  for (var i = 1; i <= 10; i++)
  {
    if (document.MyForm("khg" + i).value == "Yes" && document.MyForm("custodian" + i).value != "")
    {
      mb[mb.length] = document.MyForm("childname" + i).value;
      mc[mc.length] = document.MyForm("custodian" + i).value;
    }
    else if (document.MyForm("khg" + i).value == "Yes" && document.MyForm("custodian" + i).value == "")
    {
      document.MyForm("custodian" + i).focus();
      return;
    }
  }
  document.MyForm.numkidsgifts.value = mb.length;
  document.MyForm.minorbeneficiaries.innerText = mb.join("|");
  document.MyForm.custodians.innerText = mc.join("|");
  document.all("submitty").style.display = "block";
}

function doGifts(bob)
{
  window.open("popups/giftinput.cfm?type=" + bob, 'bigwindow', 'width=600,height=400,top=10,left=10,scrollbars=1,resizable=1,status=1');
}

var missingFields;
function checkIt(what)
{
  missingFields = new Array();
  try
  {
  	var els = what.elements;
  	for (i = 0; i < els.length; i++)
    {
  	 	el = els[i];
    	n = el.name.toLowerCase();
   	 	switch (el.tagName.toUpperCase())
      {
    	  case "INPUT":
     	  case "SELECT":
         if (el.type.toLowerCase() == "radio")
           v = getRadioValue(el.name);
         else
         	 v = el.value;
      	break;
      	case "TEXTAREA":
       	 v = el.innerText;
      	break;
   		}
   		if (v == "")
      {
        if(n == "ismarried" || n == "gcity" || n == "truststate" || n == "kidsyorn" || n == "suctrustsingormult" 
          || n == "successortrustee1" || n == "successoralt1" || n == "compyorn" || n == "beneficiarytype" 
          || n == "oneorcoresidbeny" || checkMarried(what.ismarried.value, n) || checkKids(what.kidsyorn.value, n)
          || checkSuc(what.suctrustsingormult.value, n) || checkBeny("", getRadioValue("beneficiarytype"), n)
          || checkResBen("", getRadioValue("oneorcoresidbeny"), n) )
        {
        	missingFields[missingFields.length] = n;
     		}
    	}
    }
  	if (missingFields.length > 0)
    {
		  window.open('popups/trusts/missing_information.cfm','missinginfo','width=600,height=500,scrollbars=1,resizable=1,status=1');
     	return false;
  	}
    else
    {
  		return true;
  	}
	}  // close try
 	catch(e)
  {
    alert(e.message + " : " + n);
    return false;
  }
}

function checkMarried(what, n)
{
  if (what == "Yes")
  {
    if (n == "husbandname" || n == "wifename" || n == "wbeneficiarytype" || n == "woneorcoresidbeny"
      || checkBeny("w", getRadioValue("wbeneficiarytype"), n) || checkResBen("w", getRadioValue("oneorcoresidbeny"), n))
      return true;
  }
  else
  {
    if (n == "trustname")
      return true;
  }
  return false;
}

function checkKids(what, n)
{
  if (what == "Yes")
  {
    if (n == "numkids")
      return true;
    var p = parseInt(document.MyForm.numkids.value)
    for (var i = 1; i <= p; i++)
      if (n == "childname" + i)
        return true;
  }
  return false;
}

function checkSuc(what, n)
{
  if (n == "successortrustee1" || n == "successoralt1" || n == "compyorn")
    return true;
  if (what == "multi")
  {
    if (n == "successortrustee2" || n == "successoralt2" || n == "successortrustindyorn")
      return true;
  }
  return false;
}

function checkBeny(where, what, n)
{
  if (what == "onebenygetsall")
  {
    if (n == where + "solebeneficiary1" || document.MyForm.ismarried.value == "No" && n == "altsolebeneficiary1")
      return true;
  }
  else if (what == "multieven" || what == "multipercent")
  {
    if (n == where + "solebeneficiary1" || n == where + "solebeneficiary2")
      return true;
    if (what == "multipercent")
    {
      if (n == where + "solepercent1" || n == where + "solepercent2")
        return true;
    }
    else
      if (n == where + "issueorothers")
        return true;
  }
  return false;
}

function checkResBen(where, what, n)
{
  if (what == "one")
  {
    if (n == where + "soleresiduary1" || n == where + "soleresidalt1")
      return true;
  }
  else if (what == "allequal" || what == "allpercent")
  {
    if (n == where + "coresiduary1" || n == where + "coresiduary2")
      return true;
    if (what == "allpercent")
      if (n == where + "residpercent1" || n == where + "residpercent2")
        return true;
  }
  return false;
}

function getRadioValue(what)
{
  var els = document.getElementsByName(what);
  for (var i = 0; i < els.length; i++)
    if (els[i].checked)
      return els[i].value;
  return "";
}

function dosubmit()
{
  if (checkIt(document.MyForm))
    document.MyForm.submit();
}