<script src="//cdn.ckeditor.com/4.7.3/standard/ckeditor.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.min.js"></script>
 <section id="content">

                <div class="page page-dashboard">

                    <div class="pageheader">

                        <h3>Add/Edit Product</h3>
                    </div>

					<div class="row">
                    <div class="col-md-10">
                    <section class="tile">

                                <!-- tile header -->
                                <div class="tile-header dvd dvd-btm">
                                    <h1 class="custom-font"><strong>Product </strong>Details</h1>
                                </div>
                                <div class="tile-body">
        						<form action="<?php echo base_url();?>admin/add_product_submit1" method="post" enctype="multipart/form-data">
            <div class="row">
                <div class="form-group col-md-4">
                    <label for="email">Select MainCategory</label>
                    <select class="cat form-control load_pre_attr" name="mid" id="mcat" required>
                        <option value="">Select MainCategory</option>
                        <?php $mcat=$this->db->get("mcategory")->result();
                            foreach($mcat as $cat){?>
                        <option value="<?php echo $cat->mid;?>"><?php echo $cat->mcat_name;?></option>
                        <?php }?>
                    </select>
                </div>
                 <div class="form-group col-md-4">
                    <label for="email">Select Category</label>
                    <select class="cat form-control load_pre_attr" name="cid" id="cat" required>
                        <option value="">Select Category</option>
                    </select>
                </div>
                <div class="form-group col-md-4">
                    <label for="email">Select Subcategory</label>
                    <select class="subcat form-control load_pre_attr" name="sid" id="subcat">
                        <option value="">Select Subcategory</option>
                    </select>
                </div>
                <div class="form-group col-md-6">
                	<label>Product Title</label>
                    <input type="text" name="title" required class="form-control">
                </div>
                <div class="form-group col-md-3">
                	<label>Product <b>SKU</b></label>
                    <input type="text" name="psku" required class="form-control">
                </div>
                <div class="form-group col-md-3">
                    <label for="pwd" class="text-success">Select Brand</label>
                     <select class=" form-control" name="brand">
                        <option value="">Select Brand</option>
                        <?php $vn=$this->db->get("brands")->result();
                                foreach($vn as $v){?>
                        <option value="<?php echo $v->brid;?>"><?php echo $v->brname;?></option>
                        <?php }?>
                    </select>
                </div>
                <div class="col-md-12 attributes_list">
            
            	</div>
                <div class="form-group col-md-4">
                    <label for="email">Select Vendor</label>
                    <select class="form-control" name="vendor" required>
                        <option value="">Select Vendor</option>
                        <?php $vn=$this->db->get("vendors")->result();
                                foreach($vn as $v){?>
                        <option value="<?php echo $v->vid;?>"><?php echo $v->v_name.'-'.$v->vb_name;?></option>
                        <?php }?>
                    </select>
                </div>
                <div class="form-group col-md-4">
                <label for="email">Add Main Image</label>
                <input type="file" class="form-control" id="fileUpload" required name="main_image"/>
                </div>
                <div class="form-group col-md-4">
                <label for="email">Add Gallery Images</label>
                <input type="file" class="form-control" id="tg-photogallery"  onchange="preview_images();" name="test11[]"  multiple />
                </div>
            </div>
            <div class="row">
                <div class="col-md-2">
                    <div id="image-container">
                    </div>
                </div>
                <div class="col-md-10">
                    <div class="row" id="image_preview"></div>
                </div>
            </div>
            <div class="row">
									<div class="form-group col-md-3">
                                    	<label for="packing">Packing Type</label>
										<select class="form-control"  name="pack_type" required id="pack_type">
                                            <option value="Box" selected="selected">Box</option>
                                        	<option value="Cylinder">Cylinder</option>
                                        </select>
                                       <!-- <select class="form-contol" name="pack_type"  id="pack_type">

                                        	<option value="Box" selected="selected">Box</option>

                                        	<option value="Cylinder">Cylinder</option>

                                        </select>-->

                                    </div>
                                	<div class="form-group col-md-2 typebox">

                                    	<label for="price">Length (mt)</label>

                                        <input type="text" class="form-control calc" name="length" />

                                    </div>

                                    <div class="form-group  col-md-2 typebox">

                                    	<label for="price">Width (mt)</label>

                                        <input type="text" class="form-control calc" name="width" />

                                    </div>

                                    <div class="form-group  col-md-2">

                                    	<label for="price">Height (mt)</label>

                                        <input type="text" class="form-control calc" name="height" id="height" />

                                    </div>

                                    <div class="form-group col-md-2 type_cylinder" style="display:none;">

                                    	<label for="price">Diameter (mt)</label>

                                        <input type="text" class="form-control" name="diameter" id="diameter" />

                                    </div>

                                    <div class="form-group col-md-3">

                                    	<label for="price">Volumetric Wt(kg)</label>

                                        <input type="text" class="form-control calcr" name="weight" />

                                    </div>
                                    <div class="form-group col-md-3">
                                        <label>Delivery Time</label>
                                        <select class="form-control" name="del_time" required>
                                            <option value="">Select Days</option>
                                            <option value="1 day">1 day</option>
                                            <option value="2 day">2 day</option>
                                            <option value="3 day">3 day</option>
                                            <option value="4 day">4 day</option>
                                            <option value="5 day">5 day</option>
                                            <option value="A week">A week</option>
                                            <option value="More than a week">More than a week</option>
                                        </select>
                                     </div>
                                     <div class="form-group col-md-2">
                                        <label>Regular Price</label>
                                        <input type="number" class="form-control" name="price" />
                                     </div>
                                     <div class="form-group col-md-2">
                                        <label>Regular Price</label>
                                        <input type="number" class="form-control" name="oprice" />
                                     </div>
                                     <div class="form-group col-md-2">
                                        <label>Regular Qty</label>
                                        <input type="number" class="form-control" name="qty" />
                                     </div>
                                     <div class="form-group col-md-2">
                                        <label>GST(%)</label>
                                        <input type="number" class="form-control" name="gst" />
                                     </div>
                                </div>
             <div class="row">
                <div class="form-group col-md-12"> <h5 class="text-success">Add Product Description</h5>
                    <textarea class="summernote"  name="editor1"></textarea>
                </div>
             </div>
             <div class="form-group">
                <label class="control-label">Meta Title</label>
                <input type="text"  name="meta_title" class="form-control metas_p">
             </div>   
             <div class="form-group">
                <label class="control-label">Meta Keywords</label>
                <textarea class="form-control metas_p" rows="2" name="meta_key"></textarea>
             </div>
             <div class="form-group">
                <label class="control-label">Meta Description</label>
                <textarea class="form-control metas_p" rows="5" name="meta_desc"></textarea>
             </div>
             <div class="form-group">
                <label class="control-label">Og:Title</label>
                <input type="text" name="og_title" class="metas_p form-control">
             </div>
             <div class="form-group">
                <label class="control-label">Og:Description</label>
                <textarea class="form-control metas_p" rows="4" name="og_desc"></textarea>
             </div>
       		 <button type="submit" style="margin-top:25px;" class="btn btn btn-warning pull-right">Add Product</button>
            </form>
            					</div>
                                </section>
        </div>
					</div>

                </div>

                
            </section>
            <!--/ CONTENT -->
        </div>

        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/bootstrap/bootstrap.min.js"></script>
        <script>
		$("#fileUpload").on('change', function() {

  if (typeof(FileReader) == "undefined") {
    alert("Your browser doesn't support HTML5, Please upgrade your browser");
  } else {

    var container = $("#image-container");

    //remove all previous selected files
    container.empty();

    //create instance of FileReader
    var reader = new FileReader();
    reader.onload = function(e) {
      $("<img />", {
        "src": e.target.result,"style": 'width:100%;'
      }).appendTo(container);
    }
    
    reader.readAsDataURL($(this)[0].files[0]);
  }});
CKEDITOR.replace( 'editor1' );
function preview_images() 
{
	$('#image_preview').html('');
 var total_file=document.getElementById("tg-photogallery").files.length;
 for(var i=0;i<total_file;i++)
 {
  $('#image_preview').append("<div class='col-md-2'><img style='width:300px;height:150px;margin:5px;border:1px solid grey;' class='img-responsive' src='"+URL.createObjectURL(event.target.files[i])+"'></div>");
 }
}
$(document).ready(function () {
	$("#diameter").keyup(function(){var tot=1;

			var h=$("#height").val();

			var d=$("#diameter").val();

			var newv=(h*d*d*250).toFixed(3);

			$(".calcr").val(newv);

		});

		$(".calc").keyup(function(){var tot=1;

			var pt=$("#pack_type").val();

			if(pt=="Box"){

			$('.calc').each(function(){

				var total_amt=$(this).val();

				if(total_amt!="" && parseFloat(total_amt)>0){

					tot = parseFloat(total_amt) * tot;

				}

			 });

			 var tt=(tot*250).toFixed(3);

			 $(".calcr").val(tt);

			}else{

			var h=$("#height").val();

			var d=$("#diameter").val();

			//console.log(h);

//			console.log(d);

//			return false;

			var newv=(h*d*d*250).toFixed(3);

			$(".calcr").val(newv);

			}

		});
	$("#mcat").change(function(){
			var cid=$(this).val();
			$.ajax({
			 type: "POST",
			 url: '<?php echo base_url();?>manufacture/ajax_mcat',
			 data: {cid:cid},
			 success: function(res){
				$("#cat").html(res);
				$('.subcat').html('<option value="">Select Subcategory</option>');
				}
			 }); 
	});
	$(".cat").change(function(){
			var cid=$(this).val();
			$.ajax({
			 type: "POST",
			 url: '<?php echo base_url();?>manufacture/ajax_showsubcat1',
			 data: {cid:cid},
			 success: function(res){
			//alert(res);
			$(".subcat").html(res);
			}
		}); 
	});
	///filters
	$(".load_pre_attr").change(function(){
		var mid=$("#mcat").val();
		var cid=$("#cat").val();
		var sid=$("#subcat").val();
		$.ajax({
			 type: "POST",
			 url: '<?php echo base_url();?>admin/attributes_list',
			 data: {mid:mid,cid:cid,sid:sid},
			 success: function(res){
			 //$("."+id+"_dynamic_attr").html(res);
			 $(".attributes_list").html(res);
			}
		 }); 
	});
});
</script>
		<script src="<?php echo base_url();?>admin_assets/assets/js/vendor/jRespond/jRespond.min.js"></script>


        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/rickshaw/rickshaw.min.js"></script>

        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/sparkline/jquery.sparkline.min.js"></script>

        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/slimscroll/jquery.slimscroll.min.js"></script>

        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/animsition/js/jquery.animsition.min.js"></script>


        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/screenfull/screenfull.min.js"></script>

        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/flot/jquery.flot.min.js"></script>
        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/flot-tooltip/jquery.flot.tooltip.min.js"></script>
        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/flot-spline/jquery.flot.spline.min.js"></script>

        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/chosen/chosen.jquery.min.js"></script>

        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/summernote/summernote.min.js"></script>

        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/coolclock/coolclock.js"></script>
        <script src="<?php echo base_url();?>admin_assets/assets/js/vendor/coolclock/excanvas.js"></script>
        <script src="<?php echo base_url();?>admin_assets/assets/js/main.js"></script>
        
</html>