$(document).ready(function(){
	load();
});

/////////--Validation--/////////
// function validateInput(input) {
// 	var regex = /(\b(on\w+)=|javascript:|(<\s*)(\/*)script)/i;
// 	if (input.length > 100 || regex.test(input)) {
// 	  return false;
// 	}
// 	return true;
// }

function validateInput(input) {
  if (input == "") {
    return false;
  }
}

/////////--Validation--/////////

function add_litho_quantity(){
	$("#add_litho_quantity").load("module/ground_water_ex/add_litho_quantity_modal.php");
}
// datatable start 
function load(){
	// alert(load);
	// $('#cover-spin').show(0);
    $.ajax({
        url:"module/ground_water_ex/litho_quantity_setup_datatable.php",
        datatype:'get',
       // data: datastr,
        success:function(data){
			// alert(data);
			// $('#cover-spin').hide();
			$("#data_show").html(data);
			
        }
    });  
	// $("#data_show").load("module/ground_water_ex/litho_quantity_setup_datatable.php");
}	
// datatable end 

//////////----View Form----/////////
function load_material_code_vw_modal(qty_code){
	var datastr = "qty_code="+qty_code;
	//alert(datastr);
	$("#model_litho_code_vw_body").load("module/ground_water_ex/litho_quantity_setup_details_vw.php",datastr);
}
//////////----View Form----/////////

//////////----Edit Form----/////////
function load_material_code_edit_modal(qty_code){
	var datastr = "qty_code="+qty_code;
	//alert(datastr);
	$("#model_material_code_edit_body").load("module/ground_water_ex/litho_quantity_edit_form.php",datastr);
}
//////////----Edit Form----/////////


//Insert start
function add_save_litho_quantity_setup(){
	// alert(add_save_litho_quantity_setup);
	var operation =  "insert_lithology_material_code_data";
	var qty_code =  $('#qty_code').val();
	var quantity =  $('#quantity').val();

	if (validateInput(qty_code) == false) {
    alert("Please Insert The Quantity Code correctly");
    $("#qty_code").val("");
    $("#qty_code").focus();
    return false;
  } else if (validateInput(quantity) == false) {
    alert("Please Insert The quantity correctly");
    $("#quantity").val("");
    $("#quantity").focus();
    return false;
	}

		var datastr = "operation="+operation+"&qty_code="+qty_code+"&quantity="+quantity;
	// alert(datastr);
	$('#cover-spin').show(0);
    $.ajax({
        url:"module/ground_water_ex/lithi_quantity_setup_ajax.php",
        datatype:'post',
		data: datastr,
        success:function(data){
			$('#cover-spin').hide();
			// alert(data);
			if(data==1){
				alert('This quantity code already exists');
				// $('#modal_litho_quantity_setup').modal('hide');
				// load();
				$("#qty_code").focus();
			}else if(data==2){
				alert('Information has been added successfully');
				$('#modal_litho_quantity_setup').modal('hide');
				load();
			}
			else{
				alert('error occurred');
			}
        }
    });
}
//Insert end



//Update start
function update_lithology_material_code(){
	var operation =  "update_lithology_material_code_data";
	var qty_code =  $('#qty_code').val();
	var quantity =  $('#quantity').val();
	// var status   =    $('#status').val();

	if (validateInput(qty_code) == false) {
    alert("Please Insert The Quantity Code correctly");
    $("#qty_code").val("");
    $("#qty_code").focus();
    return false;
  } else if (validateInput(quantity) == false) {
    alert("Please Insert The quantity correctly");
    $("#quantity").val("");
    $("#quantity").focus();
    return false;
	}
	
		// var datastr = "operation="+operation+"&qty_code="+qty_code+"&quantity="+quantity+"&status="+status;
		var datastr = "operation="+operation+"&qty_code="+qty_code+"&quantity="+quantity;
		// alert(datastr);
	// }
	
	//alert(datastr);
	$('#cover-spin').show(0);
    $.ajax({
        url:"module/ground_water_ex/lithi_quantity_setup_ajax.php",
        datatype:'post',
		data: datastr,
        success:function(data){
			$('#cover-spin').hide();
			// alert(data);
			if(data!==1){
				alert('Information has been updated successfully');
				$('#modal-litho-material-code-edit').modal('hide');
				load();
			}
			else{
				alert('error occurred');
			}
        }
    });  
}
//Update end

///// delete data///////
function load_material_code_delete(qty_code) {
  // alert(qty_code);
  // var row_id = row_id;
  // var well_id = $("#well_id").val();
  // var id = $("#id_" + row_id).val();
  var operation = "delete";
  var datastr = "qty_code=" + qty_code + "&operation=" + operation;
  // alert(datastr);
  if (confirm("Are you sure you want to delete the selected row?")) {
    $.ajax({
      url: "module/ground_water_ex/lithi_quantity_setup_ajax.php",
      type: "post",
      data: datastr,
      success: function (str) {
        //alert(str);
        if (str == 1) {
          alert("Data has been deleted successfully");
					load();
        } else {
          alert("Fail to delete data");
        }
        
      },
    });
  }
}



