﻿function DoAjaxRequest(action, args)
{
    var xmlHttp = GetHttpRequest();
    if (xmlHttp == null)
        return false;
        
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if (action != 2)
                ShowPopupMessage(xmlHttp.responseText);
            else
            {
                var argsSplit = args.split('|');
                var image = document.getElementById('TopWine' + argsSplit[1]);
                if (image != null)
                {
                    image.src = "../Images/UcWine/img_coeur.jpg";
                    image.style.visibility = "visible";
                }
                else
                    ShowPopupMessage(xmlHttp.responseText);
            }
            return false;
        }
    }

    //Since all pages are located within a single folder, go up one folder
    xmlHttp.open("GET", "../AjaxRequest.aspx?Action=" + action + "&Args=" + args, true);
    xmlHttp.send(null);
}

function AddContact(culture, memberOid)
{
    DoAjaxRequest(1, culture + "|" + memberOid);
}

function AddToTopWines(culture, vintageOid, vintageGroupOid)
{
    DoAjaxRequest(2, culture + "|" + vintageOid + "|" + vintageGroupOid);
}

function AddToSelection(culture, vintageOid, vintageGroupOid)
{
    DoAjaxRequest(3, culture + "|" + vintageOid + "|" + vintageGroupOid);
}
