<?php include("header.php"); ?>
<!-- upload -->
<script type="text/javascript" src="js/upload/jquery.form.js"></script>
<!-- upload -->

<script type="text/javascript" charset="utf-8">
jQuery(function($){
$(".permit_from").datepicker();
});
jQuery(function($){
$(".permit_to").datepicker();
});
</script>

<script type="text/javascript">
jQuery(document).ready( function () {
$("#second").hide();


 $(".valid").keydown(function(event) {
        // Allow: backspace, comma, delete, tab and escape
		
        if ( event.keyCode == 46 //delete
		|| event.keyCode == 188  //backspace
		|| event.keyCode == 8    //comma
		|| event.keyCode == 9  //tab
		|| event.keyCode == 27 //esc
		|| event.keyCode == 109 // dash
            || // Allow: Ctrl+A
            (event.keyCode == 65 && event.ctrlKey === true) || 
             // Allow: home, end, left, right
            (event.keyCode >= 35 && event.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        else {
            // Ensure that it is a number and stop the keypress
            if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
                event.preventDefault(); 
            }   
        }
    });



/* amo ni*/
var myDate = new Date();
var pc_date = (myDate.getMonth()+1) + '/' + (myDate.getDate()) + '/' + myDate.getFullYear();
var pc_time = myDate.getHours()+':'+myDate.getMinutes()+':'+myDate.getSeconds();
jQuery(".pc_date").val(pc_date);
jQuery(".pc_time").val(pc_time);
/*asta d*/

$("#append").click( function() {
		$(".inc").append('<div class="field"><label>&nbsp;</label><select class="guards" name="guards[]"><?php  guards(); ?></select><a href="#" class="remove_this">remove</a></div>');
		return false;
	});
	
// using live() will bind the event to all future
// elements as well as the existing ones
jQuery('.remove_this').live('click', function() {
    $(this).parent().remove();
    return false;
});

jQuery('#save_equip').submit(function(e){
var name = jQuery('.name').val();
var type = jQuery('.type').val();
var serial = jQuery('.serial').val();
var brand = jQuery('.brand').val();
var model = jQuery('.model').val();
var cal = jQuery('.cal').val();
var quantity = jQuery('.quantity').val();
var price = jQuery('.price').val();
var license = jQuery('.license').val();
var permit_from = jQuery('.permit_from').val();
var permit_to = jQuery('.permit_to').val();

    e.preventDefault();
if (name && type && serial && brand && model && cal && quantity && price && license && permit_from && permit_to){	
    var formData = jQuery(this).serialize();
    jQuery.ajax({
        type: 'POST',
        url:  'save_equip.php',
        data: formData,
        success: function(msg){
            showNotification({
message: "Equipment Successfully Added",
type: "success", // type of notification is error/success/warning/information,
autoClose: true, // auto close to true
duration: 5 // message display duration
});

$("#shadow").hide("slow");
$("#second").show();	
}
    });
} else {
alert('All fields are required!');
return false;
}		
	
	
});
});

</script>
<style type="text/css">
<style>
#output {
	height:20px;
	font-size:16px;
	font-family:Arial, Helvetica, sans-serif;
	color:#333;
	padding:5px;
	margin-bottom:10px;
	background-color:#FFFF99;
}
#suggest_guard{
	padding:3px;
	border:1px #CCC solid;
	font-size:17px;
}
.suggestionsBox {
margin-left: 145px;
	left: 0px;
	top:48px;
	width: 174px;
	padding:0px;
	background-color: #000;
	border-top: 3px solid #000;
	color: #fff;
}
.suggestionList {
	margin: 0px;
	padding: 0px;
}
.suggestionList ul li {
	list-style:none;
	margin: 0px;
	padding: 6px;
	border-bottom:1px dotted #666;
	cursor: pointer;
	background:#000;
}
.suggestionList ul li:hover {
	background-color: #FC3;
	color:#000;
}
ul {
	font-family: "Trebuchet MS","Myriad Pro",Arial,sans-serif;
	font-size:14px;
	color:#FFF;
	padding:0;
	margin:0;
}

.set{
background-image:url(../images/ajax-loader.gif);
background-position:right;
background-repeat:no-repeat;
}

#suggest {
	position:relative;
}

</style>

<title>Add Equipment</title>
</head>
<body class="modify_user standard">
<div class="wrapper">

	<div class="header">
	<h1>Lifeguard Archangels Security Corporation</h1>
	</div>
<?php include("main_menu.php"); ?>
	<div class="right_nav">
	<h1>Equipments</h1>
<?php include("records_sidebar.php"); ?>
	</div>
	<div class="content">
	<div class="title_page">

	</div>
	
	<div class="actions">
	<div class="form label-inline uniform" id="shadow" style="width: 700px; margin:0 auto;" >
	<h2>Add Equipment</h2>
	<form id="save_equip">
	<input type="hidden" value="added equipment" name="action">
	<input type="hidden" class="pc_date" name="pc_date" value="">
	<input type="hidden" class="pc_time" name="pc_time" value="">
	<input type="hidden" value="<?php echo $_SESSION['user_name']; ?>" name="user">
	
	<div class="field"><label>Name</label> <input class="name" name="name" size="30" type="text" class="medium" /></div>
	<div class="field"><label>Type</label><select name="type" class="type" >
		<option>Choose Equipment Type</option>
		<option>Office</option>
		<option>Biometrics</option>
		<option>FireArms</option></select>
	</div>
	<div class="field"><label>Serial Number</label> <input class="serial valid" name="serial" size="30" type="text" class="medium" /></div>
	<div class="field"><label>Brand</label> <input class="brand" name="brand" size="30" type="text" class="medium" /></div>
	<div class="field"><label>Kind</label> <input class="model" name="model" size="30" type="text" class="medium" /></div>
	<div class="field"><label>Caliber</label> <input class="cal" name="cal" size="20" type="text" class="medium" /></div>
	<div class="field"><label>Quantity</label> <input class="quantity valid" name="quantity" size="30" type="text" class="medium" /><select class="unit" name="unit">
	<option value="pcs.">pc/pcs.</option>
	<option value="set">set</option>
	<option value="ammos">ammos</option>
	</select></div> 
	<div class="field"><label>Price </label> <input class="price valid" name="price" size="30" type="text" class="medium" /></div>
	<div class="field"><label>License No. </label> <input class="license valid" name="license" size="30" type="text" class="medium" /></div>
	<div class="field"><label>Permit Validity </label> <input class="permit_from" name="permit_from" size="30" type="text" class="medium" /> until <input class="permit_to" name="permit_to" size="30" type="text" class="medium" /></div>
	<div class="inc">
<!-- 	<div class="field"><label>Assigned Guard(s)</label> 

	<select class="guards" name="guards[]">
	<?php $guards = mysql_query("SELECT * FROM employees WHERE type = 'guard'") or die(mysql_error());  ?>
		<?php WHILE($guard = mysql_fetch_array($guards)){
			$firstname = $guard['first_name'];
		$lastname = $guard['last_name'];
		?>
	<option value="<?php echo $firstname; echo $lastname; ?>"><?php echo $firstname; echo $lastname; ?></option>
	<?php } ?>
	</select>
	<button type="submit" id="append" name="append">Add Guard</button></div> -->
	</div>
	<div class="field"><button id="save_equip" name="SubmitOne">Save</button></div>
	</form>
	</div>
	<div class="form label-inline uniform" id="second" style="width: 700px; margin:0 auto;" >
	<form id="imageform" class="uploadthis" method="post" enctype="multipart/form-data" action='upload_equip.php'>
	<div class="field"><label>Upload Equipment Image</label> <input type="file" name="photoimg" id="photoimg" />
	</div>
	</form>
	<div id='preview'>
	</div>
	<!--<form id="license_form" class="uploadthis" method="post" enctype="multipart/form-data" action='upload_license.php'>
	<div class="field"><label>Upload License Image</label> <input type="file" name="license" id="license" />
	</div>
	</form>
	<div id='preview_license'>
	</div>-->
	</div>
</div>	
</div>
<?php include("footer.php"); ?>
</div>
</body>
</html>
<!-- upload -->
<!-- upload -->
<script type="text/javascript" >
jQuery(document).ready(function() { 
		
            jQuery('#photoimg').live('change', function()			{ 
			           jQuery("#preview").html('');
			   jQuery("#preview").html('<img src="images/loader.gif" alt="Uploading...."/>');
			jQuery("#imageform").ajaxForm({
						target: '#preview'
		}).submit();
						var delay = 3000;
						setTimeout(function(){ window.location = 'view_equip_list.php';}, delay);  
			});
			
        }); 
</script>
<!--<script type="text/javascript" >
jQuery(document).ready(function() { 
		
            jQuery('#license').live('change', function()			{ 
			           jQuery("#license_prev").html('');
			   jQuery("#license_prev").html('<img src="images/loader.gif" alt="Uploading...."/>');
			jQuery("#license_form").ajaxForm({
						target: '#preview_license'
		}).submit();
						var delay = 3000;
						setTimeout(function(){ window.location = 'view_equip_list.php';}, delay);  
			});
        }); 
</script>-->
<!-- upload end -->
