var parties=new Array();
var numParties=2;
var partySelOptions=new Array();


function initCapJS(inputStr){

var strArray=inputStr.split(" ");
var outputStr="";
var strVar="";

for (var i=0;i<strArray.length;i++) {
   strVar=strArray[i];
   if (strVar.indexOf('.') >=0 || strVar.indexOf('-') >=0) {
            
      outputStr=outputStr+strVar+' ';
   } else {
      outputStr=outputStr+strVar.substr(0,1).toUpperCase() + strVar.substr(1, strVar.length).toLowerCase()+' ';
   }
}

// remove last space from return string
outputStr=outputStr.substr(0, outputStr.length-1);
return outputStr;
}


function setNameSpan() { 
var aVar;

aVar=getFormObject('cohab', 'fullName1').value;
for (i=1;i<=3;i++) {
  getObject('party1NameSpan'+i).innerHTML=initCapJS(aVar); 
  }

aVar=getFormObject('cohab', 'fullName2').value;
   for (i=1;i<=3;i++) {
      getObject('party2NameSpan'+i).innerHTML=initCapJS(aVar);
      }

}  // end setNameSpan

// capitalizes first letter for each word in a string
function initCap(strVar) {
var temp=new Array();
var a,b;
temp=strVar.value.split(' ');
for (i=0;i<=temp.length-1;i++) {
   temp[i]=temp[i].charAt(0).toUpperCase() + temp[i].substr(1,temp[i].length).toLowerCase();
}

return temp.join(" ");

}

// displays corresponding number of text boxes for property and debt items
function numItemsChanged(numItems,pos,type) {
var on=false;
var maxItems=10;

   for(i=1;i<=maxItems;i++) {
       on=(i<= numItems);  
       setVisDisp("party"+pos+type+"TR"+i,on);     
   }

}

function setPartyNames() {
// set array of party names to first party's and second party's name

 parties[1]=getFormObject('cohab','fullName1').value;
       
 parties[2]=getFormObject('cohab','fullName2').value;
}

function setPartySelOptions() {
   var partyEntitledSel=getFormObject('cohab','partyEntitled');
   var selIndex=partyEntitledSel.selectedIndex;
   var count;
   for (count=1;count<=numParties;count++) {
      partyEntitledSel.options[count-1]=new Option(parties[count],parties[count]);
   }  
   partyEntitledSel.selectedIndex=selIndex;
}

function partyNameChanged() {
   setPartyNames();
   setPartySelOptions();
}

function numMiscClausesChanged(numClauses) {
var on=false;
var maxClauses=10;

   for (i=1;i<=maxClauses;i++) {
       on=(i<= numClauses);  
       setVisDisp("miscClause"+i,on);     
   }
}

function numMiscClausesDisplay() {
var selectObject=getFormObject('cohab', 'numMiscClauses');
numMiscClausesChanged(selectObject.value);

}

function estateRightsDisplay() {
var on=false;
var maxRights=6;
var numRights=getFormObject('cohab', 'numEstateRights').value;
for (i=1;i<=maxRights;i++) {
       on=(i<= numRights);  
       setVisDisp("estateRightTR"+i,on);     
   }
}


function numChildChanged(numChildren,pos,type) {
var on=false;
var maxChildren=5;

  for(i=1;i<=maxChildren;i++) {
  
   on=(i<=numChildren); 
   setVisDisp("child"+type+pos+"TR"+i,on);   

   }

}

function childDisplay() {
var selectObject=getFormObject('cohab', 'numChildPrev1');
numChildChanged(selectObject.value, 1, 'Prev');

selectObject=getFormObject('cohab', 'numChildPrev2');
numChildChanged(selectObject.value, 2, 'Prev');

selectObject=getFormObject('cohab', 'numChild');
numChildChanged(selectObject.value,'','');



}

function supportEntitledDisplay() {
   var supportType=getFormObject("cohab","supportEntitled");
   setVisDisp("oneSupport",supportType.value=="One");
   setVisDisp("otherSupport",supportType.value=="Other");
}

function hintDisplay() {
  if (getFormObject("cohab","hintDisplay").checked == true) {
      setVisDisp('hintDiv',true);
   } else {
      setVisDisp('hintDiv',false);
   }
}
 

function presPropertyDisplay() {

   var selectObject=getFormObject('cohab', 'presPropList');
   setVisDisp("presProperty", selectObject.value=="YesBelow");
   
 }

function sepPropertyDisplay() {
  var selectObject=getFormObject('cohab','sepPropList');
  setVisDisp("allPropTxt", selectObject.value=="All"); 
  setVisDisp("someProp", selectObject.value=="Some");
  setVisDisp("nonePropTxt", selectObject.value=="None");

}

function sharedPropertyDisplay() {
   var selectObject=getFormObject('cohab', 'sharedPropList');
   setVisDisp("sharedProperty", selectObject.value=="YesBelow");

}

function debtDisplay() {
   var selectObject=getFormObject('cohab','debtList');
   setVisDisp("presDebts", selectObject.value=="YesBelow");


}

function separateDebtsDisplay() {
var selectObject=getFormObject('cohab', 'sepDebts');
setVisDisp("allDebtsTxt", selectObject.value=="All");
setVisDisp("someDebtsTxt", selectObject.value=="Some");
setVisDisp("noneDebtsTxt", selectObject.value=="None");

}

function sharedDebtsDisplay() {
   var selectObject=getFormObject('cohab', 'sharedDebtsList');
   setVisDisp("sharedDebts", selectObject.value=="YesBelow");


}

function childPrevDisplay() {
  var selectObject=getFormObject('cohab', 'childPrevList');
  setVisDisp("childPrev", selectObject.value=="Yes");
}

function childrenDisplay() {
   var selectObject=getFormObject('cohab','childList');
   setVisDisp("children", selectObject.value=="Yes");

}

function supportEntitledDisplay(){
var supportEntitledType=getFormObject('cohab', 'supportEntitled');
setVisDisp("oneEntitledSupport", supportEntitledType.value=="One");
setVisDisp("otherEntitledSupport", supportEntitledType.value=="Other");
}


function rightsListDisplay() {
setVisDisp("estateRights", getFormObject('cohab','otherRights').checked);
}


function estateEntitledDisplay() {
var estateEntitledSel=getFormObject('cohab', 'estateEntitled');
setVisDisp("yesEntitledEstate", estateEntitledSel.value=="yes");
setVisDisp("otherEntitledEstate", estateEntitledSel.value=="other");

}

function supportTypeDisplay() {
  
setVisDisp("lumpSumSupportList", getFormObject('cohab',
        'lumpSumPaymentChk').checked);
setVisDisp("monthlyPaymentSupportList", getFormObject('cohab',
         'monthlyPaymentChk').checked);
setVisDisp('propertySupportList', getFormObject('cohab', 'propertySupportChk').checked);
setVisDisp('otherSupport', getFormObject('cohab', 'otherSupportChk').checked);


}

function monthlyPaymentDisplay() {
var monthlyPaymentType=getFormObject('cohab', 'monthlyPaymentSuppSel').value;
setVisDisp("fixedMonthlyPaymentDiv", monthlyPaymentType=="fixed");
setVisDisp("fixedMinPerMonthlyPaymentDiv", monthlyPaymentType=="fixedMinPer");
setVisDisp("otherMonthlyPaymentDiv", monthlyPaymentType=="other");

}

function lumpSumPaymentDisplay() {
var lumpSumPayment=getFormObject('cohab', 'lumpSumSuppSel').value;
setVisDisp("fixedAmtLumpSumDiv", lumpSumPayment=="fixed");
setVisDisp("fixedMinPerAmtLumpSumDiv", lumpSumPayment=="fixedMinPer");
setVisDisp("dependYrsLumpSumDiv", lumpSumPayment=="dependYrs");
setVisDisp("lumpSumOtherDiv", lumpSumPayment=="other");

}

function propertySupportDisplay(){
var input=getFormObject('cohab', 'propSuppSel');   
setVisDisp("noLengthPropertyDiv", input.value=="noLength");
setVisDisp("minPerPropertyDiv", input.value=="minPerTime");
setVisDisp("otherPropertyDiv", input.value=="other");

}

function fixedMonthlyLengthDisplay() {
setVisDisp("fixedMonthlyOther", getFormObject('cohab', 'fixedMonthlyLength').value=="other");
}

function fixedMinPerMonthlyLengthDisplay() {
setVisDisp("fixedMinPerMonthlyOther", getFormObject('cohab','fixedMinPerMonthlyLength').value=="other");
}

function otherSharedPropTxtDisplay() {
setVisDisp("otherSharedProp", getFormObject('cohab', 'sharedPropSep').value=="other");

}

function witnessDisplay() {
var input=getFormObject('cohab', 'numWitness');
setVisDisp("oneWitness", input.value=="1");
setVisDisp("twoWitnesses",input.value=="2");

}
function otherPropTxtDisplay() {
setVisDisp("otherPropShared", getFormObject('cohab', 'otherPropCheckBox').checked);
}

function otherSepDebtsDisplay() {
setVisDisp("otherSepDebts", getFormObject('cohab','otherDebtsCheckBox').checked);
}

function otherEventSepTxtDisplay() {
setVisDisp("otherEventSep", getFormObject('cohab','sharedDebtsSep').value=="other");

}

function setNonMarital() {
var needTheQuestion = (getFormObject('cohab', 'country').value==("USA"));
setVisDisp("nonMarital", needTheQuestion);
}

function numItemsDisplay() {
var numItems=getFormObject('cohab', 'numProp1');
numItemsChanged(numItems.value, 1,'Prop');

numItems=getFormObject('cohab', 'numProp2');
numItemsChanged(numItems.value, 2,'Prop');

numItems=getFormObject('cohab', 'numSharedProp');
numItemsChanged(numItems.value, 'S','Prop');

numItems=getFormObject('cohab', 'numDebts1');
numItemsChanged(numItems.value, 1,'Debts');

numItems=getFormObject('cohab', 'numDebts2');
numItemsChanged(numItems.value, 2,'Debts');

numItems=getFormObject('cohab', 'numSharedDebts');
numItemsChanged(numItems.value, 'S','Debts');
}

function sepDebtsDefDisplay(src) {
   src.title="Separate debts are debts that fall upon the responsibility of one party" +
            " and thus are not divided between the parties in the event of a breakup."+
            "  Responsibility for the payment of a separate debt will be solely on the" +
            " party who has either incurred the debt or has taken responsibility for" +
            " the debt.";
}

function sepDefDisplay(src) {


src.title="Separate property is property that will not be divided between " +
          " the parties in the event of a breakup.  In other words, there" +
          " will be no question as to the legal ownership of the property" +
          " or whether the other party has any entitlement to it.";

}

function sepDefHide(src) {

src.title="";
}

function divdisplay () {
   
   hintDisplay(); 
   partyNameChanged();
   supportEntitledDisplay();   
   presPropertyDisplay();
   sepPropertyDisplay();
   otherPropTxtDisplay(); 
   sharedPropertyDisplay();
   debtDisplay();
   separateDebtsDisplay();
   sharedDebtsDisplay();
   childPrevDisplay();
   childrenDisplay();
  
   numItemsDisplay(); 
   childDisplay();
   otherSharedPropTxtDisplay();
   otherSepDebtsDisplay(); 
   otherEventSepTxtDisplay(); 
   numMiscClausesDisplay();
   numItemsDisplay();
   supportTypeDisplay();
   lumpSumPaymentDisplay();
   monthlyPaymentDisplay();
   fixedMonthlyLengthDisplay();
   fixedMinPerMonthlyLengthDisplay();
   propertySupportDisplay();
   estateEntitledDisplay();
   rightsListDisplay();
   estateRightsDisplay();
   witnessDisplay();
   setNameSpan();
   setNonMarital();
   
}

    

