var ct= "epoareg";
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;
var relativeCount = getFormObject(ct, 'rCount').value;

function divdisplay()
{
   displayHintDiv();
   chkGovernLaw()
   chkRelatives();
   ep2Title();
   chkAttorney();
   chkRel();
   chkPOA();

   chkFee();
   chkCorrespondence();
}

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');
	setVisDisp('NIdonorDiffAddr', getFormObject(ct, 'governLaw').value == 'Northern Ireland');
	setVisDisp('nonNIotherPOAdiv', getFormObject(ct, 'governLaw').value != 'Northern Ireland');
	setVisDisp('nonNIfeesDiv', getFormObject(ct, 'governLaw').value != 'Northern Ireland');
	setVisDisp('nonNIadditionalInfoDiv', getFormObject(ct, 'governLaw').value != 'Northern Ireland');
	chkDonorDiffAddr();
}

function chkDonorDiffAddr()
{
	setVisDisp('epoaAddrDiv', getFormObject(ct, 'donorDiffAddr')[0].checked);
}

function chkRelatives()
{
	chkSpouse();

	relativeCount = relativeCount + parseInt(document.getElementById("numOfChildren").value);

	//alert("children "+relativeCount);

	setVisDisp("parentsDiv", relativeCount < 3);


	if (getVisDisp("parentsDiv"))
		relativeCount = relativeCount + parseInt(document.getElementById("numOfParents").value);

		//alert("parents "+relativeCount);

	setVisDisp("siblingsDiv", relativeCount < 3);

	if (getVisDisp("siblingsDiv"))
		relativeCount = relativeCount + parseInt(document.getElementById("numOfSiblings").value);

		//alert("childrenInLaw "+relativeCount);

	setVisDisp("childrenInLawDiv", relativeCount < 3);

	if (getVisDisp("childrenInLawDiv"))
		relativeCount = relativeCount + parseInt(document.getElementById("numOfChildrenInLaw").value);

		//alert("grandchildren "+relativeCount);

	setVisDisp("grandchildrenDiv", relativeCount < 3);

	if (getVisDisp("grandchildrenDiv"))
		relativeCount = relativeCount + parseInt(document.getElementById("numOfGrandchildren").value);

		//alert("NN "+relativeCount);

	setVisDisp("nephewNieceDiv", relativeCount < 3);

	if (getVisDisp("nephewNieceDiv"))
		relativeCount = relativeCount + parseInt(document.getElementById("numOfNephewNiece").value);

		//alert("auntUncle "+relativeCount);

	setVisDisp("auntUncleDiv", relativeCount < 3);

	if (getVisDisp("auntUncleDiv"))
		relativeCount = relativeCount + parseInt(document.getElementById("numOfAuntUncle").value);

		//alert("cousin"+relativeCount);

	setVisDisp("cousinsDiv", relativeCount < 3);

	if (getVisDisp("cousinsDiv"))
		relativeCount = relativeCount + parseInt(document.getElementById("numOfCousins").value);


	if (getVisDisp("childrenDiv"))
		chkChildren();

	if (getVisDisp("parentsDiv") || getVisDisp("parent1Div"))
		chkParents();

	if (getVisDisp("siblingsDiv") || getVisDisp("sibling1Div"))
		chkSiblings();

	if (getVisDisp("childrenInLawDiv") || getVisDisp("childInLaw1Div"))
		chkChildrenInLaw();

	if (getVisDisp("grandchildrenDiv") || getVisDisp("grandchild1Div"))
		chkGrandchildren();

	if (getVisDisp("nephewNieceDiv") || getVisDisp("nephewNiece1Div"))
		chkNephewNiece();

	if (getVisDisp("auntUncleDiv") || getVisDisp("auntUncle1Div"))
		chkAuntUncle();

	if (getVisDisp("cousinsDiv") || getVisDisp("cousin1Div"))
  	chkCousins();

  getFormObject(ct, 'rCount').value = relativeCount;
}


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 chkSpouse()
{
	setVisDisp("spouseDiv",getFormObject(ct, 'competentSpouse')[0].checked);
	setVisDisp("relationsDiv",getFormObject(ct, 'competentSpouse')[0].checked);

	if (getFormObject(ct, 'competentSpouse')[0].checked)
		relativeCount = 1;

	else
		relativeCount = 0;
}

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()
{
	if (getFormObject(ct, 'attorneyNum').value == '1')
	{
		setVisDisp('attorneyDiv1', true);
		setVisDisp('attorneyDiv2', false);
		setVisDisp('attorneyDiv3', false);

		setVisDisp("attorneyOtherTitleDivA1", getFormObject(ct, 'attorneyTitle1').value == 'other');
		setVisDisp("attorneyOtherTitleDivB1", getFormObject(ct, 'attorneyTitle1').value == 'other');
		setVisDisp("attorneyOtherTitleDivA2", false);
		setVisDisp("attorneyOtherTitleDivB2", false);
		setVisDisp("attorneyOtherTitleDivA3", false);
		setVisDisp("attorneyOtherTitleDivB3", false);

		setVisDisp("attorneyDecisionDiv",false);
		
		setVisDisp("att2CorrDiv",false);
		setVisDisp("att3CorrDiv",false);
	}

	else if (getFormObject(ct, 'attorneyNum').value == '2')
	{
		setVisDisp('attorneyDiv1', true);
		setVisDisp('attorneyDiv2', true);
		setVisDisp('attorneyDiv3', false);

		setVisDisp("attorneyOtherTitleDivA1", getFormObject(ct, 'attorneyTitle1').value == 'other');
		setVisDisp("attorneyOtherTitleDivB1", getFormObject(ct, 'attorneyTitle1').value == 'other');
		setVisDisp("attorneyOtherTitleDivA2", getFormObject(ct, 'attorneyTitle2').value == 'other');
		setVisDisp("attorneyOtherTitleDivB2", getFormObject(ct, 'attorneyTitle2').value == 'other');
		setVisDisp("attorneyOtherTitleDivA3", false);
		setVisDisp("attorneyOtherTitleDivB3", false);

		setVisDisp("attorneyDecisionDiv",true);

		if (getFormObject(ct, 'attorneyRelationship')[1].checked)
			chkParticipation();
			
		setVisDisp("att2CorrDiv",true);
		setVisDisp("att3CorrDiv",false);
	}

	else
	{
		setVisDisp('attorneyDiv1', true);
		setVisDisp('attorneyDiv2', true);
		setVisDisp('attorneyDiv3', true);

		setVisDisp("attorneyOtherTitleDivA1", getFormObject(ct, 'attorneyTitle1').value == 'other');
		setVisDisp("attorneyOtherTitleDivB1", getFormObject(ct, 'attorneyTitle1').value == 'other');
		setVisDisp("attorneyOtherTitleDivA2", getFormObject(ct, 'attorneyTitle2').value == 'other');
		setVisDisp("attorneyOtherTitleDivB2", getFormObject(ct, 'attorneyTitle2').value == 'other');
		setVisDisp("attorneyOtherTitleDivA3", getFormObject(ct, 'attorneyTitle3').value == 'other');
		setVisDisp("attorneyOtherTitleDivB3", getFormObject(ct, 'attorneyTitle3').value == 'other');

		setVisDisp("attorneyDecisionDiv",true);


		if (getFormObject(ct, 'attorneyRelationship')[1].checked)
			chkParticipation();
			
		setVisDisp("att2CorrDiv",true);
		setVisDisp("att3CorrDiv",true);
	}



}

function chkRel()
{
	if (getFormObject(ct, 'attorneyNum').value == '1')
	{
		setVisDisp("otherRelDiv1", getFormObject(ct, 'attorneyRel1').value == 'otherRel');
		setVisDisp("otherProDiv1", getFormObject(ct, 'attorneyRel1').value == 'otherPro');
		setVisDisp("otherRelDiv2", false);
		setVisDisp("otherRelDiv3", false);
		setVisDisp("otherProDiv2", false);
		setVisDisp("otherProDiv3", false);
	}

	else if (getFormObject(ct, 'attorneyNum').value == '2')
	{
		setVisDisp("otherRelDiv1", getFormObject(ct, 'attorneyRel1').value == 'otherRel');
		setVisDisp("otherProDiv1", getFormObject(ct, 'attorneyRel1').value == 'otherPro');
		setVisDisp("otherRelDiv2", getFormObject(ct, 'attorneyRel2').value == 'otherRel');
		setVisDisp("otherProDiv2", getFormObject(ct, 'attorneyRel2').value == 'otherPro');
		setVisDisp("otherRelDiv3", false);
		setVisDisp("otherProDiv3", false);
	}

	else
	{
		setVisDisp("otherRelDiv1", getFormObject(ct, 'attorneyRel1').value == 'otherRel');
		setVisDisp("otherProDiv1", getFormObject(ct, 'attorneyRel1').value == 'otherPro');
		setVisDisp("otherRelDiv2", getFormObject(ct, 'attorneyRel2').value == 'otherRel');
		setVisDisp("otherProDiv2", getFormObject(ct, 'attorneyRel2').value == 'otherPro');
		setVisDisp("otherRelDiv3", getFormObject(ct, 'attorneyRel3').value == 'otherRel');
		setVisDisp("otherProDiv3", getFormObject(ct, 'attorneyRel3').value == 'otherPro');
	}

}

function chkParticipation()
{
	if (getFormObject(ct, 'attorneyNum').value == '2')
	{
		//setVisDisp("participationDiv2", getFormObject(ct, 'attorneyRelationship')[1].checked);
		setVisDisp("participatingHintDiv2", getFormObject(ct, 'attorneyRelationship')[0].checked && getFormObject(ct, 'attorneyParticipation2')[1].checked);
		//setVisDisp("participationDiv3", false);
		setVisDisp("participatingHintDiv3", false);

		setVisDisp("attorneyRegistrationDiv2", getFormObject(ct, 'attorneyRelationship')[1].checked && getFormObject(ct, 'attorneyParticipation2')[1].checked);
		setVisDisp("attorneyRegistrationDiv3", false);

		//setVisDisp("attorneyNotifiedDiv2", getFormObject(ct, 'attorneyParticipation2')[1].checked);
		//setVisDisp("yesNotificationDiv2", getFormObject(ct, 'attorneyParticipation2')[1].checked && getFormObject(ct, 'attorneyNotification2')[0].checked);
		//setVisDisp("attorneyNotifiedDiv3", false);
		//setVisDisp("yesNotificationDiv3", false);
	}

	else if (getFormObject(ct, 'attorneyNum').value == '3')
	{
		//setVisDisp("participationDiv2", getFormObject(ct, 'attorneyRelationship')[1].checked);
		//setVisDisp("participationDiv3", getFormObject(ct, 'attorneyRelationship')[1].checked);

		setVisDisp("participatingHintDiv2", getFormObject(ct, 'attorneyRelationship')[0].checked && getFormObject(ct, 'attorneyParticipation2')[1].checked);
		setVisDisp("participatingHintDiv3", getFormObject(ct, 'attorneyRelationship')[0].checked && getFormObject(ct, 'attorneyParticipation3')[1].checked);

		setVisDisp("attorneyRegistrationDiv2", getFormObject(ct, 'attorneyRelationship')[1].checked && getFormObject(ct, 'attorneyParticipation2')[1].checked);
		setVisDisp("attorneyRegistrationDiv3", getFormObject(ct, 'attorneyRelationship')[1].checked && getFormObject(ct, 'attorneyParticipation3')[1].checked);


		//setVisDisp("attorneyNotifiedDiv2", getFormObject(ct, 'attorneyParticipation2')[1].checked);
		//setVisDisp("yesNotificationDiv2", getFormObject(ct, 'attorneyParticipation2')[1].checked && getFormObject(ct, 'attorneyNotification2')[0].checked);
		//setVisDisp("attorneyNotifiedDiv3", getFormObject(ct, 'attorneyParticipation3')[1].checked);
		//setVisDisp("yesNotificationDiv3", getFormObject(ct, 'attorneyParticipation3')[1].checked && getFormObject(ct, 'attorneyNotification3')[0].checked);

	}
}


function chkPOA()
{
	setVisDisp("poaDetailsDiv", getFormObject(ct, 'otherPOA')[0].checked);
}

/*function chkNotify()
{
	setVisDisp("notifiedByOtherDiv", getFormObject(ct, 'notifiedByOther')[0].checked);
}*/

function chkFee()
{
	setVisDisp("postponementDiv", getFormObject(ct, 'encloseCheck')[1].checked);
	setVisDisp("yesPostponementDiv", getFormObject(ct, 'encloseCheck')[1].checked && getFormObject(ct, 'postponement')[0].checked );

}

function chkCorrespondence()
{
	//setVisDisp("sendToDiv", getFormObject(ct, 'correspondence')[1].checked);
	setVisDisp("otherCorrespondenceDiv", getFormObject(ct, 'correspondence')[3].checked);
	setVisDisp("otherCorresTitleDiv1", getFormObject(ct, 'otherCorresTitle').value == 'other');
	setVisDisp("otherCorresTitleDiv2", getFormObject(ct, 'otherCorresTitle').value == 'other');
}

