<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
    <div id="warning" class="warning"><?php echo $error_warning; ?></div>
  <?php } else { ?>
    <div id="warning"></div>
  <?php } ?>
  <?php if ($success) { ?>
    <div id="success" class="success"><?php echo $success; ?></div>
  <?php } else { ?>
    <div id="success"></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><?php echo $heading_title; ?></h1>
      <div class="buttons">
	    <a href="<?php echo $cancel; ?>" class="button"><span><?php echo $button_cancel; ?></span></a>
	  </div>
    </div>
    <div class="content">
		<form id="testcare_form">
			<div style="float: left; width: 100%;"><h2><?php echo $text_call_type; ?></h2></div>
			<div style="float: left; width: 98%; margin-top: 4px; margin-bottom: 15px; padding: 8px; border: 1px solid #CCC; box-shadow: 1px 0px 0px #EEE">
				<div style="float: left; width: 15%; font-weight: bold; font-size: 12px;"><?php echo $entry_existing_types; ?></div>
				<div style="float: left; width: 85%; font-weight: bold; font-size: 12px;">
					<select id="call_type" name="call_type" style="margin-right: 35px;">
						<option value=""></option>
						<?php foreach ($call_types as $call_type) { ?>
							<option value="<?php echo $call_type['table_id']; ?>"><?php echo $call_type['value']; ?> - <?php echo $call_type['dvalue']; ?></option>
						<?php } ?>
					</select>    <br/>
	           				<?php echo $entry_edit; ?><input type="checkbox" id="edit_type" name="edit_type" value="1" style="margin-left: 12px; margin-right: 12px;" />
					<?php echo $entry_delete; ?><input type="checkbox" id="del_type" name="del_type" value="1" style="margin-left: 12px; margin-right: 20px;" />
					<input type="text" id="edit_type_box" name="edit_type_box" value="" size="30" style="margin-right: 35px;" />  <br />
             Desc:  <textarea rows="3" id="edit_type_box2" name="edit_type_box2" cols="50" style="margin-right: 40px; vertical-align: middle;"></textarea>
            <a id="update_type" class="button"><span><?php echo $button_update; ?></span></a></div>
				<div style="float: left; width: 15%; margin-top: 15px; font-weight: bold; font-size: 12px;"><?php echo $entry_new_type; ?>
			   <input type="text" id="new_type" name="new_type" value="" size="30" />  <br />
               Desc:
               <textarea rows="3" id="new_type2" name="new_type2" cols="50" style="margin-right: 40px; vertical-align: middle;"></textarea>
		<a id="save_call_type" class="button"><span><?php echo $button_save; ?></span></a></div>
			</div>
			<div style="float: left; width: 100%;"><h2><?php echo $text_priority_code; ?></h2></div>
			<div style="float: left; width: 98%; margin-top: 4px; margin-bottom: 15px; padding: 8px; border: 1px solid #CCC; box-shadow: 1px 0px 0px #EEE">
				<div style="float: left; width: 15%; font-weight: bold; font-size: 12px;"><?php echo $entry_existing_codes; ?></div>
				<div style="float: left; width: 85%; font-weight: bold; font-size: 12px;">
					<select id="priority_code" name="priority_code" style="margin-right: 35px;">
						<option value=""></option>
						<?php foreach ($priority_codes as $priority_code) { ?>
							<option value="<?php echo $priority_code['table_id']; ?>"><?php echo $priority_code['value']; ?></option>
						<?php } ?>
					</select>
					<?php echo $entry_edit; ?><input type="checkbox" id="edit_code" name="edit_code" value="1" style="margin-left: 12px; margin-right: 12px;" />
					<?php echo $entry_delete; ?><input type="checkbox" id="del_code" name="del_code" value="1" style="margin-right: 20px;" />
					<input type="text" id="edit_code_box" name="edit_code_box" value="" size="30" style="margin-left: 12px; margin-right: 35px;" />
                      Desc:  <textarea rows="3" id="edit_code_box2" name="edit_code_box2" cols="50" style="margin-right: 40px; vertical-align: middle;"></textarea>
					<a id="update_code" class="button"><span><?php echo $button_update; ?></span></a>
				</div>
				<div style="float: left; width: 15%; margin-top: 15px; font-weight: bold; font-size: 12px;"><?php echo $entry_new_code; ?></div>
				<div style="float: left; width: 20%; margin-top: 15px;"><input type="text" id="new_code" name="new_code" value="" size="30" />

                 <br />
               Desc:
               <textarea rows="3" id="new_code2" name="new_code2" cols="50" style="margin-right: 40px; vertical-align: middle;"></textarea>

                </div>
				<div style="float: left; width: 65%; margin-top: 15px;"><a id="save_priority_code" class="button"><span><?php echo $button_save; ?></span></a></div>
			</div>
			<div style="float: left; width: 100%;"><h2><?php echo $text_problem_type; ?></h2></div>
			<div style="float: left; width: 98%; margin-top: 4px; margin-bottom: 15px; padding: 8px; border: 1px solid #CCC; box-shadow: 1px 0px 0px #EEE">
				<div style="float: left; width: 15%; font-weight: bold; font-size: 12px;"><?php echo $entry_existing_problems; ?></div>
				<div style="float: left; width: 85%; font-weight: bold; font-size: 12px;">
					<select id="problem_type" name="problem_type" style="margin-right: 35px;">
						<option value=""></option>
						<?php foreach ($problem_types as $problem_type) { ?>
							<option value="<?php echo $problem_type['table_id']; ?>"><?php echo $problem_type['value']; ?></option>
						<?php } ?>
					</select>
					<?php echo $entry_edit; ?><input type="checkbox" id="edit_problem" name="edit_problem" value="1" style="margin-left: 12px; margin-right: 12px;" />
					<?php echo $entry_delete; ?><input type="checkbox" id="del_problem" name="del_problem" value="1" style="margin-left: 12px; margin-right: 20px;" />
					<input type="text" id="edit_problem_box" name="edit_problem_box" value="" size="30" style="margin-right: 35px;" />
             Desc:  <textarea rows="3" id="edit_problem_box2" name="edit_problem_box2" cols="50" style="margin-right: 40px; vertical-align: middle;"></textarea>

            <a id="update_problem" class="button"><span><?php echo $button_update; ?></span></a>
				</div>
				<div style="float: left; width: 15%; margin-top: 15px; font-weight: bold; font-size: 12px;"><?php echo $entry_new_problem; ?></div>
				<div style="float: left; width: 20%; margin-top: 15px;"><input type="text" id="new_problem" name="new_problem" value="" size="30" />
                 <br />
               Desc:
               <textarea rows="3" id="new_problem2" name="new_problem2" cols="50" style="margin-right: 40px; vertical-align: middle;"></textarea>
                </div>
				<div style="float: left; width: 65%; margin-top: 15px;"><a id="save_problem_type" class="button"><span><?php echo $button_save; ?></span></a></div>
			</div>
		</form>
    </div>
  </div>
</div>
<script type="text/javascript">

	$(document).ready(function() {

		$('#edit_type').live('click', function() {
			if ($('#edit_type').attr('checked')) {
				if ($('#del_type').attr('checked')) {
					$('#del_type').attr('checked', false);
				}
			}
		});

		$('#del_type').live('click', function() {
			if ($('#del_type').attr('checked')) {
				if ($('#edit_type').attr('checked')) {
					$('#edit_type').attr('checked', false);
				}
			}
		});
		
		$('#edit_code').live('click', function() {
			if ($('#edit_code').attr('checked')) {
				if ($('#del_code').attr('checked')) {
					$('#del_code').attr('checked', false);
				}
			}
		});
		
		$('#del_code').live('click', function() {
			if ($('#del_code').attr('checked')) {
				if ($('#edit_code').attr('checked')) {
					$('#edit_code').attr('checked', false);
				}
			}
		});
		
		$('#edit_problem').live('click', function() {
			if ($('#edit_problem').attr('checked')) {
				if ($('#del_problem').attr('checked')) {
					$('#del_problem').attr('checked', false);
				}
			}
		});
		
		$('#del_problem').live('click', function() {
			if ($('#del_problem').attr('checked')) {
				if ($('#edit_problem').attr('checked')) {
					$('#edit_problem').attr('checked', false);
				}
			}
		});
		
		$('#update_type').live('click', function() {
			if ($('#call_type').val() == '') {
				alert('You must select an existing Call Type');
				return false;
			} else {
				if ($('#edit_type').attr('checked')) {
					if ($('#edit_type_box').val() == '') {
						alert('Update box cannot be empty.  Please enter the new Call Type name');
						$('#edit_type_box').focus();
						return false;
					} else {
						$.ajax({
							url: 'index.php?route=tool/testcare_table/edit_call_type&token=<?php echo $token; ?>',
							type: 'POST',
							dataType: 'json',
							data: 'table_id=' + $('#call_type').val() + '&dropdown_id=1&value=' + $('#edit_type_box').val() + '&dvalue=' + $('#edit_type_box2').val(),
							success: function(json) {
								$('#call_type').html(json);
								$('#testcare_form :input').val('');
								$('#testcare_form :input').attr('checked', false);
							}
						});
					}
				} else if ($('#del_type').attr('checked')) {
					$.ajax({
						url: 'index.php?route=tool/testcare_table/delete_call_type&token=<?php echo $token; ?>',
						type: 'POST',
						dataType: 'json',
						data: 'table_id=' + $('#call_type').val() + '&dropdown_id=1',
						success: function(json) {
							$('#call_type').html(json);
							$('#testcare_form :input').val('');
							$('#testcare_form :input').attr('checked', false);
						}
					});
				} else {
					alert('Edit/Delete box not checked');
					return false;
				}
			}
		});
		
		$('#update_code').live('click', function() {
			if ($('#priority_code').val() == '') {
				alert('You must select an existing Priority Code');
				return false;
			} else {
				if ($('#edit_code').attr('checked')) {
					if ($('#edit_code_box').val() == '') {
						alert('Update box cannot be empty.  Please enter the new Priority Code name');
						$('#edit_code_box').focus();
						return false;
					} else {
						$.ajax({
							url: 'index.php?route=tool/testcare_table/edit_priority_code&token=<?php echo $token; ?>',
							type: 'POST',
							dataType: 'json',
							data: 'table_id=' + $('#priority_code').val() + '&dropdown_id=2&value=' + $('#edit_code_box').val()+ '&dvalue=' + $('#edit_code_box2').val(),
							success: function(json) {
								$('#priority_code').html(json);
								$('#testcare_form :input').val('');
								$('#testcare_form :input').attr('checked', false);
							}
						});
					}
				} else if ($('#del_code').attr('checked')) {
					$.ajax({
						url: 'index.php?route=tool/testcare_table/delete_priority_code&token=<?php echo $token; ?>',
						type: 'POST',
						dataType: 'json',
						data: 'table_id=' + $('#priority_code').val() + '&dropdown_id=2',
						success: function(json) {
							$('#priority_code').html(json);
							$('#testcare_form :input').val('');
							$('#testcare_form :input').attr('checked', false);
						}
					});
				} else {
					alert('Edit/Delete box not checked');
					return false;
				}
			}
		});
		
		$('#update_problem').live('click', function() {
			if ($('#problem_type').val() == '') {
				alert('You must select an existing Problem Type');
				return false;
			} else {
				if ($('#edit_problem').attr('checked')) {
					if ($('#edit_problem_box').val() == '') {
						alert('Update box cannot be empty.  Please enter the new Problem Type name');
						$('#edit_problem_box').focus();
						return false;
					} else {
						$.ajax({
							url: 'index.php?route=tool/testcare_table/edit_problem_type&token=<?php echo $token; ?>',
							type: 'POST',
							dataType: 'json',
							data: 'table_id=' + $('#problem_type').val() + '&dropdown_id=3&value=' + $('#edit_problem_box').val()+ '&dvalue=' + $('#edit_problem_box2').val() ,
							success: function(json) {
								$('#problem_type').html(json);
								$('#testcare_form :input').val('');
								$('#testcare_form :input').attr('checked', false);
							}
						});
					}
				} else if ($('#del_problem').attr('checked')) {
					$.ajax({
						url: 'index.php?route=tool/testcare_table/delete_problem_type&token=<?php echo $token; ?>',
						type: 'POST',
						dataType: 'json',
						data: 'table_id=' + $('#problem_type').val() + '&dropdown_id=3',
						success: function(json) {
							$('#problem_type').html(json);
							$('#testcare_form :input').val('');
							$('#testcare_form :input').attr('checked', false);
						}
					});
				} else {
					alert('Edit/Delete box not checked');
					return false;
				}
			}
		});
		
		$('#save_call_type').live('click', function() {
			$('#save_call_type').attr('disabled', true);
			if ($('#new_type').val() != '') {
				$.ajax({
					url: 'index.php?route=tool/testcare_table/save_call_type&token=<?php echo $token; ?>',
					type: 'POST',
					dataType: 'json',
					data: 'dropdown_id=1&value=' + $('#new_type').val() + '&dvalue=' + $('#new_type2').val(),
					success: function(json) {
						$('#call_type').html(json);
						$('#testcare_form :input').val('');
						$('#testcare_form :input').attr('checked', false);
					}
				});
			}
			$('#save_call_type').attr('disabled', false);
		});
		
		$('#save_priority_code').live('click', function() {
			$('#save_priority_code').attr('disabled', true);
			if ($('#new_code').val() != '') {
				$.ajax({
					url: 'index.php?route=tool/testcare_table/save_priority_code&token=<?php echo $token; ?>',
					type: 'POST',
					dataType: 'json',
					data: 'dropdown_id=2&value=' + $('#new_code').val()+ '&dvalue=' + $('#new_code2').val(),
					success: function(json) {
						$('#priority_code').html(json);
						$('#testcare_form :input').val('');
						$('#testcare_form :input').attr('checked', false);
					}
				});
			}
			$('#save_priority_code').attr('disabled', false);
		});
		
		$('#save_problem_type').live('click', function() {
			$('#save_problem_type').attr('disabled', true);
			if ($('#new_problem').val() != '') {
				$.ajax({
					url: 'index.php?route=tool/testcare_table/save_problem_type&token=<?php echo $token; ?>',
					type: 'POST',
					dataType: 'json',
					data: 'dropdown_id=3&value=' + $('#new_problem').val()+ '&dvalue=' + $('#new_problem2').val(), 
					success: function(json) {
						$('#problem_type').html(json);
						$('#testcare_form :input').val('');
						$('#testcare_form :input').attr('checked', false);
					}
				});
			}
			$('#save_problem_type').attr('disabled', false);
		});
		
	});
	
</script>
<?php echo $footer; ?>
