$(function() 
{
	tagsetup = function(tagid, tagversion)
	{
		$("#servererrormessage").html('');
		
		$.ajax
		(
			{
				url: "tagsetupform.php",
				async: true, 
				type: "POST",
				dataType: "json",
				data: {tag: tagid, recversion: tagversion},
				success: function(json)
				{
					if(json[0].isdataobtained == 0)
					{
						$("#servererrormessage").html(json[0].message);
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
					else
					{
						$("#tagdetails").html(json[0].message);
						$('#tagmodal').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');
					}
				}
			}
		);
	}
	
	deletetag = function(tagid, tagversion)
	{
		$("#servererrormessage").html('');
		
		$.ajax
		(
			{
				url: "gltagdelete.php",
				async: true, 
				type: "POST",
				dataType: "json",
				data: {tag: tagid, recversion: tagversion},
				success: function(json)
				{
					if(json[0].issaved == 0)
					{
						$("#servererrormessage").html("<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>" + json[0].message + "</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
					}
					else
					{
						$("#servererrormessage").html("<div class=\"alert alert-success\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>" + json[0].message + "</div>");
						$('html, body').animate({ scrollTop: $("#servererrormessage").offset().top }, 'slow');
						location.href="gltagsview.php";
					}
				},
				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');
					}
				}
			}
		);
	}
	
});