﻿$(function () {
	$('input.watchlist').change(function () {
		var action = "";
		if ($(this).attr("checked")) {
			action = "Add";
		} else {
			action = "Remove";
		}
		var id = $(this).attr("id");
		$(this).prev().show();
		$(this).hide();

		$.ajax({
			url: "/AsWebService.asmx/Watchlist_" + action,
			dataType: "json",
			type: "POST",
			contentType: "application/json; charset=uft-8",
			data: "{ArtNr:'" + $(this).next().find(".wartnr").html() + "'}",
			success: function (data) {
				if ((action == "Add" && data.d == "true") || (action == "Remove" && data.d == "true")) {
					//$('#' + id).next().find(".wtxt").effect('highlight', { color: "#267F00" }, 2500);
					$('#' + id).next().find(".wtxt").toggleClass("wSuccess", 500);
					setTimeout("$('#" + id + "').next().find('.wtxt').toggleClass('wSuccess');", 2000);
				}
				else {
					//$('#' + id).next().find(".wtxt").effect('highlight', { color: "#FFDDDD" }, 2500);
					$('#' + id).next().find(".wtxt").toggleClass("wError", 500);
					setTimeout("$('#" + id + "').next().find('.wtxt').toggleClass('wError');", 2000);
				}
				$('#' + id).prev().hide();
				$('#' + id).show();
			},
			error: function (x, y, z) {
				//alert(x.responseText);
				$('#' + id).prev().hide();
				$('#' + id).show();
			}
		});
		//var old_txt = $(this).next().find(".wtxt").html();
		//var new_txt = $(this).next().find(".hidden").html();
		//$(this).next().find(".wtxt").html(new_txt);
		//$(this).next().find(".hidden").html(old_txt);
	});
});

function CreateWatchListSelector() {
	$('input.watchlist').change(function () {
		var action = "";
		if ($(this).attr("checked")) {
			action = "Add";
		} else {
			action = "Remove";
		}
		var id = $(this).attr("id");
		$(this).prev().show();
		$(this).hide();

		$.ajax({
			url: "/AsWebService.asmx/Watchlist_" + action,
			dataType: "json",
			type: "POST",
			contentType: "application/json; charset=uft-8",
			data: "{ArtNr:'" + $(this).next().find(".wartnr").html() + "'}",
			success: function (data) {
				if ((action == "Add" && data.d == "true") || (action == "Remove" && data.d == "true")) {
					//$('#' + id).next().find(".wtxt").effect('highlight', { color: "#267F00" }, 2500);
					$('#' + id).next().find(".wtxt").toggleClass("wSuccess", 500);
					setTimeout("$('#" + id + "').next().find('.wtxt').toggleClass('wSuccess');", 2000);
				}
				else {
					//$('#' + id).next().find(".wtxt").effect('highlight', { color: "#FFDDDD" }, 2500);
					$('#' + id).next().find(".wtxt").toggleClass("wError", 500);
					setTimeout("$('#" + id + "').next().find('.wtxt').toggleClass('wError');", 2000);
				}
				$('#' + id).prev().hide();
				$('#' + id).show();
			},
			error: function (x, y, z) {
				//alert(x.responseText);
				$('#' + id).prev().hide();
				$('#' + id).show();
			}
		});
		//var old_txt = $(this).next().find(".wtxt").html();
		//var new_txt = $(this).next().find(".hidden").html();
		//$(this).next().find(".wtxt").html(new_txt);
		//$(this).next().find(".hidden").html(old_txt);
	});

}
