$(document).ready( function() {
	$(".shid").hide(); 
	$('.unavail').click( function() {
		alert("This Feature is not yet Available...");
	});
	$('.left-col').hover( function() {
		$(".shid").slideDown(); 
		}, function() {
			$(".shid").slideUp(); 
		});	
		
	$(".del").click( function() { 
	
		var id = $(this).attr("id");
		if(confirm("Are you sure you want to delete this book??"))
		{
	 	$.ajax({
		type: "POST",
		data: ({id: id}),
		url: "delete_book.php",
		cache: false,
		success: function(response){
		
		$(".del"+id).fadeOut('slow', function() {$(this).remove();});	
		
		}
		});
		}
		
		return false;
	});
	
	$("#update").click( function() { 
		var id = $("#id").val();
		var title = $("#title").val();
		var author = $("#author").val();
		var publisher = $("#publisher").val();
		var status = $("#status").val();
		var isbn = $("#isbn").val();
		var call_no = $("#call_no").val();
		var section = $("#section").val();
		var Class = $("#Class").val();
		var subClass = $("#subClass").val();
		var copyright = $("#copyright").val();
	
		$.ajax({
		type: "POST",
		data: ({
		id: id,
		copyright: copyright,
		subClass: subClass,
		Class: Class,
		title: title,
		section: section,
		author: author,
		publisher: publisher,
		status: status, 
		isbn: isbn, 
		call_no: call_no}),
		url: "update_book.php",
		cache: false,
		success: function(response){
		$(".stat").fadeIn().html(response); 
		$('.success').show();
		}
		});
	
	});
	
	$("#save").click( function() {
		var title = $(".title").val();
		var author = $(".author").val();
		var pub_name = $(".pub_name").val();	
		var pub_place = $(".pub_place").val();
		var isbn = $(".isbn").val();		
		var class1 = $(".class1").val();
		var section = $(".section").val();
		var sub_class = $(".sub_class").val();		
		var copyright = $(".copyright").val();			
		var callNumber = $(".callNumber").val();		
		var stat = $(".stat").val();		
	
	if(title == "" ){
		$(".title").addClass("error");
	}else if(author == ""){
		$(".author").addClass("error");	
	}else if(callNumber == ""){
		$(".callNumber").addClass("error");
	}else if(pub_name == ""){
		$(".pub_name").addClass("error");
	}else if(pub_place == ""){
		$(".pub_place").addClass("error");
	}else if( class1 == "" ){
		$(".class1").addClass("error");
	}else if( section == "" ){
		$(".section").addClass("error");
	}else if( sub_class == "" ){
		$(".sub_class").addClass("error");
	}else if( copyright == "" ){
		$(".title").addClass("error");
	}else if( stat == "" ){
		$(".stat").addClass("error");
	}else{	
	
	jQuery('.loading').fadeIn();
	
	$.ajax({		
	type: "POST",
	data: ({
	callNumber: callNumber, 
	stat: stat, 
	copyright: copyright, 
	title: title,
	author: author,
	pub_name: pub_name,
	pub_place: pub_place,
	isbn: isbn,
	class1: class1,
	section: section,
	sub_class: sub_class}),	
	url: "add_book.php",	
	cache: false,
	success: function(response){
	$(".success").fadeIn().html(response); 
		$(".title").removeClass("error");
		$(".author").removeClass("error");
		$(".pub_name").removeClass("error");
		$(".pub_place").removeClass("error");
		$(".isbn").removeClass("error");
		$(".class1").removeClass("error");
		$(".section").removeClass("error");
		$(".sub_class").removeClass("error");
		$(".title").removeClass("error");
		$("input[type='text']").val('');
		$("textarea").val('');
		jQuery('.loading').fadeOut();
	}		
	});
	}
	});
		
		
		$('#btn_header').click( function() {
			var storeName = $('.store_name').val()
			var storeSubName = $('.store_subname').val()
			var copyright = $('.copyright').val()
			var copy = $('.copy').val()
			var address = $('.address').val()
			var email = $('.email').val()
			var phoneNumber = $('.phoneNumber').val()
				$.ajax({
				type: 'POST',
				data: ({
				storeName : storeName,
				storeSubName: storeSubName, 
				address: address,
				email: email,
				phoneNumber: phoneNumber,
				copyright: copyright
				}),
				url: 'update_store_header.php',
				success: function(response){
					alert("Successful Update");
				}
				})	
		})
	
	
});