var ct= "lasting-power-of-attorney-registration";
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;
var relativeCount = getFormObject(ct, 'rCount').value;


function divdisplay()
{
   displayHintDiv();
   chkGovernLaw()
   ep2Title();
   chkAttorney();
   chkRel();
   chkPOA();
   notifyDisplay();
   chkCorrespondence();
   noticeSigningDateDisplay();
   lparegApplyDisplay()
   donorSpecifiedDisplay();
   exemptionDisplay();
   trustCorpDisplay();
}

function onlyNumeric(event)
{
   if(isIE)
      iKeyCode = event.keyCode;

   else
      iKeyCode = event.which;

   if( (iKeyCode >= 32 && iKeyCode <= 43) || (iKeyCode == 45 || iKeyCode == 47) || iKeyCode >= 58)
         return false;

   return true;
}

function displayHintDiv() {
	setVisDisp("hintDiv", getFormObject(ct,"hintDisplay").checked);
}


function chkGovernLaw()
{
	setVisDisp("northernIrelandFeeHint", getFormObject(ct, 'governLaw').value == 'Northern Ireland');
	setVisDisp("otherFeeHint", getFormObject(ct, 'governLaw').value == 'England' || getFormObject(ct, 'governLaw').value == 'Wales');
}


function chkRelations()
{
	if (getFormObject(ct, 'competentSpouse')[0].checked || getFormObject(ct, 'numOfChildren').value != '0' || getFormObject(ct, 'numOfParents').value != '0' ||
			getFormObject(ct, 'numOfSiblings').value != '0' || getFormObject(ct, 'numOfChildrenInLaw').value != '0' || getFormObject(ct, 'numOfGrandchildren').value != '0' ||
			getFormObject(ct, 'numOfNephewNiece').value != '0' || getFormObject(ct, 'numOfAuntUncle').value != '0' || getFormObject(ct, 'numOfCousins').value != '0')

		setVisDisp("relationsDiv", true);

	else
		setVisDisp("relationsDiv", false);
}



function chkChildren()
{
	chkRelations();

		 for(i=1;i<=8;i++)
		 {
				if(i <= document.getElementById("numOfChildren").value)
				{
					setVisDisp("child"+i+"Div",true);
				}

				else
					 setVisDisp('child'+i+"Div",false);
			}

}

function chkParents()
{
	chkRelations();



		 for(i=1;i<=2;i++)
		 {
				if(i <= document.getElementById("numOfParents").value)
					 setVisDisp("parent"+i+"Div",true);

				else
					 setVisDisp('parent'+i+"Div",false);
			}
}


function chkSiblings()
{
	chkRelations();

   for(i=1;i<=8;i++)
   {
      if(i <= document.getElementById("numOfSiblings").value)
         setVisDisp("sibling"+i+"Div",true);

      else
         setVisDisp('sibling'+i+"Div",false);
    }
}

function chkChildrenInLaw()
{
	chkRelations();

   for(i=1;i<=4;i++)
   {
      if(i <= document.getElementById("numOfChildrenInLaw").value)
         setVisDisp("childInLaw"+i+"Div",true);

      else
         setVisDisp('childInLaw'+i+"Div",false);
    }
}


function chkGrandchildren()
{
	chkRelations();

   for(i=1;i<=10;i++)
   {
      if(i <= document.getElementById("numOfGrandchildren").value)
         setVisDisp("grandchild"+i+"Div",true);

      else
         setVisDisp('grandchild'+i+"Div",false);
    }
}


function chkNephewNiece()
{
	chkRelations();

   for(i=1;i<=10;i++)
   {
      if(i <= document.getElementById("numOfNephewNiece").value)
         setVisDisp("nephewNiece"+i+"Div",true);

      else
         setVisDisp('nephewNiece'+i+"Div",false);
    }
}


function chkAuntUncle()
{
	chkRelations();

   for(i=1;i<=8;i++)
   {
      if(i <= document.getElementById("numOfAuntUncle").value)
         setVisDisp("auntUncle"+i+"Div",true);

      else
         setVisDisp('auntUncle'+i+"Div",false);
    }
}


function chkCousins()
{
	chkRelations();

   for(i=1;i<=10;i++)
   {
      if(i <= document.getElementById("numOfCousins").value)
         setVisDisp("cousin"+i+"Div",true);

      else
         setVisDisp('cousin'+i+"Div",false);
    }
}


function ep2Title()
{
	setVisDisp("testrOtherTitleDiv1", getFormObject(ct, 'testrTitle').value == 'other');
	setVisDisp("testrOtherTitleDiv2", getFormObject(ct, 'testrTitle').value == 'other');

}

function chkAttorney()
{
	var attNum = getFormObject(ct, 'attorneyNum').value;
	for (i=1; i<=4; i++)
	{
		setVisDisp('attorneyDiv'+i, attNum>=i);
		setVisDisp('attorneyOtherTitleDivA'+i, getFormObject(ct, 'attorneyTitle'+i).value == 'other');
		setVisDisp('attorneyOtherTitleDivB'+i, getFormObject(ct, 'attorneyTitle'+i).value == 'other');
	}
	
	setVisDisp('attorneyDecisionDiv',attNum>1);
}

function chkRel()
{
	for (i=1;i<=4;i++)
	{
		setVisDisp('otherRelDiv'+i, getFormObject(ct, 'attorneyRel'+i).value == 'otherRel' && getFormObject(ct, 'attorneyNum').value >= i);
		setVisDisp('otherProDiv'+i, getFormObject(ct, 'attorneyRel'+i).value == 'otherPro' && getFormObject(ct, 'attorneyNum').value >= i);
	}
}



function chkPOA()
{
	setVisDisp("poaDetailsDiv", getFormObject(ct, 'otherPOA')[0].checked);
}

function notifyDisplay()
{
	for (i=1;i<=5;i++)
		setVisDisp('notify'+i+'Div', getFormObject(ct, 'notifiedNum').value >= i);
}


function chkCorrespondence()
{
	setVisDisp("otherCorrespondenceDiv", getFormObject(ct, 'correspondence').value == 'other');
	setVisDisp("otherCorresTitleDiv1", getFormObject(ct, 'otherCorresTitle').value == 'other');
	setVisDisp("otherCorresTitleDiv2", getFormObject(ct, 'otherCorresTitle').value == 'other');
}

function noticeSigningDateDisplay()
{
	setVisDisp('noticeSpecificSign', getFormObject(ct, 'noticeSigningDate').value == 'specified');
}

function lparegApplyDisplay()
{
	for (i=1;i<=4;i++)
		setVisDisp('participationDiv'+i, getFormObject(ct, 'lparegApply')[1].checked);

	togetherWarningDisplay();
}

function donorSpecifiedDisplay()
{
	setVisDisp('notifiedPersonsDiv', getFormObject(ct, 'donorSpecified')[0].checked);
}

function exemptionDisplay()
{
	setVisDisp('exemptionForm', getFormObject(ct, 'remission')[0].checked || getFormObject(ct, 'exemption')[0].checked || getFormObject(ct, 'postponement')[0].checked);
}

function trustCorpDisplay()
{
	//setVisDisp('attorneyNumDiv', getFormObject(ct, 'trustCorp')[1].checked);
	setVisDisp('companyDiv', getFormObject(ct, 'trustCorp')[0].checked);
	//setVisDisp('attorneyDiv2', getFormObject(ct, 'trustCorp')[1].checked);
	//setVisDisp('attorneyDiv3', getFormObject(ct, 'trustCorp')[1].checked);
	//setVisDisp('attorneyDiv4', getFormObject(ct, 'trustCorp')[1].checked);
	//setVisDisp('participationDiv1', getFormObject(ct, 'trustCorp')[1].checked);
	//setVisDisp('attorneyDecisionDiv', getFormObject(ct, 'trustCorp')[1].checked);
	setVisDisp('attorneyCorrDiv', getFormObject(ct, 'trustCorp')[1].checked);
	setVisDisp('trustCorrDiv', getFormObject(ct, 'trustCorp')[0].checked);
	chkCorrespondence();
	//if (getFormObject(ct, 'trustCorp')[1].checked)
	//	chkAttorney();
}

function togetherWarningDisplay()
{
	for (i=1;i<=4;i++)
		setVisDisp('togetherWarning'+i+'Div', getFormObject(ct, 'lparegApply')[1].checked && getFormObject(ct, 'attorneyNum').value != 1 && getFormObject(ct, 'attorneyRelationship').value == 'joint' && getFormObject(ct, 'attorneyParticipation'+i)[1].checked);
}