/********************************** Validation *******************************************************/
function shift_validation()
{
	
    var from_time = document.getElementById("from_time").value;
	if(from_time=='')
	{
		document.getElementById("from_time_validation_div").innerHTML="* This field is Required.";
		document.getElementById("from_time").focus();
		return false;
	}
	
	var to_time = document.getElementById("to_time").value;
	if(to_time=='')
	{
		document.getElementById("to_time_validation_div").innerHTML="* This field is Required.";
		document.getElementById("to_time").focus();
		return false;
	}
	
	var shift_name = document.getElementById("shift_name").value;
	if(shift_name=='')
	{
		document.getElementById("shift_name_validation_div").innerHTML="* This field is Required.";
		document.getElementById("shift_name").focus();
		return false;
	}
	
	var description = document.getElementById("descript").value;
	if(description=='')
	{
		document.getElementById("description_validation_div").innerHTML="* This field is Required.";
		document.getElementById("description").focus();
		return false;
	}
	
	
	var from = document.getElementById("from_time").value;
	var to = document.getElementById("to_time").value;
	if(from_time==to_time)
	{
		alert("From and To time Shouldn't To Be Same");
		document.getElementById("from_time").focus();
		return false;
	}
}

function shift_clear_validation(str)
{
	if(str!='')
	{
		document.getElementById("from_time_validation_div").innerHTML=" ";
	}
	
	if(str!='')
	{
		document.getElementById("to_time_validation_div").innerHTML=" ";
	}
	
	if(str!='')
	{
		document.getElementById("shift_name_validation_div").innerHTML=" ";
	}
}

/********************************** Mainlist Add *******************************************************/
function shift_entry_add(from_time,to_time,shift_name,description,edit_id,action)
{
if((from_time!='')&&(to_time!='')&&(shift_name!='')&&(from_time!=to_time))
 {
  jQuery.ajax({
		type: "POST",
		url: "shift_entry_db.php",
		data: "from_time="+from_time+"&to_time="+to_time+"&shift_name="+shift_name+"&description="+description+"&edit_id="+edit_id+"&action="+action,
		success: function(msg){jQuery("#entry_list_div").html(msg);	
		alert(msg);
		window.close();
		window.opener.location.reload(true);
 }
		});
 }
else
{
    shift_validation();
}
}

/********************************** Mainlist Delete *******************************************************/
function shift_delete(id) {
    if (!confirm('Are you sure you want to delete?')) return;

    $.ajax({
        type: "POST",
        url: "shift_creation/shift_entry_db.php",
        data: $.param({ id: id, action: 'delete' }),
        success: function (response) {
            $("#entry_list_div").html(response);
            if (window.opener) {
                window.opener.location.reload(true);
            }
        },
        error: function (xhr, status, error) {
            console.error("Deletion failed:", error);
            alert("An error occurred while deleting the shift.");
        }
    });
}



