//////////////////////////////////////////////////////////////////////////////////
/// SHOW BOOK DETAIL
///
function show_book_detail(objid, objtext){
	showLoadingDiv('ajaxloading');
	$('#book_list').load('book_detail.php', {'objid': objid, 'objtext': objtext}, function() {
		$("#ajaxloading").hide('');
		var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		var tabs1 = 'js/tabs/jquery-ui-personalized-1.5.2.packed.js';
		var tabs2 = 'js/tabs/sprinkle.js';
		
		//var ajaxfunction = 'js/function_ajax.js';
		
		if (window.addthis){
			window.addthis = null;
		}
		$.getScript( script );
		$.getScript( tabs1 );
		$.getScript( tabs2 );
		//$.getScript( ajaxfunction );
	});

	return false;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
/// SHOW eBOOK DETAIL
///
function show_ebook_detail(objid, objtext){
	showLoadingDiv('ajaxloading');
	$('#book_list').load('ebook_detail.php', {'objid': objid, 'objtext': objtext}, function() {
		$("#ajaxloading").hide('');
		var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		var tabs1 = 'js/tabs/jquery-ui-personalized-1.5.2.packed.js';
		var tabs2 = 'js/tabs/sprinkle.js';
		
		//var ajaxfunction = 'js/function_ajax.js';
		
		if (window.addthis){
			window.addthis = null;
		}
		$.getScript( script );
		$.getScript( tabs1 );
		$.getScript( tabs2 );
		//$.getScript( ajaxfunction );
	});
	
	return false;
}
function show_journal_detail(objid, objtext){
	showLoadingDiv('ajaxloading');
	$('#book_list').load('journal_details.php', {'objid': objid, 'objtext': objtext}, function() {
		$("#ajaxloading").hide('');
		var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		var tabs1 = 'js/tabs/jquery-ui-personalized-1.5.2.packed.js';
		var tabs2 = 'js/tabs/sprinkle.js';
		
		//var ajaxfunction = 'js/function_ajax.js';
		
		if (window.addthis){
			window.addthis = null;
		}
		$.getScript( script );
		$.getScript( tabs1 );
		$.getScript( tabs2 );
		//$.getScript( ajaxfunction );
	});
	
	return false;
}


function add_cart(idbook, iduser, type, id_showinfo){ 
	showLoadingDiv('ajaxloading');
	var html_query = "";
	html_query += 'task=addcart' + '&objid=' + idbook + '&iduser=' + iduser + '&type=' + type;
	
	$.ajax({
		url: 'ajax.php',
		type: 'POST',
		cache: false,
		data: html_query,
		success: function(string){
			
			$("#"+id_showinfo).show();
			
			if(string=="1"){
				if(type==3)
					$("#"+id_showinfo).text("This article was added to your cart!");
				else
					$("#"+id_showinfo).text("This book was added to your cart!");
				
				amount = parseInt($("#cart_item").text())+1;
				$("#cart_item").text( amount );
				//$("#cart_item_top").text( amount );
			}
			if(string=="3"){
				$("#"+id_showinfo).text("This item is already added to your cart.");
			}
			else{
				//alert('Có lỗi xảy ra');
			}
		}
	});
	$("#ajaxloading").hide('');
	
	return false;
}




function show_procedure_login(idblock){
	$("#ajaxloading").show('');
	$('#'+idblock).load('login_signup.php', function() {
		$("#ajaxloading").hide('');
	});
	return false;
}


function add_wishlist(iduser, idbook, type){
	$.ajax({
		  url: 'ajax.php',
		  type: 'POST',
		  cache: false,
		  data: 'task=addwishlist&iduser=' + iduser + '&idbook=' + idbook + '&type=' + type,
		  success: function(data) {
		    if(data==1){
		    	if( type=="1" )
		    		$("#w_info").html("This book was added successfully");
		    	if( type=="2" )
		    		$("#w_info").html("This eBook was added successfully");
		    	if( type=="3" )
		    		$("#w_info").html("This Journal was added successfully");
		    }
		    else{
		    	$("#w_info").html("There are some error, please try again!");
		    }
		    $("#chk_status").val(data);
		  }
	});
	return false;
}

function delwishlist(id, idobj, iduser){
	$("#w_ajax_loading").show();
	$.ajax({
		  url: 'ajax.php',
		  type: 'POST',
		  cache: false,
		  data: 'task=delwishlist&idobj=' + idobj + '&iduser=' + iduser,
		  success: function(data) {
		    if(data==1){
		    	$("#wlist_" + id).remove(); 
		    }
		    else{
		    	;
		    }
		    
		    $("#w_ajax_loading").hide();
		  }
	});
	
	return false;
}

function delwishlist_article(id, iduser){
	$("#w_ajax_loading").show();
	$.ajax({
		  url: 'ajax.php',
		  type: 'POST',
		  cache: false,
		  data: 'task=delwishlist_article&id=' + id + '&iduser=' + iduser,
		  success: function(data) {
		    if(data==1){
		    	$("#wishlist_article_" + id).remove(); 
		    }
		    else{
		    	;
		    }
		    
		    $("#w_ajax_loading").hide();
		  }
	});
	
	return false;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
/// ADD WISHLIST ARTICLE
///
function addwishlist_article(id_user, id_journal, id_article){
	$("#w_article_info").html("");
	$.ajax({
		  url: 'ajax.php',
		  type: 'POST',
		  cache: false,
		  data: 'task=addwishlist_article&id_user=' + id_user + '&id_journal=' + id_journal + '&id_article=' + id_article,
		  success: function(data) {
		    if(data==1){
		    	$("#w_article_info").html("This Article was added successfully");
		    }
		    else{
		    	$("#w_article_info").html("There is some error when add.");
		    }
		  }
	});
	
	return false;
}

function show_journal(objid, objtext){
	$("#ajaxloading").show("");
	$('#book_list').load('show_journalby_sub_area.php', {'objid': objid, 'objtext': objtext}, function() {
		$("#ajaxloading").hide('');
	});
	
	return false;
}


function update_price(idquality, id, original_price){
	//fnl_total
	
	frst_price = $("#m_price_"+id).text();
	frst_price = parseFloat(frst_price);
	
	fnl_price = ($("#fnl_total").text());
	fnl_price = parseFloat(fnl_price);
	
	
	$("#img_price_"+id).show();
	var quality = $("#"+idquality).val();
	original_price = parseFloat(original_price);
	
	$.ajax({
		  url: 'ajax.php',
		  type: 'POST',
		  cache: false,
		  data: 'task=update_price&id=' + id + '&quality=' + quality,
		  success: function(data) {
		    if(data==1){
		    	price = parseFloat(quality) * (original_price.toFixed(2));
		    	
	    		fnl_price = ( (fnl_price - frst_price) + price );
	    		$("#fnl_total").text( fnl_price.toFixed(2) );

		    	
		    	$("#m_price_"+id).text( price.toFixed(2) );
		    	$("#img_price_"+id).hide();
		    }
		    else{
		    	$("#img_price_"+id).hide();
		    }
		  }
	});
}

function delcart_item(id){
	$("#img_price_"+id).show();
	$.ajax({
		  url: 'ajax.php',
		  type: 'POST',
		  cache: false,
		  data: 'task=del_price&id=' + id,
		  success: function(data) {
		    if(data==1){
		    	$("#tbl_price_" + id).remove(); 
		    	$("#img_price_"+id).hide();
		    }
		    else{
		    	$("#img_price_"+id).hide();
		    }
		  }
	});
	
	return false;
}

