
function PopUp(URL,name,w,h) {
	x = (screen.width) ? (screen.width-w)/2 : 0;
	y = (screen.height) ? (screen.height-h)/3 : 0;
	attributes='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+w+',height='+h+',left='+x+',top='+y;
	win = window.open(URL,name,attributes);
	win.focus();
}

function LoadPage(url, id, scrolltop) {
	if (scrolltop) window.scrollTo(0,0);
	$("#"+id).html('<div align="center"><img src="images/ajax-loader.gif" width="32" height="32"></div>');
	$("#"+id).load(url);
}

/* USER */

function EnableLogin() {

	$("#FormLogin").submit(function(event) {

		event.preventDefault(); // prevent form to submit via browser

		var Username = $("#Username").attr("value");
		var Password = $("#Password").attr("value");

		$("#user_message").text("Loading...");

		$.post("command.php", {Command: 'UserLogin', Username: Username, Password: Password}, function(data, textStatus) {
			if (textStatus == "success") {
			
				if (data == "1") {

					//$sidetabs.tabs('load', 0);
					
					top.location.reload();


				} else {
					$("#user_message").text("Username oder Passwort falsch!");
				}

			} else {
				$("#user_message").text("Fehler bei Anmeldung.");
			}
		});
	});
}

function UserLogout() {

	$("#user_message").text("Loading...");

	$.post('command.php', {Command: 'UserLogout'}, function(data, textStatus) {
		if (textStatus == "success") {

			//$sidetabs.tabs('load', 0);

			top.location.reload();

		} else {
			$("#user_message").text("Fehler bei Abmeldung.");
		}
	});
}


/* SHOP */
/*
function LoadVinylList(Type) {

	switch (Type) {

		case 'News':
			var CatID = $("#News_CatID").attr("value");
			var OnlyWithTracks = $("#News_OnlyWithTracks").attr("checked");
			var DateIncoming = $("#News_DateIncoming").attr("value");
			var SearchKeyword = '';
			break;

		case 'Presale':
			var CatID = $("#Presale_CatID").attr("value");
			var OnlyWithTracks = $("#Presale_OnlyWithTracks").attr("checked");
			var DateIncoming = '';
			var SearchKeyword = '';
			break;

		case 'Search':
			var CatID = $("#Search_CatID").attr("value");
			var OnlyWithTracks = $("#Search_OnlyWithTracks").attr("checked");
			var DateIncoming = '';
			var SearchKeyword = $("#Search_Keyword").attr("value");
			break;
	}


}
*/

function GetVinylNews() {

	var CatID = $("#News_CatID").attr("value");
	var OnlyWithTracks = $("#News_OnlyWithTracks").attr("checked");
	var DateIncoming = $("#News_DateIncoming").attr("value");
	var SearchKeyword = '';
	var Page = 1;

	LoadPage('shop_vinyls_list.php?CatID='+CatID+'&OnlyWithTracks='+OnlyWithTracks+'&DateIncoming='+DateIncoming+'&SearchKeyword='+SearchKeyword+'&Page='+Page, 'articles', true);
}

function GetVinylPresale() {

	var CatID = $("#Presale_CatID").attr("value");
	var OnlyWithTracks = $("#Presale_OnlyWithTracks").attr("checked");
	var DateIncoming = '';
	var SearchKeyword = '';
	var Page = 1;

	LoadPage('shop_vinyls_list.php?CatID='+CatID+'&OnlyWithTracks='+OnlyWithTracks+'&DateIncoming='+DateIncoming+'&SearchKeyword='+SearchKeyword+'&Page='+Page, 'articles', true);
}

function GetVinylSearch() {

	var CatID = $("#Search_CatID").attr("value");
	var OnlyWithTracks = $("#Search_OnlyWithTracks").attr("checked");
	var DateIncoming = '';
	var SearchKeyword = $("#Search_Keyword").attr("value");
	var Page = 1;

	var url = 'shop_vinyls_list.php?CatID='+CatID+'&OnlyWithTracks='+OnlyWithTracks+'&DateIncoming='+DateIncoming+'&SearchKeyword='+escape(SearchKeyword)+'&Page='+Page;

	LoadPage(url, 'articles', true);
}

function GetShirts() {

	var CatID = $("#CatID").attr("value");
	var SearchKeyword = $("#Keyword").attr("value");
	var Page = 1;

	LoadPage('shop_shirts_list.php?CatID='+CatID+'&SearchKeyword='+SearchKeyword+'&Page='+Page, 'articles', true);

}

/* BASKET */

/*
function OrderAddItem(ItemSource, ItemID) {

	//$("#shopboxes").accordion("activate", 2);

	$.post('command.php', {Command: 'OrderAddItem', ItemSource: ItemSource, ItemID: ItemID}, function(data, textStatus) {
		if (textStatus == "success") {

			$sidetabs.tabs("select", 1);
			$sidetabs.tabs("load", 1);

			//LoadPage("order_basket_info.php", "basket", false);


		} else {
			$("#user_message").text("Fehler!");
		}
	});

}
*/

function OrderAddItem() {

	var fields = $(":input", document['FormOrderOptions']).serializeArray();

	$.post('command.php', fields, function(data, textStatus) {
		if (textStatus == "success") {
			$order_options.dialog('close');
			$sidetabs.tabs('select', 1);
			$sidetabs.tabs('load', 1);

			$("#debug").html(data);


		} else {
			$("#user_message").text("Fehler!");
		}
	});
}

function OrderAddItem_Options(ItemSource, ItemID) {

	LoadPage('order_options.php?ItemSource='+ItemSource+'&ItemID='+ItemID, 'order_options', false);
	$order_options.dialog('open');

}


/* PLAYER */

function GetPlayerID(gid) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[gid];
	} else {
		return document[gid];
	}
}

function LoadTrack(TrackID) {
	LoadPage('player.php?TrackID='+TrackID, 'player2', false);
	$player.dialog('open');
}

// TEST

function PlayTrack(url) {
	var player = GetPlayerID('mpl');
	setTimeout("player.sendEvent('LOAD', {file:'"+url+"'})", 500);
	setTimeout("player.sendEvent('PLAY')", 100);
}


function WishlistAdd(ArticleID) {

	$.post('command.php', {Command: 'WishlistAdd', ArticleID: ArticleID}, function(data, textStatus) {
		if (textStatus == "success") {
			alert(data);
		} else {
			$("#user_message").text("Fehler!");
		}
	});
}

function WishlistRemove(ArticleID) {

	$.post('command.php', {Command: 'WishlistRemove', ArticleID: ArticleID}, function(data, textStatus) {
		if (textStatus == "success") {

			location.href = "/wishlist";
			
		} else {
			$("#user_message").text("Fehler!");
		}
	});
}


