$(function() 
{
	$("#stockitemstable").dataTable();
	
	receivegoodsform = function(item, itemstatus, itemversion)
	{
		$("#servererrormessage").html('');
		
		if(itemstatus == 1)
		{
			$.ajax
			(
				{
					url: "receiveitemgoodsform.php",
					async: true, 
					type: "POST",
					dataType: "json",
					data: {stockitem: item, recversion: itemversion},
					success: function(json)
					{
						if(json[0].isdataobtained == 0)
						{
							$("#servererrormessage").html(json[0].message);
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						}
						else
						{
						 
							$("#largemodaldetails").html(json[0].message);
							$('#largemodal').modal('show');
						}
					},
					error: function(jqXHR, exception)
					{	
						if (jqXHR.status === 0) 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Not Connected Verify Network.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (jqXHR.status == 404) 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested Operation Not Found.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (jqXHR.status == 500) 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Internal Server Error.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (exception === 'parsererror') 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested JSON Parse Failed.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (exception === 'timeout') 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Time Out Error.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (exception === 'abort') 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Ajax Request Aborted.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Uncaught Error " + jqXHR.responseText + ".</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						}
					}
				}
			);
		}
		else
		{
			$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Item Status Does Not Support Goods Receipt!</div>");
			$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
		}
	}
	
	transfergoodstoshopform = function(item, itemstatus, itemversion)
	{
		$("#servererrormessage").html('');
		
		if(itemstatus == 1)
		{
			$.ajax
			(
				{
					url: "itemtransfertoshopform.php",
					async: true, 
					type: "POST",
					dataType: "json",
					data: {stockitem: item, recversion: itemversion},
					success: function(json)
					{
						if(json[0].isdataobtained == 0)
						{
							$("#servererrormessage").html(json[0].message);
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						}
						else
						{
							$("#largemodaldetails").html(json[0].message);
							$('#largemodal').modal('show');
						}
					},
					error: function(jqXHR, exception)
					{	
						if (jqXHR.status === 0) 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Not Connected Verify Network.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (jqXHR.status == 404) 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested Operation Not Found.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (jqXHR.status == 500) 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Internal Server Error.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (exception === 'parsererror') 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested JSON Parse Failed.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (exception === 'timeout') 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Time Out Error.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else if (exception === 'abort') 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Ajax Request Aborted.</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						} 
						else 
						{
							$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Uncaught Error " + jqXHR.responseText + ".</div>");
							$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						}
					}
				}
			);
		}
		else
		{
			$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Item Status Does Not Support Goods Transfer!</div>");
			$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
		}
	}
	
	returngoodstostoreform = function(item, itemversion)
	{
		$("#servererrormessage").html('');
		
		$.ajax
		(
			{
				url: "itemreturntostoreform.php",
				async: true, 
				type: "POST",
				dataType: "json",
				data: {stockitem: item, recversion: itemversion},
				success: function(json)
				{
					if(json[0].isdataobtained == 0)
					{
						$("#servererrormessage").html(json[0].message);
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
					else
					{
						$("#largemodaldetails").html(json[0].message);
						$('#largemodal').modal('show');
					}
				},
				error: function(jqXHR, exception)
				{	
					if (jqXHR.status === 0) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Not Connected Verify Network.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 404) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested Operation Not Found.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 500) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Internal Server Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'parsererror') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested JSON Parse Failed.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'timeout') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Time Out Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'abort') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Ajax Request Aborted.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Uncaught Error " + jqXHR.responseText + ".</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
				}
			}
		);
		
	}
	
	itemadjustmentform = function(item, itemversion)
	{
		$("#servererrormessage").html('');
		
		$.ajax
		(
			{
				url: "itemadjustmentform.php",
				async: true, 
				type: "POST",
				dataType: "json",
				data: {stockitem: item, recversion: itemversion},
				success: function(json)
				{
					if(json[0].isdataobtained == 0)
					{
						$("#servererrormessage").html(json[0].message);
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
					else
					{
						$("#largemodaldetails").html(json[0].message);
						$('#largemodal').modal('show');
					}
				},
				error: function(jqXHR, exception)
				{	
					if (jqXHR.status === 0) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Not Connected Verify Network.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 404) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested Operation Not Found.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (jqXHR.status == 500) 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Internal Server Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'parsererror') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Requested JSON Parse Failed.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'timeout') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Time Out Error.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else if (exception === 'abort') 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Ajax Request Aborted.</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					} 
					else 
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>Uncaught Error " + jqXHR.responseText + ".</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
				}
			}
		);
		
	}
});