// constants EXACTLY = 1 ; ABOUT = 2 ; BEFORE = 3 ; AFTER = 4 ; BETWEEN = 5 ; //IN = ; PRESENT = 8 ; DONT_KNOW = 9 ; /* these js arrays are populated from php */ var showDay = new Array(1, 16, 0 ); var showMonth = new Array(1, 2, 16, 0 ); var showYear = new Array(1, 12, 2, 3, 4, 5, 14, 16, 13, 0 ); var showBetweenYear = new Array(5, 0 ); var showCentury = new Array(15, 0 ); //added by paul.) 07/01/2011 var hideToDate = new Array(16, 0 ); var globalHiddenToDate=false; /* facade that makes the show/hiding simpler to understand arrays (from php) contain the rules to use lm (1 apr 2010) */ function change_date_option(field_name, drop) { //debugger; var option_id = drop.options[drop.selectedIndex].value; changeDMYOfDateField(option_id, field_name); //hide the TO date if required (to date must be enclosed in div id of 'property-connection-to-row') hideToDateFlag = determineDisplayFromRulesArray(option_id, hideToDate); showOrHideToDate(hideToDateFlag, field_name, option_id); //when the end date is set to present show private-address-row, in other cases, hide it if(field_name == 'end' && option_id == 8) { //show the private address row if(document.getElementById("private-address-row") != null) document.getElementById("private-address-row").style.display = ''; //alert("show private-address-row"); } else { //hide the private address row if(document.getElementById("private-address-row") != null) document.getElementById("private-address-row").style.display = 'none'; //alert("hide private-address-row"); } } function changeDMYOfDateField(option_id, field_name) { // check rules to see if day should be displayed for this option_id showDayFlag = determineDisplayFromRulesArray(option_id, showDay); // show or hide the day based on the rule showOrHideDay(showDayFlag, field_name); // repeat the above procedure for month showMonthFlag = determineDisplayFromRulesArray(option_id, showMonth); showOrHideMonth(showMonthFlag, field_name); // repeat the above procedure for year showYearFlag = determineDisplayFromRulesArray(option_id, showYear); showOrHideYear(showYearFlag, field_name); // repeat the above procedure for century - added by paul.O 07/01/2011 showCenturyFlag = determineDisplayFromRulesArray(option_id, showCentury); showOrHideCentury(showCenturyFlag, field_name); // repeat the above procedure for between year showBetweenYearFlag = determineDisplayFromRulesArray(option_id, showBetweenYear); showOrHideBetweenYear(showBetweenYearFlag, field_name); } function determineDisplayFromRulesArray(option_id,arrayToSearch) { var showFlag=false; for ( var i=0; i < arrayToSearch.length; ++i ){ if(arrayToSearch[i] == option_id) { showFlag=true; } } return showFlag; } function showOrHideDay(showDayFlag, field_name) { var idName = field_name + '-date-from-day'; showOrHideBasedOnFlag(showDayFlag, idName); } function showOrHideMonth(showMonthFlag, field_name) { var idName = field_name + '-date-from-month'; showOrHideBasedOnFlag(showMonthFlag, idName); } function showOrHideYear(showYearFlag, field_name) { var idName = field_name + '-date-from-year'; showOrHideBasedOnFlag(showYearFlag, idName); } function showOrHideCentury(showCenturyFlag, field_name) { //added by paul.O 07/01/2011 var idName = field_name + '-date-century'; showOrHideBasedOnFlag(showCenturyFlag, idName); } function showOrHideBasedOnFlag(flag, htmlElementId) { if(flag) { var ele = document.getElementById(htmlElementId); if(ele!=null) ele.style.display = ''; } else { var ele = document.getElementById(htmlElementId); if(ele!=null) ele.style.display = 'none'; } } function showOrHideBetweenYear(showMonthFlag, field_name) { if (showMonthFlag) { var ele = document.getElementById(field_name + '-date-to-year'); if(ele!=null) ele.style.display = 'inline'; //note this is inline } else { var ele = document.getElementById(field_name + '-date-to-year'); if(ele!=null) ele.style.display = 'none'; } } /* * call this to hide the day month and year of a certain date field - lm 6 apr 2010 */ function hideDMY(field_name_prefix) { var show = false; showOrHideDay(show, field_name_prefix); showOrHideMonth(show, field_name_prefix); showOrHideYear(show, field_name_prefix); showOrHideBetweenYear(show, field_name_prefix); if(document.getElementById("built-date-from-option") != null) showOrHideCentury(show, field_name_prefix); //added by paul.O 0/7/2011 - may need to remove!! } /* * call this to show the day month and year of a certain date field - lm 6 apr 2010 */ function showDMY(field_name_prefix) { var show = true; showOrHideDay(show, field_name_prefix); showOrHideMonth(show, field_name_prefix); showOrHideYear(show, field_name_prefix); //showOrHideBetweenYear(show, field_name_prefix); if(document.getElementById("built-date-from-option") != null) showOrHideCentury(show, field_name_prefix); //added by paul.O 0/7/2011 - may need to remove!! } // NB had to call this showYearField as when called it showYear it conflicted with the array name above function showYearField(field_name_prefix) { showOrHideYear(true, field_name_prefix); } /** * resets values of the date field to be blank (note does not change the option eg Dont know etc ... */ function resetDateFieldValues(field_name_prefix) { document.getElementById(field_name_prefix+'-date-from-year').value = ''; document.getElementById(field_name_prefix+'-date-from-month').value = ''; document.getElementById(field_name_prefix+'-date-from-day').value = ''; document.getElementById(field_name_prefix+'-date-century').value = ''; //added by paul.O 07/01/2011 - may need removing!! } /* * shows / hides to date as needed * field_name is the prefix */ function showOrHideToDate(hideToDate, field_name, option_id) { if(field_name=='end') // we only hide the TO date when FROM option = IN , if==end the TO option is being passed return; // check if this is part of the household flow (ie multilink_s_2 etc ... ) householdId = isHouseholdFlow( field_name ); if(field_name=='household_e' || field_name=='household_s') householdId = 'household_e'; // its on create_household_step1.php // this will be hidden when TO should always be hidden eg if on link // person to property and the option married here is selected - lm 26 aug2010 if(globalHiddenToDate==true) hideToDate=true; //alert('gloobal hide = ' + globalHiddenToDate); //debugger; if(householdId == 'household_e') // on create_household_step1.php { if (hideToDate) { var ele = document.getElementById('property-connection-to-row'); if(ele!=null){ ele.style.display = 'none'; resetToDontKnow('household_e'); } } else { var ele = document.getElementById('property-connection-to-row'); if(ele!=null) ele.style.display = ''; } } else if(householdId) { if(householdId==123456789) return; // dont nowt its on the to part dont need to do anything only from part triggers code below // navigate dom to get the next tr which is the to part of the from ,to date stuff houseSelect = document.getElementById('multilink_s_'+householdId+'-date-from-option'); a = houseSelect.parentNode; thetd = a.parentNode; thetr = thetd.parentNode; thetrto = thetr.nextSibling.nextSibling; if (hideToDate) { var ele = thetrto; if(ele!=null){ ele.style.display = 'none'; resetToDontKnow('multilink_e_'+householdId); } } else { var ele = thetrto; if(ele!=null) ele.style.display = ''; } } else { // normal date (not household ) if (hideToDate) { var ele = document.getElementById('property-connection-to-row'); if(ele!=null){ ele.style.display = 'none'; resetToDontKnow('end'); } } else { var ele = document.getElementById('property-connection-to-row'); if(ele!=null) ele.style.display = ''; } } } /* resets option and values of date field */ function resetToDontKnow(prefix) { var dontKnow = 9; resetDateFieldValues(prefix); changeDMYOfDateField(dontKnow, prefix); endSelect = document.getElementById(prefix+'-date-from-option'); endSelect.value = dontKnow; } //----------------------------------------------------------------------- // below here added 10 feb - louis for household stuff // an option is based in eg about , exactly etc .. // based on this show / hide relevant parts of the date component function showRelevantFields(selected_option, date_prefix, startDateBoolean, readFrom) { //-date-from-option //alert('hits here option = '+selected_option + ' pref = '+date_prefix ) ; optionValue = selected_option.options[selected_option.selectedIndex].value; if(optionValue != DONT_KNOW) // 9 = DONT KNOW { changeDMYOfDateField(optionValue, date_prefix) // change actual option also document.getElementById(''+date_prefix+'-date-from-option').selectedIndex = selected_option.selectedIndex; // set values from lead //debugger; if(startDateBoolean) { sprefix = 'start'; if(readFrom != '') sprefix = 'household_s'; startDay = document.getElementById(''+sprefix+'-date-from-day').value; document.getElementById(''+date_prefix+'-date-from-day').value = startDay; startMonth = document.getElementById(''+sprefix+'-date-from-month').value; document.getElementById(''+date_prefix+'-date-from-month').value = startMonth; startYear = document.getElementById(''+sprefix+'-date-from-year').value; startYearStr = ''+date_prefix+'-date-from-year'; document.getElementById(startYearStr).value = startYear; } else { // eprefix = 'end'; if(readFrom != '') eprefix = 'household_e'; document.getElementById(''+date_prefix+'-date-from-day').value = document.getElementById(''+eprefix+'-date-from-day').value; document.getElementById(''+date_prefix+'-date-from-month').value = document.getElementById(''+eprefix+'-date-from-month').value; document.getElementById(''+date_prefix+'-date-from-year').value = document.getElementById(''+eprefix+'-date-from-year').value; } } else { //alert('its DONT KNOW , = '+optionValue); } } // checks that multi link dates are ok, ie there is date/s in common with household dates //used in household stuff - lm 3 feb 2011 function validateHouseholdDatesOk() { //debugger; houseHoldStartDate = makeDateFrom('household_s',''); //alert('start='+houseHoldStartDate); houseHoldEndDate = makeDateFrom('household_e',''); //alert('end='+houseHoldEndDate); errorMsg=''; //alert('arr count = '+additionalPersons.length); for (i=0;i houseHoldEndDate) // bad errorMsg += '\n'+sdate.toDateString()+' start date after household end date '+houseHoldEndDate.toDateString(); if(sdate < houseHoldStartDate) // bad errorMsg += '\n'+sdate.toDateString()+' start date before household start date '+houseHoldStartDate.toDateString(); if(edate > houseHoldEndDate) // bad errorMsg += '\n'+edate.toDateString()+' end date after household end date '+houseHoldEndDate.toDateString(); } return errorMsg; } // used in household stuff - lm 3 feb 2011 function makeDateFrom(prefix, idPerson) { //alert('test '+prefix+ 'person = '+idPerson); prefix = prefix+''+idPerson; day = document.getElementById(prefix+'-date-from-day').value if(trim(day)=='') day=1; month = document.getElementById(prefix+'-date-from-month').value if(trim(month)=='') { month=0; } else { month = month-1; } year = document.getElementById(prefix+'-date-from-year').value linkDate = new Date(year, month, day); return linkDate; } // checks if we are looking at dates on the household flow (eg create_household_step4.php ) function isHouseholdFlow( prefix ) { //debugger; //alert(prefix); var pattern = /multilink_._(\d)+/; res = pattern.test(prefix); //alert('res = '+res); if(!res) { return false; // its not a match , were not on household stuff } var pattern = /multilink_e_(\d)+/; res = pattern.test(prefix); if(res) { return 123456789; // its on the to of household date already , so do nothing // pass back this to calling function to let it know what todo } pattern = /(\d)+/; // get the if part of the hosehouse multilink date arrayOfMatches = pattern.exec(prefix); if(arrayOfMatches.length>0){ //for(i = 0; i < arrayOfMatches.length; i++) { // alert('match = '+arrayOfMatches[i]); //} //alert('prefix to return = '+ arrayOfMatches[0]); return arrayOfMatches[0] ; // only want the first match , as they will be the most acurate match } return false; // if it gets here its not part of household flow (SHOULD NEVER GET TO THIS LINE ) }