// submit the form to the specified page function showPie(chl,chd,chc) { moneyTrackerPieChart = document.getElementById('moneyTrackerPieChart'); newChartSrc = '/dynamic_content_pages/calcs/graphs/get-chart.php?cht=p3&chs=548x180&chl=' + escape(chl) + '&chco=' + escape(chc) + '&chf=bg,s,fffaee&chd=t:' + escape(chd); //alert(newChartSrc) ; moneyTrackerPieChart.src = newChartSrc; } function goToPage( pageUrl, target ) { // the form object that will be used var form_object = document.getElementById('calcForm'); validation_success = validate_form( form_object ); if ( validation_success ) { form_object.action = pageUrl; if (target != null && new String(target) != '') form_object.target = target; else form_object.target = '_self'; if (form_object.elements['form_id']) { form_object.elements['form_id'].value = ''; form_object.elements['form_id'].name = 'not_form_id'; } form_object.submit(); } else { window.alert( 'Sorry, you did not complete the form correctly' ); } } function doDelete(pageUrl) { var dontShowDeleteDialog = $.cookie('dontShowDeleteDialog'); if (dontShowDeleteDialog == 'true') { goToPage(pageUrl); } else { $("#deleteDialog").show(); doDeletePageUrl = pageUrl; $("#deleteDialog").dialog('open'); } } function goToBudget() { var dontShowCopyDialog = $.cookie('dontShowCopyDialog'); if (dontShowCopyDialog == 'true') { goToPage('../budget/page1.php', '_blank'); } else { $("#dialog").show(); $("#dialog").dialog('open'); } // goToPage('../budget/page1.php', '_blank'); } function showHelp() { window.open('/dynamic_content_pages/calcs/money-tracker/csv-popup.php','helpPopup','status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,height=450,width=650'); } // required_elements contains the names of elements that have to be // filled in before the form can be submitted required_elements = new Array(); // check_format_elements contains the names and formats of elements // that have to be filled in with the correct format before // the form can be submitted check_format_elements = new Array(); // add an element to the required_elements array function add_required_element( element_name ) { required_elements[ required_elements.length ] = element_name; } // add an element to the check_format_elements array function add_check_format_element( element_name, element_format ) { element_to_format = new Array( element_name, element_format ) check_format_elements[ check_format_elements.length ] = element_to_format; } /** * returns true if all the required elements are filled in and all * the formated elements have the right format. otherwise returns false. */ function validate_form() { var form_is_valid = true; for ( i = 0; i < required_elements.length; i++ ) { elements = document.getElementsByName( required_elements[ i ] ); // there may be more than one element with the same name, // eg. radiobuttons // NOTE: not sure what the effect of a hidden variable with // the same name as a required/formatted element will have for ( j = 0; j < elements.length; j++ ) { //window.alert( elements[ j ].name + " - " + elements[ j ].type ); var valid = false; valid = validate_required_element( elements[ j ].name, elements[ j ].type ); if ( !valid ) { form_is_valid = false; } } } for ( i = 0; i < check_format_elements.length; i++ ) { var element_name; element_name = check_format_elements[ i ][ 0 ]; var element_format; element_format = check_format_elements[ i ][ 1 ]; elements = document.getElementsByName( element_name ); for ( j = 0; j < elements.length; j++ ) { //window.alert( elements[ j ].name + " - " + elements[ j ].type ); valid = validate_formatted_element( elements[ j ].name, elements[ j ].type, element_format ); if ( !valid ) { form_is_valid = false; } } } // TODO: remove //form_is_valid = false; return form_is_valid; } /** * returns true if the required element is filled in, false otherwise */ function validate_required_element() { // TODO: implement return true; } /** * returns true if the formatted element is filled in with the correct * format, false otherwise. * note: it will return true if the element * is not filled in at all. this is so that optional elements can be * tested for formatting. */ function validate_formatted_element() { // TODO: implement return true; } function saveResult() { goToPage( 'save-to-myplan.php' ); }