<div class="footer">
        <div class="footerNav"> </div>
        <div class="copyright"> © Copyright 2017, Orbis. All Rights Reserved </div>
</div>
</div>

<div class="se-pre-con">
<div class="loaderNew"></div>
<h3>Loading.. Please wait</h3>
</div>


<div id="lightboxPopup" class="modal fade lightboxCost lightboxPopup" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <div class="modal-content">
            <div class="modal-body">
           
            <form id="add_costcenter2">
            <div class="ajax_msg"></div>
            <div class="row lighboxInner">
                <div class="col-lg-12 img_src">
                    
                </div>
            </div>
            
             <div class="row lighboxInner">
                <div class="col-lg-12 modal_text">
                    <p>r</p>
                </div>
            </div>
            
             <div class="add_more_fields"></div>
           
           </form>
            </div>
        </div>
    </div>
</div>



<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
<script src="<?= base_url(); ?>js/jquery-1.11.2.min.js"></script>
<script src="<?= base_url(); ?>js/jquery.validate.min.js"></script>
<script src="<?= base_url(); ?>js/jquery.dataTables.min.js"></script>

<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.material.min.js"></script>
<!-- <script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script> -->
<!-- Include all compiled plugins (below), or include individual files as needed --> 
<script src="<?= base_url(); ?>js/bootstrap.js"></script>
<script src="<?= base_url(); ?>js/common.js"></script>
<script src="<?= base_url(); ?>js/material-kit.js"></script>
<script src="<?= base_url(); ?>js/material.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src=".<?= base_url(); ?>js/jquery.cropit.js"></script>
  <script>
  
  $( function() {
	  
	 
    $.widget( "custom.combobox", {
      _create: function() {
        this.wrapper = $( "<span>" )
          .addClass( "custom-combobox" )
          .insertAfter( this.element );
 
        this.element.hide();
        this._createAutocomplete();
        this._createShowAllButton();
      },
 
      _createAutocomplete: function() {
        var selected = this.element.children( ":selected" ),
          value = selected.val() ? selected.text() : "";
 
        this.input = $( "<input>" )
          .appendTo( this.wrapper )
          .val( value )
          .attr( "title", "" )
          .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
          .autocomplete({
            delay: 0,
            minLength: 0,
            source: $.proxy( this, "_source" )
          })
          .tooltip({
            classes: {
              "ui-tooltip": "ui-state-highlight"
            }
          });
 
        this._on( this.input, {
          autocompleteselect: function( event, ui ) {
            ui.item.option.selected = true;
            this._trigger( "select", event, {
              item: ui.item.option
            });
          },
 
          autocompletechange: "_removeIfInvalid"
        });
      },
 
      _createShowAllButton: function() {
        var input = this.input,
          wasOpen = false;
 
        $( "<a>" )
          .attr( "tabIndex", -1 )
          .attr( "title", "Show All Items" )
          .tooltip()
          .appendTo( this.wrapper )
          .button({
            icons: {
              primary: "ui-icon-triangle-1-s"
            },
            text: false
          })
          .removeClass( "ui-corner-all" )
          .addClass( "custom-combobox-toggle ui-corner-right" )
          .on( "mousedown", function() {
            wasOpen = input.autocomplete( "widget" ).is( ":visible" );
          })
          .on( "click", function() {
            input.trigger( "focus" );
 
            // Close if already visible
            if ( wasOpen ) {
              return;
            }
 
            // Pass empty string as value to search for, displaying all results
            input.autocomplete( "search", "" );
          });
      },
 
      _source: function( request, response ) {
        var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
        response( this.element.children( "option" ).map(function() {
          var text = $( this ).text();
          if ( this.value && ( !request.term || matcher.test(text) ) )
            return {
              label: text,
              value: text,
              option: this
            };
        }) );
      },
 
      _removeIfInvalid: function( event, ui ) {
 
        // Selected an item, nothing to do
        if ( ui.item ) {
          return;
        }
 
        // Search for a match (case-insensitive)
        var value = this.input.val(),
          valueLowerCase = value.toLowerCase(),
          valid = false;
        this.element.children( "option" ).each(function() {
          if ( $( this ).text().toLowerCase() === valueLowerCase ) {
            this.selected = valid = true;
            return false;
          }
        });
 
        // Found a match, nothing to do
        if ( valid ) {
          return;
        }
 
        // Remove invalid value
        this.input
          .val( " " )
          .attr( "title", value + " didn't match any item" )
          .tooltip( "open" );
        this.element.val( "" );
        this._delay(function() {
          this.input.tooltip( "close" ).attr( "title", "" );
        }, 2500 );
        this.input.autocomplete( "instance" ).term = "";
      },
 
      _destroy: function() {
        this.wrapper.remove();
        this.element.show();
      }
    });
 
    $( ".combobox" ).combobox();
    $( ".toggle" ).on( "click", function() {
      $( ".combobox" ).toggle();
    });
  } );
  </script>

<script type="text/javascript">
	$(document).ready(function() {

	$('#example_length').css("padding-top","20px");
    $("#example_filter").css("padding-top","15px");


		
	  $('.settingselect').on('change', function() {
           if($(this).val()=="settings") { 
			var favorite = [];
            $.each($(".usercheck:checked"), function(){            
                favorite.push($(this).val());

            });
         	
			if(favorite=='')
			{
			  alert("Please select at least one user");
			}
			else
			{
				$('#lwd_ids').val(favorite);
				$('#settingpopup').modal('show');
			}		  
		   }
      });
	  
	  $('#change_setting').click(function(){
		   var arr = [];
           var i = 0;
		   var redalert       = $('.redalert').val();
		   var amberalert     = $('.amberalert').val();
		   var ipaddress      = $('.ipaddress').val();
		   var port           = $('.port').val();
		   var redalertsms    = $('.redalertsms').val();
		   var silentdial     = $('.silentdial').val();
		   var positionupdate = $('.fixedamber').val();
		   $('.usercheck').each(function () {
				if ($(this).is(':checked')) {
				     arr[i++] = $(this).val(); 
				}
		   });
           $.ajax({
				  url: '',
                  dataType: "json",	
                  data : { redalrt : redalert, amberalrt : amberalert, ipaddrss : ipaddress, prt : port, redalrtsms : redalertsms, silentdl : silentdial, positionupd : positionupdate, lwdid : arr },				  
				  success: function(result){
					   if(result == "success") {
						   window.location.reload();
					   }
                  }
			  });
            		    
	  });
		
     /* var table=$('#example').DataTable({
        "order": [[ 2, "desc" ]]
      });*/

      var table=$('#example').DataTable({
        "order": [[ 2, "desc" ]],
		   dom: "<'row'<'col-sm-3'l><'col-sm-3'f><'col-sm-6'p>>" +
		"<'row'<'col-sm-12'tr>>" +
		"<'row'<'col-sm-5'i><'col-sm-7'p>>"
		      });
			  
		 $('.dataTables_paginate').css('display','none');
	  $('#example_paginate').css('display','block');
	  
	  $(".costcenter").combobox({ 
        select: function (event, ui) { 
		
		     $('.contractfiltersubmit').submit();
        } 
      });
	  
	  $(".costcenteroffice").combobox({ 
        select: function (event, ui) {
			$.ajax({
				  url: "<?php echo base_url()."index.php/office/get_contract_area/" ?>"+$(this).val(),
                  dataType: "json",
                  beforeSend:function(){
					  $(".loading").css("display","inline");
                  },					  
				  success: function(result){
					    $(".contractareaoffice option").remove();
						$.each(result, function(i, item) {
							 $('.contractareaoffice').append(new Option(item.description,item.lindex));
						});
						 $(".loading").css("display","none");
                  }
		  	});
              
        } 
      });
	  
	  $('.contractareaoffice').combobox({ 
	     select: function (event, ui) {
			 if($(this).val()!="Select Contract Area") {
				 
				  $('.office').submit();
			 }
			
		 }
	  });
	  
	  $(".costcenterlwd").combobox({ 
        select: function (event, ui) {
        	// $('.contractarealwd option').html('<option>Loading</option>');
			$.ajax({
				  url: "<?php echo base_url()."index.php/office/get_contract_area/" ?>"+$(this).val(),
                  dataType: "json",
                   beforeSend: function(){
			        $('.loadingcontract').css('display','inline');
			    },			  
				  success: function(result){
						
						$.each(result, function(i, item) {
						 	$('.contractarealwd').append(new Option(item.description,item.lindex));
						});
						$('.loadingcontract').css('display','none');
                  }
			  });
              
        } 
      });
	  
	  $(".contractarealwd").combobox({ 
	      select: function (event, ui) {
			  
			  $.ajax({
				  url: "<?php echo base_url()."index.php/lwd/get_office/" ?>"+$(this).val(),
                  dataType: "json",
                     beforeSend: function(){
			        $('.loadingoffice').css('display','block');
			    },			  				  
				  success: function(result){
					    
						$.each(result, function(i, item) {
							
							 $('.officelwd').append(new Option(item.description,item.lindex));
						});
						$('.loadingoffice').css('display','none');
                  }
			  });
			  
		  }
	  });
	  
	  $('.costcenterpopup').change(function(){
		   
		    if($(this).val()!="") {
				  $.ajax({
						  url: "<?php echo base_url()."index.php/office/get_contract_area/" ?>"+$(this).val(),
						  dataType: "json",				  
						  success: function(result){
								$.each(result, function(i, item) {
									 //$('.contractareapopup').append(new Option(item.contractarea_name,item.contractarea_id));
									$('.contractareapopup').append('<option value="'+item.contractarea_id+'">'+item.contractarea_name+'</option>');
								});
						  }
					  });
			}else{
				 $('#restpartpopup').css('display','none');
			}
	  });
	  
	  $('.contractareapopup').on('change', function() {
		  if($(this).val()!="") {
				 $.ajax({
						  url: "<?php echo base_url()."index.php/lwd/get_office/" ?>"+$(this).val(),
						  dataType: "json",				  
						  success: function(result){
								
								$.each(result, function(i, item) {
									 //$('.officelwd').append(new Option(item.office_name,item.office_id));
									 $('.officepopup').append('<option value="'+item.office_id+'">'+item.office_name+'</option>');
								});
						  }
					  });
		  }else{
			  $('#restpartpopup').css('display','none');
		  }
	  });
	  
	  $('.officepopup').on('change', function() {
		  if($(this).val()!="") {
			  $('#restpartpopup').css('display','block');
		  }else{
			  $('#restpartpopup').css('display','none');
		  }
		  
		  
	  });
	  
	  
	  $(".contractarealwd").combobox({ 
	      select: function (event, ui) {
			  $('.loadingoffice').css('display','inline');
			  
			  $.ajax({
				  url: "<?php echo base_url()."index.php/lwd/get_office/" ?>"+$(this).val(),
                  dataType: "text",
				  beforeSend: function(){
				      $('.loadingoffice').css('display','block');
				  },
                  async:false,
                  contentType: "application/json; charset=utf-8",				  
				  success: function(result){
					  var obj = jQuery.parseJSON( result );
					 //console.log(obj);
					    for(var i=0; i<obj.length; i++){
							 //alert(obj.description);
                              $('.officelwd').append(new Option(obj[i].description,obj[i].lindex));
                         }	
					  $('.loadingoffice').css('display','none');
                  },
				  error: function (textStatus, errorThrown) {
                         
                  }
				  
			  });
			  
		  }
	  });
	  
	  $('.officelwd').combobox({ 
	     select: function (event, ui) {
			
			 if($('.costcenterlwd').val()!="Select Cost Center" &&  $('.contractarealwd').val()!="Select Contract Area") {
				 
				  $('.lwd').submit();
			 }
			
		 }
	  });
	  
	  
	$('.burgerMenu').click( function() {
		$(".leftSide").toggle("slide");
		$(".leftSide").toggleClass("active");
	});
	
	$('.cancelButton').click( function() {
		$(".leftSide").toggle("slide");
		$(".leftSide").toggleClass("active");	
	});
	
	
	$('.dropdownList1').on('click', function() {
		 $('.dropdownList1 .listInner1').toggleClass("collapse1"); 
		 if( $('.clickArrow2').is(':hidden') )
         {
            $('.clickArrow2').css('display', 'inline-block');
            $('.clickArrow1').css('display', 'none'); 
         }
         else
         {
            $('.clickArrow1').css('display', 'inline-block');
            $('.clickArrow2').css('display', 'none');  
         }
	});
	
	$('.dropdownList2').on('click', function() {
		 $('.dropdownList2 .listInner2').toggleClass("collapse1"); 
		 if( $('.clickArrow4').is(':hidden') )
         {
            $('.clickArrow4').css('display', 'inline-block');
            $('.clickArrow3').css('display', 'none'); 
         }
         else
         {
            $('.clickArrow3').css('display', 'inline-block');
            $('.clickArrow4').css('display', 'none');  
         }
	});
	
	$('.dropdownList3').on('click', function() {
		 $('.dropdownList3 .listInner3').toggleClass("collapse1"); 
		 if( $('.clickArrow6').is(':hidden') )
         {
            $('.clickArrow6').css('display', 'inline-block');
            $('.clickArrow5').css('display', 'none'); 
         }
         else
         {
            $('.clickArrow5').css('display', 'inline-block');
            $('.clickArrow6').css('display', 'none');  
         }
	});
	
	$(window).load(function() {
		$("#example_length .form-control").addClass("combobox");	
	});

	
	var height2=$( window ).height();
	$(".leftSide").css('height',height2);
	
	var height3=$( window ).height();
	$(".rightSide").css('min-height',height3);
	
	
	
   // updateImageSize();
   // $(window).resize(function() {
     //  updateImageSize();
 // });
	
	$('#selectCost').on('change',function(){
		 if( $(this).val() != ' ' || $(this).val() != null )
		 {
		 	$.ajax(
		 	{
		 		url: '<?php echo base_url()."index.php/lwd/get_contract_area"; ?>',
		 		type: 'get',
		 		dataType: 'json',
		 		data: { costcenter: $(this).val() },
		 		success: function(response)
		 		{
		 			if( response != ' ' || response != null )
		 			{
		 				$('.error_msg1').html(' ');
			 			$('#selectContract').html('<option>Select Contract Area</option>');
			 			for( var i=0; i<response.length; i++ )
			 			{
			 				$('#selectContract').append('<option value="'+response[i].lindex+'" >'+response[i].description+'</option>');
			 				$('.box22').css('opacity', '1');
			 				$('#step2').addClass('progress-done progress-current').removeClass('progress-todo');
			 			}
		 			}
		 			if( response.length == ' ' || response.length == null )
		 			{
		 				$('.error_msg1').html('<p style="color: red "><b> This Cost Center does not have Contract Area</b></p>');
		 			}
		 		}
		 	});
		 }

		
	});
	
	$('#selectContract').on('change',function(){
		//alert( $(this).val() );
		if( $(this).val() != ' ' || $(this).val() != null )
		 {
		 	$.ajax(
		 	{
		 		url: '<?php echo base_url()."index.php/lwd/get_office_list"; ?>/'+$(this).val(),
		 		type: 'get',
		 		dataType: 'json',
		 		//data: { contractarea: $(this).val() },
		 		success: function(response)
		 		{
		 			console.log(response);
		 			if( response != ' ' || response != null )
		 			{
		 				$('.error_msg2').html(' ');
			 			$('#selectOffice').html('<option>Select Office</option>');
			 			for( var i=0; i<response.length; i++ )
			 			{
			 				$('#selectOffice').append('<option value="'+response[i].lindex+'" >'+response[i].description+'</option>');
							$('.box33').css('opacity', '1');
			 				$('#step3').addClass('progress-done progress-current').removeClass('progress-todo');
			 			}
			 		}
			 		if( response.length == ' ' || response.length == null )
		 			{
		 				$('.error_msg2').html('<p style="color: red "><b> This Contract Area does not have Office</b></p>');
		 			}
		 		}
		 	});
		 }
	});
	
	$('#selectOffice').on('change',function(){
		$('#office_id').val( $(this).val() );
		
		$('#arrow').css('opacity', '1');
		$('#arrow').css('display', 'inline-block');
	});

	$('#arrow').click(function()
	{
		$('#step4').addClass('progress-done progress-current').removeClass('progress-todo');
		$('.box44').css('display','block');	
	})
	
	$('#selectLwd').on('change',function(){
		
	$('.box22').css('display', 'none');
	$('.box33').css('display', 'none');
	$('.box11').css('display', 'block');
	$('.box44').css('display', 'none');
	});
	
	$('.editlwd').click(function(){
		
		var id = $(this).attr('id');

		get_escalation_detail(id);

		$.ajax(
		{
		 		url: '<?php echo base_url()."index.php/lwd/get_lwd/" ?>'+id,
		 		type: 'get',
		 		dataType: 'json',
		 		data: { lwdid: id },
		 		success: function(response)
		 		{
		 			$.each(response, function(i, item) {
						$('#lwd_ids').val(response[i].ref);
						$('.firstname').val(response[i].loginname);
						$('.lastname').val(response[i].surname);
						$('.emailaddress').val(response[i].emailaddress);
						//$('.devicetype select').val(response[i].device_type);
						$('[name=devicetype]').val(response[i].device_type);
						$('.phonenumber').val(response[i].number);
						$('.imeinumber').val(response[i].imei_no);
						$('.address').val(response[i].address);
						if( response[i].gender == 'male' )
						{
							$('#valueMale').attr('selected', 'selected');
						}
						if(response[i].gender == 'female')
						{
							$('#valueFemale').attr('selected', 'selected');
						}
                        
                    })
					$('#editlwd').modal('show');
		 			
		 		}
		 });
		  
	  });
	  
	  $('#edit_lwd').click(function(e){
		  
	  	//alert($('.devicetype option:selected').val());

		 e.preventDefault();
		 var lwdid        = $('#lwd_ids').val();
		 var firstname    = $('.firstname').val();
		 var lastname     = $('.lastname').val();
		 var emailaddress = $('.emailaddress').val();
		 var devicetype   = $('.devicetype option:selected').val();
         var phonenumber  = $('.phonenumber').val();
		 var imeinumber   = $('.imeinumber').val();
		 var address      = $('.address').val();
		 var gender		  = $('.gender option:selected').val();
		  
		$.ajax(
		{
		 		url: '<?php echo base_url()."index.php/lwd/edit_lwd/" ?>'+lwdid,
		 		type: 'post',
		 		dataType: 'json',
		 		data: { lwdid: lwdid, fname: firstname, lname: lastname, emaddress: emailaddress, dtype: devicetype, phnumber: phonenumber, imnumber: imeinumber, addr: address, gender: gender},
		 		success: function(response)
		 		{
		 			if(response == "success"){
						
						alert("Lwd updated successfully");
						location.reload();
					}
					$('#editlwd').modal('hide');
		 			
		 		}
		 });  
	  });
	  
	  $('.editsetting').click(function(){
		  
		var id = $(this).attr('id');
		$('#setting_id').val(id);
		$.ajax(
		{
		 		url: '<?php echo base_url()."index.php/lwd/get_settings/" ?>'+id,
		 		type: 'get',
		 		dataType: 'json',
		 		success: function(response)
		 		{
		 			
		 			if( response.length == 1 )
		 			{
		 				$.each(response, function(i, item) {
							//$('#setting_id').val(id);
							$('#setting_screen_edit .label-floating').addClass('is-focused');
							$('#setting_screen_edit .redalert').val(response[0]['redalertnumber']);
							$('#setting_screen_edit .amberalert').val(response[0]['amberalertnumber']);
							$('#setting_screen_edit .ipaddress').val(response[0]['ipaddress']);
							$('#setting_screen_edit .port').val(response[0]['port']);
							$('#setting_screen_edit .redalertsms').val(response[0]['redalertsmsnumber']);
							$('#setting_screen_edit .silentdial').val(response[0]['silentdial']);
							$('#setting_screen_edit .positionupdate').val(response[0]['positionupdateinterval']);
							$('#setting_screen_edit .fixedamber ').val(response[0]['fixedambertime']);
							$('#setting_screen_edit #ambertimer ').val(response[0]['limitamber']);
							if( response[0]['falldetectenabled'] == '1' )
							{
								$('#setting_screen_edit #falldetectenabled ').prop("checked", true);
								$('#setting_screen_edit #falldetect ').removeAttr('disabled');
								$("#setting_screen_edit #falldetect").val( response[0]['falldetectedsensitivity'] );
							}
							if( response[0]['falldetectenabled'] == '0' )
							{
								$('#setting_screen_edit #falldetectdisable ').prop("checked", true);
							}
							if( response[0]['allow_user'] == '1' )
							{
								$('#setting_screen_edit #allowuser ').prop("checked", true);
							}
						
	                    });
						$('#editsettingpopup').modal('show');
		 			}else{
						
						$('#editsettingpopup').modal('show');
						
					}
					
					
		 		}
		 });
		  
		  
	  });
	  
	  $('.arrowIcon22').click(function(){
		  
		  $('.boxForm').css('display', 'inline-block');
		  
	  });
	  
	  
	  $("#setting_screen_edit").validate({
			rules: {
			  redalertnumber: "required",
			  amberalertnumber: "required",
			  ipaddress: "required",
			  port: "required",
			  redalertsmsnumber: "required",
			  silentdial: "required",
			  positionupdateinterval:"required",
			  fixedambertime:"required",
			  falldetectenabled:"required",
			  limitamber:"required",
			  falldetectedsensitivity:"required"			
			},
			messages: {
			  redalertnumber: "Please enter redalert number",
			  amberalertnumber: "Please enter amber alert number",
			  ipaddress: "Please enter ip address",
			  port: "Please enter port number",
			  redalertsmsnumber: "Please enter red alert sms number",
			  silentdial: "Please enter silent dial",
			  positionupdateinterval: "Please enter position update interval",
			  fixedambertime: "Please enter fixed amber time",
			  falldetectenabled: "Please enter fall detect enabled",
			  limitamber: "Please enter limit amber",
			  falldetectedsensitivity: "Please enter fall detected sensitivity"
			},
			submitHandler: function(form) {
			    var lwdid = $('#setting_id').val();
                var redalert = $('#redalert').val();
                var amberalert = $('#amberalert').val();
                var ipaddress = $('#ipaddress').val();
                var port = $('#port').val();
                var redalertsms = $('#redalertsms').val();
                var silentdial = $('#silentdial').val();
                var positionupdate = $('#positionupdate').val();
                var fixedamber = $('#fixedamber').val();
                var falldetectenabled = $('input[name=falldetectenabled]:checked').val();
                var limitamber = $('#ambertimer').val();
                var falldetectsensitivity  = $('#falldetect').val();
				var allowuser = "";
				if($("#allowuser").is(':checked')){
					allowuser = $('input[name="allow_user"]:checked').val();
				}else{
					allowuser="0";
				}
               $.ajax(
		       {
					url: '<?php echo base_url()."index.php/lwd/edit_setting/" ?>'+lwdid,
					type: 'post',
					dataType: 'json',
					data: { lwdid: lwdid, redalert: redalert, amberalert: amberalert, ipaddress: ipaddress, port: port, redalertsms: redalertsms, silentdial: silentdial, positionupdate: positionupdate, fixedamber: fixedamber, falldetectenabled: falldetectenabled, limitamber: limitamber, falldetectsensitivity: falldetectsensitivity, allowuser: allowuser },
					success: function(response)
					{
						
						if(response == true){
							
							alert("Settings updated successfully");
							location.reload();
						}
						//$('#editsettingpopup').modal('hide');
						
					}
		       });  				
			 
			}
	   });
	   
	   
	   $('.savecostcenter').click(function(e){
		   e.preventDefault();
		   var group = $('.fullNameField');
		  
		   var value=$.trim($('#cc_name').val());
		   
		   if(value.length==0) {
			  
			   $('.add_more_fields').prev('.error').remove();
			   $('.add_more_fields').before('<p style="color:red;" class="error">This field is required</p>');
			   $('.errorcount').attr('id',1);
			   //$('.errorcount').attr('id',"error");
			   
		   }else{
			  
			   $('.add_more_fields').prev('.error').remove();
			   $('.errorcount').attr('id',0);
			   //$('.errorcount').attr('id',"noerror");
		   }
		   group.each(function () {
			   
			    if($(this).val().length==0) {
					
					if($(this).parent().parent().next('.error').length>0){
						$(this).parent().parent().next('.error').remove();
						$(this).parent().parent().after('<p style="color:red;" class="error">This field is required</p>');	
					}else{
						
						$(this).parent().parent().after('<p style="color:red;" class="error">This field is required</p>');
					}
					
					//$('.errorcount').attr("id","error");
						
				}else{
					//alert("hello3");
					$(this).parent().parent().next('.error').remove();
					//$('.errorcount').attr('id',"noerror");
				}
		   });
           $('.cost').next('.error').remove();		   
		  
		   if($('.errorcount').attr('id')==0){
			   
			   $('#add_costcenter').submit();
		   }
	   });
	});

function get_escalation_detail(id)
	{
		$.ajax({
			url: '<?= base_url() ?>index.php/lwd/get_escalation_detail/'+id,
			type: 'get',
			dataType: 'json',
			success:function(response)
			{
				console.log(response);
				if(response == null)
				{
					$('#escalation_option').val('save_escalation');
					$('#escalationID').val(id);
					$('#escalation_tab')[0].reset();
					$('#button_div').html('<input type="submit" class="btn btn-default" id="save_escalation" value="Save Escalation">');
				}
				if(response.detail_id != null)
				{
					$('#escalation_option').val('edit_escalation');
					$('#escalationID').val(id);
					$('#name1').val( response.name1 );
					$('#phone1').val( response.phone_number1 );
					$('#name2').val( response.name2 );
					$('#phone2').val( response.phone_number2 );
					$('#name3').val( response.name3 );
					$('#phone3').val( response.phone_number3 );
					$('#button_div').html('<input type="submit" class="btn btn-default" id="edit_escalation" value="Edit Escalation">');
				}
			}
		});
	}
</script>

<script type="text/javascript">
	$(window).load(function() {
		// Animate loader off screen
		$(".se-pre-con").fadeOut("slow");
	});
</script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
	<div class="modal-content">
	  <div class="modal-header">
		<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
		<button type="button" class="close" data-dismiss="modal" aria-label="Close">
		  <span aria-hidden="true">&times;</span>
		</button>
	  </div>
	  <div class="modal-body">
		  <form action="#">
			  <div class="image-editor">
				<input type="file" class="cropit-image-input">
				<div class="cropit-preview"></div>
				<div class="image-size-label">
				  Resize image
				</div>
				<input type="range" class="cropit-image-zoom-input">
				<input type="hidden" name="image-data" class="hidden-image-data" />
				<button type="submit">Submit</button>
			  </div>
		   </form>

			<div id="result">
			  <code>$form.serialize() =</code>
			  <code id="result-data"></code>
			</div>
	  </div>
	  <div class="modal-footer">
		<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
		<button type="button" class="btn btn-primary">Save changes</button>
	  </div>
	</div>
  </div>
</div>
 <script>
      $(function() {
        $('.image-editor').cropit();

        $('form').submit(function() {
          // Move cropped image data to hidden input
          var imageData = $('.image-editor').cropit('export');
          $('.hidden-image-data').val(imageData);

          // Print HTTP request params
          var formValue = $(this).serialize();
          $('#result-data').text(formValue);

          // Prevent the form from actually submitting
          return false;
        });
      });
    </script>
</body>
</html>
