	function confirm_and_delete_consumer_by_id( consumer_id ) {

		try {
			if ( !isNaN(consumer_id) ) {
				if ( confirm("Deleting a consumer will also delete all of that consumer's warranty claims.\n\nAre you sure you want to delete this consumer?") ) {
					redirect_to( '../consumers/consumer-delete.php?consumer_id=' + consumer_id );
				}
			}
			else {
				alert( 'Invalid consumer ID' );
			}
                }
                catch(e) {
                	alert( e.message );
                }

	}


	function confirm_and_delete_address_from_consumer_profile( address_id ) {
	
		try {
			if ( !isNaN(address_id) ) {
				if ( confirm('Are you sure you want to delete this address?') ) {
					redirect_to( '../consumers/consumer-address-delete.php?consumer_id=<[consumer_id]>&address_id=' + address_id );
				}
			}
			else {
				alert( 'invalid address id' );
			}
                }
                catch(e) {
                	alert( e.message );
                }


	}

        function show_claim_details_by_id( claim_id ) {

                try {
                        var request_obj = new BRIJ_Request();

                        request_obj.set_script_filename( './consumer-brij.php' );
                        request_obj.set_function_name('get_warranty_claim_details_by_id');
                        request_obj.add_parameter( claim_id );
                        request_obj.set_result_handler_name( 'show_claim_details_by_data' );

                        try {
                                var result = request_obj.get_function_result();
                        }
                        catch( e ) {
                        	alert( 'BRIJ error: ' + e.message );
                        }

			show_claim_transactions_by_id( claim_id );


                }
                catch(e) {
                	alert( e.message );
                }

        }

	function show_claim_details_by_data( data ) {
		
		try {
			if ( is_BRIJ_Error(data) ) {
				alert( data.get_error_message() );
			}
			else {
				if ( (data === false) || data === 0 ) {
					alert( 'Claim not found.' );
				}
				else {
					var address_key_found = false;
					var cur_key;
					var cur_obj;
					var cur_val;
					var parts_html = '';
					var return_reason_html = '';
					var j;

					show_profile_data_view( 'claim' );
					//dom_object_enable_display_by_id( 'div_claim_detail_container' );
					
					if ( typeof(data['warranty_claim_id']) != 'undefined' && (data['warranty_claim_id'] != null) ) {
						ACTIVE_CLAIM_ID = data['warranty_claim_id'];
					}
					else {
						alert( 'Error retrieving claim.' );
						return false;
					}

					for( cur_key in data) {
						parts_html = '';
						return_reason_html = '';

						cur_val = data[cur_key];

						if ( is_address_key(cur_key) ) {

							if ( cur_val ) {
								if ( !address_key_found ) {
									dom_object_enable_display_by_id('div_claim_detail_container_full_address');
									address_key_found = true;
								}
							}
						}

						if ( cur_key == 'parts_replaced' ) {
							
							if ( cur_val.length > 0 ) {
								for ( j = 0; j < cur_val.length; j++ ) {
									parts_html = parts_html + cur_val[j]['sunglass_part_name'] + ', ';
								}	
								cur_val = parts_html.substring( 0, parts_html.length - 2 );
							}
							else {
								cur_val = null;
							}
						}
						else if ( cur_key == 'return_reasons' ) {

							if ( cur_val.length > 0 ) {
								for ( j = 0; j < cur_val.length; j++ ) {
									return_reason_html = return_reason_html + cur_val[j]['return_reason_text'] + ', ';
								}	
								cur_val = return_reason_html.substring( 0, return_reason_html.length - 2 );
							}
							else {
								cur_val = null;
							}

						}
						else if ( cur_key == 'city_name' ) {
							if ( typeof(data['state_abbr']) != 'undefined' && data['state_abbr'] ) {
								if ( cur_val ) {
									cur_val = cur_val + ',&nbsp;';
								}
							}
						}
						else if ( cur_key == 'zip_code' ) {
							if ( cur_val ) {
								cur_val = '&nbsp;' + cur_val;
							}
						}
						else if ( cur_key == 'claim_awaiting_refund' ) {
							if ( cur_val ) {
								cur_val = 'Yes';
							}
							else {
								cur_val = 'No';
							}
						}
						else if ( cur_key == 'upc_included'  
								|| cur_key == 'claim_receipt_included' 
								|| cur_key == 'claim_upc_included' 
								|| cur_key == 'claim_upc_correct' 
								|| cur_key == 'claim_mfgr_defect' 
								|| cur_key == 'claim_pop_exempt' ) {

									// 
									// boolean values
									//
									if ( cur_val !== null ) {
										if ( parseInt(cur_val) == 1 ) {
											cur_val = 'Yes';
										}
										else {
											cur_val = 'No';
										}
									}							
						}
						else if ( cur_key == 'lens_type_name' ) {
							if ( cur_val != null ) {
								cur_val = '(Lens: ' + cur_val + ')';
							}
						}					
	
						if ( cur_obj = dom_get_object_by_id('div_claim_detail_' + cur_key) ) {
							if ( (cur_val !== null) ) {

								cur_val = cur_val.replace( /\n/g, '<br />' );

								dom_object_set_class_name( cur_obj, '' );
								dom_object_set_inner_html( cur_obj, cur_val );
							}
							else {
								if ( detail_key_ignore_if_null(cur_key) ) {
									dom_object_set_inner_html( cur_obj, '' );
								}
								else {
									dom_object_set_class_name( cur_obj, 'fadedText' );
									dom_object_set_inner_html( cur_obj, '(Not Specified)' );
								}
							}
						}					
					}

					if ( !address_key_found ) {
						dom_object_disable_display_by_id('div_claim_detail_container_full_address');
						dom_object_enable_display_by_id('div_claim_detail_container_no_address');

					}
					else {
						dom_object_disable_display_by_id('div_claim_detail_container_no_address');
					}

				}
			}

                }
                catch(e) {
                	alert( e.message );
                }

	}


        function show_claim_transactions_by_id( claim_id ) {

                try {

                        var request_obj = new BRIJ_Request();

                        request_obj.set_script_filename( '../warranty/warranty-brij.php' );
                        request_obj.set_function_name('brij_get_warranty_claim_transaction_array');
                        request_obj.add_parameter( claim_id );
                        request_obj.set_result_handler_name( 'apply_claim_transaction_list' );

                        try {
                                var result = request_obj.get_function_result();
                        }
                        catch( e ) {
                                alert( 'BRIJ error: ' + e.message );
                        }

                }
                catch(e) {
                        alert( e.message );
                }

        }

        function apply_claim_transaction_list( result ) {

                try {
			var j;
			var html = '';
			var status_name;

                        if ( is_BRIJ_Error(result) ) {
                                alert( result.get_error_message() );
                        }
                        else {
                                if ( result !== false ) {
					if ( typeof(result.length) != undefined && (result.length > 0) ) {
						html = '<table class="claim_txn_list">';

						for ( j = 0; j < result.length; j++ ) {
						
							status_name = result[j]['payment_status_type_name'];

							if ( status_name == 'Refunded' ) {
								status_name = 'Refund';
							}
	
							html = html + '<tr>';
							html = html + '<td>' + result[j]['txn_id_gateway'] + '</td>';
							html = html + '<td>(' + status_name + ')</td>';
							html = html + '</tr>';
				
						}
	
						html = html + '</table>';
					}
				}
			}

			dom_object_set_inner_html_by_id( 'div_claim_txn_container', html );

                }
                catch(e) {
                        alert( e.message );
                }

        }

	function detail_key_ignore_if_null( which_key ) {

		if ( is_item_info_string_key(which_key) || is_address_key(which_key) || which_key=='html_applied_claim_status_reason_names' 
			|| which_key == 'lens_type_name' ) {
			return true;
		}

		return 0;

	}

	function is_item_info_string_key( which_key ) {

		if ( which_key.indexOf('item_info_string') != -1 ) {
			return true;
		}

		return 0;

	}
		
	function is_address_key( which_key ) {

		if ( which_key == 'zip_code' || which_key == 'city_name' || which_key == 'state_abbr' 
			|| which_key == 'address_l1' || which_key == 'address_l2' || which_key == 'address_l3' ) {
				return true;
		}

		return false;

	}

	function check_consumer_zip_code_textbox( textbox_obj ) {

		try {


			if ( textbox_obj.value.length >= 5 ) {
				perform_consumer_zip_code_lookup(textbox_obj.value);
			}
			else {
				clear_consumer_city_name();
				unset_consumer_state_id();
			}

                }
                catch(e) {
                        alert( e.message );
                }

	}

	function perform_consumer_zip_code_lookup(zip_code) {

		try {

			var request_obj = new BRIJ_Request();

        		request_obj.set_script_filename( '../brij/brij-location.php' );
                	request_obj.set_function_name('brij_location_data_by_zip_code');
	                request_obj.set_result_handler_name( 'apply_consumer_zip_code_lookup_results' );

			request_obj.add_parameter( zip_code );

	        	try {
        	        	var result = request_obj.get_function_result();
						
	
			}	
	        	catch( e ) {
                		alert( 'BRIJ error: ' + e.message );
		        }

        		return result;

                }
                catch(e) {
                        alert( e.message );
                }


	}

	function apply_consumer_zip_code_lookup_results( result ) {

		try {
			if ( is_BRIJ_Error(result) ) {
				alert( 'BRIJ Error: ' + result.get_error_message() );
			}
			else {
				if ( (typeof(result) != 'undefined') && (result != null) ) {

					if ( typeof(result['city_name']) != 'undefined' ) {
						set_consumer_city_name( result['city_name'] );
					}
					else {
						clear_consumer_city_name();
					}

					if ( typeof(result['state_id']) != 'undefined' ) {
						set_consumer_state_by_id( result['state_id'] );
					}
					else {
						unset_consumer_state_id();
					}
				}
			}
                }
                catch(e) {
                        alert( e.message );
                }

	}

	function set_consumer_city_name( city_name ) {

		try {

			var form = get_active_form();
			var city_name_input = get_city_name_input();

			if ( city_name_input ) {
				city_name_input.value = city_name;
			}

                }
                catch(e) {
                        alert( e.message );
                }


	}

	function get_city_name_input() {

		try {

			var form = get_active_form();

			if ( typeof(form.consumer_city_name) != 'undefined' ) {
				return form.consumer_city_name;
			}
			else if ( typeof(form.city_name) != 'undefined' ) {
				return form.city_name;
			}

			return null;

                }
                catch(e) {
                        alert( e.message );
                }

	}

	function clear_consumer_city_name() {

		try {

			var form = get_active_form();
			var city_name_input = get_city_name_input();
	
			city_name_input.value = '';
                }
                catch(e) {
                        alert( e.message );
                }


	}

	function set_consumer_state_by_id( state_id ) {

		try {
			 dropdown_select_item_by_option_value( 'dropdown_consumer_state_id', state_id );

                }
                catch(e) {
                        alert( e.message );
                }


	}

	function unset_consumer_state_id() {

		try {
			 dropdown_select_item_by_index( 'dropdown_consumer_state_id', 0 );

                }
                catch(e) {
                        alert( e.message );
                }


	}


        function show_order_details_by_id( order_id ) {

                try {
   						var request_obj = new BRIJ_Request();

                        request_obj.request_uri = 'http://www.nativeyewear.com/OrderDetailsByID/' + order_id
                        request_obj.set_result_handler_name( 'show_order_details_by_data' );
                        
                        try {
                                var result = request_obj.get_function_result();

                        }
                        catch( e ) {
                                alert( 'BRIJ error: ' + e.message );
                       }

                }
                catch(e) {
                	alert( e.message );
                }

        }

	function show_order_details_by_data( data, options ) {
		
		try {
			if ( is_BRIJ_Error(data) ) {
				alert( data.get_error_message() );
			}
			else {
				if ( (data === false) || data === 0 ) {
					alert( 'Order not found.' );
				}
				else {
					var txns_found = false;
					var address_key_found = false;
					var cur_key;
					var cur_obj;
					var cur_val;
					var parts_html = '';
					var return_reason_html = '';
					var j;

					var txn_list = document.getElementById('div_order_txn_list');
							
					if ( txn_list.hasChildNodes() ) {
						while ( txn_list.childNodes.length >= 1 ) {
							txn_list.removeChild( txn_list.firstChild );
						}
					}
					
							
					show_profile_data_view('order');
					//dom_object_enable_display_by_id( 'div_order_detail_container' );
					
					if ( typeof(data['order_id']) != 'undefined' && (data['order_id'] != null) ) {
						ACTIVE_ORDER_ID = data['order_id'];
					}
					else {
						alert( 'Error retrieving order.' );
						return false;
					}

					for( cur_key in data) {
						parts_html = '';
						return_reason_html = '';

						cur_val = data[cur_key];

						if ( cur_key == 'shipping_address_city_name' ) {
							cur_val = cur_val + ',&nbsp;';		
						}
						else if ( cur_key == 'shipping_address_state_abbr' ) {
							cur_val = cur_val + '&nbsp;';
						}
						else if ( cur_key == 'upc_included'  )
								 {

									// 
									// boolean values
									//
									if ( cur_val !== null ) {
										if ( parseInt(cur_val) == 1 ) {
											cur_val = 'Yes';
										}
										else {
											cur_val = 'No';
										}
									}							
						}
						else if ( cur_key == 'transactions' ) {
							
							var info_div;
							var refund_div;
							var clearer_div = document.createElement('div');
							var refund_img;
							
							for ( j = 0; j < cur_val.length; j++ ) {
							
								txns_found = true;
								info_div = document.createElement('div');
								refund_div = document.createElement('div');
							
								cur_txn = cur_val[j];
								
								info_div.style.cssFloat = 'left';
								
								info_div.innerHTML = 
									cur_txn['txn_id_gateway']
									+ ' - '
									+ cur_txn['payment_status_type_key'];

								txn_list.appendChild(info_div);
								
								if ( cur_txn['payment_status_type_key'] == 'paid' ) {
									
									refund_img = document.createElement('img');
									refund_div.style.cssFloat = 'left';
									
									refund_div.id = 'refund_link_' + cur_txn['txn_id_internal'];
									refund_div.innerHTML = '&nbsp;( <a onclick="if ( confirm(\'Refund this payment?\') ) { refund_order_transaction( ' + cur_txn['txn_id_internal'] + ' ); }" style="text-decoration:underline; cursor:pointer;">Refund</a> )';
									
									refund_img.id = 'img_refund_loading_' + cur_txn['txn_id_internal'];
									refund_img.style.visibility = 'hidden';
									refund_img.style.cssFloat='left';
									refund_img.style.display='block';
									refund_img.src = 'http://www.nativeyewear.com/images/common/lists/row-loading.gif';									

									txn_list.appendChild(refund_div);
									txn_list.appendChild(refund_img);				
								}

								clearer_div.className='clearer';
								txn_list.appendChild(clearer_div);
							}
							
							
							
							continue;
						}
	
						if ( cur_obj = dom_get_object_by_id('div_order_detail_' + cur_key) ) {
							if ( (cur_val !== null) ) {

								cur_val = cur_val.replace( /\n/g, '<br />' );

								dom_object_set_class_name( cur_obj, '' );
								dom_object_set_inner_html( cur_obj, cur_val );
							}
							else {
								if ( detail_key_ignore_if_null(cur_key) ) {
									dom_object_set_inner_html( cur_obj, '' );
								}
								else {
									dom_object_set_class_name( cur_obj, 'fadedText' );
									dom_object_set_inner_html( cur_obj, '(Not Specified)' );
								}
							}
						}					
					}

					if ( !address_key_found ) {
						dom_object_disable_display_by_id('div_order_detail_container_full_address');
						dom_object_enable_display_by_id('div_order_detail_container_no_address');

					}
					else {
						dom_object_disable_display_by_id('div_order_detail_container_no_address');
					}

					if ( !txns_found ) {
						txn_list.innerHTML = '[ None ]';
					}
				}
			}

                }
                catch(e) {
                	alert( e.message );
                }

	}




