﻿// This is used in calls in search.js
var websitestring = "delizie";

function init_delizie() {
	$(".printLink").each(function() {
		$(this).click(function() {
			window.print();
			return false;
		});
	});
	$("table.register #change_password").click(function() {
		if ($(this).attr("checked")) {
			$("table.register tr.hide").each(function() {
				$(this).show();
			});
		}
		else {
			$("table.register tr.hide").each(function() {
				$(this).hide();
			});
		}
	});

	$(".recipePush").each(function() {
		$(this).hover(
	    	    function() {
	    	    	$(this).find("img.delete").fadeIn("fast");
	    	    },
	    	    function() {
	    	    	$(this).find("img.delete").fadeOut("fast");
	    	    }
	    	    );
	});
	$(".productPush").each(function() {
		$(this).hover(
	    	    function() {
	    	    	$(this).find("img.delete").fadeIn("fast");
	    	    },
	    	    function() {
	    	    	$(this).find("img.delete").fadeOut("fast");
	    	    }
	    	    );
   	   });

   	   //$('.vAlign').VerticalAlign();
}

// Calls the Zeta web service.
// method (string) - The name of the method to call.
// args (object) - An object with the arguments to the method. An empty object if there are no arguments.
// success (function) - The function to call on success.
// error (function) - The function to call on failure.
function call(method, args, success, error) {
	$.ajax({
		type: 'POST',
		contentType: 'application/json; charset=utf-8',
		url: '/Service.asmx/' + method,
		data: JSON.stringify(args),
		dataType: 'json',
		error: error,
		success: function(data) { success(data.d); }
	});
}

function addrecipe(userid, recipeid) {
	var $this = $(this)
	$.get(location.protocol + '//' + location.hostname + ':' + location.port + "/Recipe.ashx",
    {
    	userid: userid,
    	recipeid: recipeid
    },
    function(data) {
    	var width = $(document).width();
    	var height = $(document).height();
    	var infocontainer = $("#infoContainer");
    	var msg = "";
    	if (data == "OK")
    		msg = "Receptet har lagts till i din samling."
    	if (data == "DENIED")
    		msg = "Ett okänt fel har uppstått. Vänligen kontakta <a href='mailto:admin@delizie.nu'>admin@delizie.nu</a>.";
    	if (data == "ALREADY_EXISTS")
    		msg = "Detta receptet finns redan i din samling.";
    	infocontainer.html(msg);
    	infocontainer.show();

    	infocontainer.css({ left: (width / 2 - infocontainer.width() / 2) + "px", top: (height / 2 - infocontainer.height() / 2) + "px" });
    	infocontainer.fadeOut(4000);
    });
	return false;
}

function addproduct(userid, productid) {
	$.get(location.protocol + '//' + location.hostname + ':' + location.port + "/Product.ashx",
    {
    	userid: userid,
    	productid: productid
    },
    function(data) {
    	var width = $(document).width();
    	var height = $(document).height();
    	var infocontainer = $("#infoContainer");
    	var msg = "";
    	if (data == "OK")
    		msg = "Produkten har lagts till i din samling."
    	if (data == "DENIED")
    		msg = "Ett okänt fel har uppstått. Vänligen kontakta <a href='mailto:admin@delizie.nu'>admin@delizie.nu</a>.";
    	if (data == "ALREADY_EXISTS")
    		msg = "Denna produkt finns redan i din samling.";
    	infocontainer.html(msg);
    	infocontainer.show();

    	infocontainer.css({ left: (width / 2 - infocontainer.width() / 2) + "px", top: (height / 2 - infocontainer.height() / 2) + "px" });
    	infocontainer.fadeOut(4000);
    });
	return false;
}

function deleterecipe(userid, recipeid) {
	if (confirm("Vill du verkligen ta bort detta recept?")) {
		$.get(location.protocol + '//' + location.hostname + ':' + location.port + '/Recipe.ashx',
        {
        	userid: userid,
        	recipeid: recipeid,
        	'delete': true
        },
        function(data) {
        	if (data == 'OK') {
        		window.location.reload();
        	}
        },
        'text');
	}
}
function deleteproduct(userid, productid) {
	if (confirm("Vill du verkligen ta bort denna produkt?")) {
		$.get(location.protocol + '//' + location.hostname + ':' + location.port + '/Product.ashx',
        {
        	userid: userid,
        	productid: productid,
        	'delete': true
        },
        function(data) {
        	if (data == 'OK') {
        		window.location.reload();
        	}
        },
        'text');
	}
}

var addthis_config = {
	ui_cobrand: "DELIZIE",
	ui_offset_top: 15,
	ui_offset_left: -60,
	ui_delay: 200,
	//services_compact: "",
	ui_language: "sv",
	services_exclude: "print"
}

$(function() {
	init_delizie();
});



