/*
###################################
#           FusionCMS v5          #
# - - - - - - - - - - - - - - - - #
#   Made by Jesper of raxezdev    #
###################################
*/

var items = 0;
var totalvp = 0;
var totaldp = 0;
var cmd = "";
var cart_html;

function shop_reset() {
	items = 0;
	totalvp = 0;
	totaldp = 0;
	cmd = "";
	cart_html = "";
	document.getElementById("cart_items").innerHTML = "";
	
	shop_update();
}

function shop_update() {
	$("#totalvp").html(totalvp + " vp");
	$("#totaldp").html(totaldp + " dp");
	$("#cart_itemcount").html(items + " items");
}

function shop_add(id, name, vp, dp, realm) {
	cmd += id + ":" + realm + ",";
	
	var cost;
	
	if(vp == 0) {
		cost = '<td class="dp">' + dp + ' dp</td>';
		totaldp = totaldp + dp;
	} else { 
		cost = '<td class="vp">' + vp + ' vp</td>';
		totalvp = totalvp + vp; 
	}
	
	if(items == 0) {
		cart_html = '<table class="table" width="100%"><tr class="stats_top"><td width="55%">Item</td><td width="15%">Price</td></tr><tr><td>' + name +'</td>' + cost + '</tr>';
	} else {
		cart_html += '<tr><td>' + name + '</td>' + cost + '</tr>';
	}
	
	items = items + 1;
	
	shop_update_cart_html()
}

function shop_update_cart_html() {
	document.getElementById("cart_items").innerHTML = cart_html + "</table>";
	shop_update();
}

function shop_show(name, info) {
	$("#current_item").html("<center><b>" + name +"</b></center>" + Base64.decode(info));
}

function shop_next() {
	if(cmd != "") {
		$("#itemshop").html("<div id='checkout'></div><center><img src='theme/" + theme + "/images/ajax.gif' /></center>");
		
		$.get("inc/itemshop_checkout.php", { cart: cmd}, function(data){
			$("#itemshop").html("<div id='checkout'></div>");
			$("#checkout").html(data);
			$("#checkout").show("fast");
		});
	}
}

function shop_checkout() {
	var char1 = "z";
	var char2 = "z";
	var char3 = "z";
	
	if(document.getElementById("character_1")) {
		char1 = document.getElementById("character_1").value;
	}
	
	if(document.getElementById("character_2")) {
		char2 = document.getElementById("character_2").value;
	}
	
	if(document.getElementById("character_3")) {
		char3 = document.getElementById("character_3").value;
	}
	
	$("#checkout").hide("fast", function(){ 
		$("#itemshop").html("<div id='checkout'></div><center><img src='theme/" + theme + "/images/ajax.gif' /></center>");
		
		$.get("inc/itemshop_do_checkout.php", { cart: cmd, char1: char1, char2: char2, char3: char3 }, function(data){
			$("#itemshop").html("<div id='checkout'></div>");
			$("#checkout").html(data);
			$("#checkout").show("fast");
		});
	});
}

function vote(id, site) {
	
	site = window.open("vote.php?v=" + site + "&id=" + id);
	
	$("#v" + id).html("<img src='theme/" + theme + "/images/loading_vote.gif' />")
}

function vote_done(id) {
	$("#v" + id).html("-")
}
