function save_tin() {
	var mainpage 	= $("#main_page").val();
	var maintype 	= $("#main_type").val();
	var mainaction 	= $("#main_action").val();
	var mainid 		= $("#main_id").val();
   	 
	var tinform = $("#tin_form");
	var tinformserial = $("#tin_form").serialize();	
 
	var dataString	= tinformserial + "&action=" + encodeURIComponent(mainaction) + "&mainid=" + encodeURIComponent(mainid);

	$.post("./ajax/tin.php", dataString, function(result) {
		  	var obj	= $.parseJSON(result);
			if(obj.output==true){
				bootbox.alert("Successfully Saved ...");
				window.setTimeout(function() { window.location.href = 'index.php?pg='+mainpage+'&type='+maintype; }, 1000);
			}else{
				bootbox.alert("Failed in saving."); 
			} 
	});
 
}

function delete_tin(e) {
	var a = "tin",
		o = $("#main_page").val(),
		t = $("#main_type").val(),
		n = "mainid=" + encodeURIComponent(e) + "&transaction=" + encodeURIComponent(a);
	$.post("./ajax/delete_transaction.php", n, function(e) {
		var a = $.parseJSON(e);
		1 == a.output ? (bootbox.alert("Successfully Deleted ..."), window.setTimeout(function() {
			window.location.href = "index.php?pg=" + o + "&type=" + t
		}, 1e3)) : (bootbox.alert("Failed in Deleting ..."), window.setTimeout(function() {
			window.location.href = "index.php?pg=" + o + "&type=" + t
		}, 1e3))
	})
}

function load_tin() {
 
	var mainpage 	= $("#main_page").val();
	var maintype 	= $("#main_type").val();
	var mainaction 	= $("#main_action").val();
	var mainid 		= $("#main_id").val();
	 
	var dataString	= "action=" + encodeURIComponent(mainaction) + "&mainid=" + encodeURIComponent(mainid);
 
	$.post("./ajax/load_tin.php", dataString, function(result) {
		  	var obj					= $.parseJSON(result);			 
			var company 			= obj.data[0].company;  
			var category 			= obj.data[0].category; 
			var tin 				= obj.data[0].tin;   
  
			$('#company').val(company);   
			$('#category').val(category);
			$('#tin_no').val(tin); 

			var action 			=	$('#main_action').val(); 

			if(action=="view"){
				$('input').attr("disabled", true);
				$('textarea').attr("disabled", true);
				$('select').attr("disabled", true);
				$('#current_project').select2('disable');
				$('#current_model').select2('disable'); 
				$('.glyphicon-trash').hide();
				$('.glyphicon-plus').hide();  
				$('.refresh').hide();  
			}

	});
 
}
 

	var mods 			=	$('#main_page').val();
	var types 			=	$('#main_type').val(); 
	var action 			=	$('#main_action').val(); 
	if(mods=="settings" && types=="tin" && (action=="edit" || action=="view")){
			
 			load_tin();
 
 	}

 