﻿var AllowWineScroll = true;
function MoveRight(p_PanelId, p_MaxRight)
{
    if(AllowWineScroll == false) return;
    
    var Counter = 1;
    var left = parseInt(document.getElementById(p_PanelId).style.left.replace("px",""));
    
    if(left < p_MaxRight) return;
    AllowWineScroll  = false;
        
    for (var i = left ; i>left - 586; i=i-5)
    {
        if(i>left -584)
            setTimeout("MoveWines('" + p_PanelId + "', " + i + ", 'false')", 5 * Counter);
        else
            setTimeout("MoveWines('" + p_PanelId + "', " + i + ", 'true')", 5 * Counter);
            
       Counter++;
    }

}
function MoveLeft(p_PanelId)
{
    if(AllowWineScroll == false) return;
    
    var Counter = 1;
    var left = parseInt(document.getElementById(p_PanelId).style.left.replace("px",""));

    if(left >= 0) return;
     AllowWineScroll  = false;

     for (var i = left; i < left + 586; i = i + 5)
    {
       if(i<left + 584)
            setTimeout("MoveWines('" + p_PanelId + "', " + i + ", 'false')", 5 * Counter);
        else
            setTimeout("MoveWines('" + p_PanelId + "', " + i + ", 'true')", 5 * Counter);

       Counter++;
    }

}
function MoveWines(p_PanelId, p_Position, p_Bool)
{
    document.getElementById(p_PanelId).style.left = p_Position + "px";
    if(p_Bool == "true")
        AllowWineScroll = true;
}

function CreateNewMeal() {
    if (CheckLogon() == true) {
        eraseCookie("MealId");
        document.getElementById("WhichControl").value = "NewMeal";
        SetMealId("");
        StartSommelier();
    }
    else {
        if (ShowBalloon() == true) {
            document.getElementById("Register").style.display = "block";
            document.getElementById("RegBgr").style.display = "block";
        }
        else {
            eraseCookie("MealId");
            document.getElementById("WhichControl").value = "NewMeal";
            SetMealId("");
            StartSommelier();
        }
    }
}
function MealDone(MealId)
{
    Url = "http://" + location.host + location.pathname.replace("winesteinresults","winestein");
   
    document.getElementById("Body_Sommelier_btn_CancelSommelierPopup").click();
    if(MealId)
    {
        createCookie("MealId", MealId, 0);
        createCookie("WineSteinBanner", "1", 0);
        location.href = Url;
    }
    else
        createCookie("MealId", "", -1);
}

function passFlashVar(variable) {
    a = document.getElementsByName("flashvars");
    if (a[0] != null && a[0].getAttribute("value") != null) {
        variable = 'SiteId=' + variable;
        a[0].setAttribute("value", variable);
    }
}
function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}
function StartWineStein() {

    var TimeOut = document.getElementById("Body_WineSteinTimeOut").value;
    if (readCookie("WineSteinBanner") == "1") {
        $.post("http://new.winewinewine.com/webservices/Meals.asmx/PrepareMeal");
        setTimeout(WineSteinContinue, TimeOut);
    }
        
    if(readCookie("WineSteinBanner") == "99") //99 is used when coming from frontpage
    {
        setTimeout(StartSommelier,500);        
    }
}

function WineSteinContinue()
{
    createCookie("WineSteinBanner", "2", 0);
    location.reload();
}
function OpenCloseMetaWine (p_PanelId1, p_PanelId2, p_ImageId)
{
    var Image = document.getElementById(p_ImageId);
    var LastIndex = Image.src.lastIndexOf('/'); 
    var Url = Image.src.substring(0, LastIndex);
    
   if(document.getElementById(p_PanelId1).style.display == "none")
   {
       document.getElementById(p_PanelId1).style.display = "block";
       document.getElementById(p_PanelId2).style.display = "block";
        Image.src = Url + "/Arrow_ClosePanel.png";
   }
   else
   {
       document.getElementById(p_PanelId1).style.display = "none";
       document.getElementById(p_PanelId2).style.display = "none";
        Image.src = Url + "/Arrow_OpenPanel.png";
   }
}
function NewMeal ()
{
    eraseCookie("MealId");
    document.getElementById("WhichControl").value = "NewMeal"; 
    document.forms[0].submit();
}
function GetMeal()
{
    document.getElementById("WhichControl").value = "SelectedMeal"; 
    document.forms[0].submit();
}
function SearchMeal()
{
    var Watermark = document.getElementById('Body_lbl_WaterMarkSearchBox').innerHTML;
    var Searchtext = document.getElementById('Body_txt_SearchMeals').value;
    if(Searchtext != "" && Searchtext != Watermark)
    {
        document.getElementById("WhichControl").value = "SearchMeal"; 
        document.forms[0].submit();
    }
}
function ChangeMeal()
{
    document.getElementById("Body_Sommelier_btn_ShowSommelierPopup").click();
}

    
