﻿var currentSedurRequestWindow;

function ShiftClick(shift)
{

    if (currentSedurRequestWindow != undefined)
    {
        $(currentSedurRequestWindow).remove();
        currentSedurRequestWindow = undefined;
    }
    
    
    var autoDiv = document.createElement('div');
    Element.extend(autoDiv);
    autoDiv.addClassName('RequestWindow').hide();
    
    currentSedurRequestWindow = autoDiv.identify();
    autoDiv.setOpacity(0.4);
    
    var demEleTextBox = $(shift).getDimensions();
    var PosEleTextBox = $(shift).positionedOffset();
    
    autoDiv.setStyle({
                        top: (PosEleTextBox.top + demEleTextBox.height - 200 - 20)+"px",
                        left: (PosEleTextBox.left + demEleTextBox.width - 174)+"px"
                     });
    
    var val = ShiftClickAJAX(shift);
    
    autoDiv.insert(val); 
    $("aspnetForm").appendChild(autoDiv);
    
    new Effect.Appear(autoDiv,{duration: 0.3,to: 0.9, afterFinish: function() {
                                                                if ($("txtUserName") != null)
                                                                {
                                                                    $("txtUserName").focus();
                                                                }
                                                                              }
                        });
    
    if (val == null || val == "")
    {
        ClientSedurRequestClose();
    }
    

}

function ClientSedurRequestClose()
{
    if (currentSedurRequestWindow != undefined)
    {
        new Effect.DropOut(
         $(currentSedurRequestWindow),
          {afterFinish: function() {
                         if ($(currentSedurRequestWindow) != undefined)
                         {
                             $(currentSedurRequestWindow).remove();
                         }
                         currentSedurRequestWindow = undefined; 
                         }} 
         );
     
    }
}

function ShiftClickAJAX(shift)
{ 
    var arr = shift.split("_");
    var columnId = arr[1];
    var shiftDate = arr[2] + "/" + arr[3] + "/" + arr[4];

    $("ctl00_ContentPlaceHolder1_hdnMonth").value = arr[3];
    
    var val = SedurAJAX.ShiftClick(shiftDate, columnId);
    if (val.value != null)
    {
        return val.value;
    }
    else
    {
        Modalbox.show(baseUrl + "UI/personal/HTML/LogIn.htm", { title: 'כניסה', width: 300 });
        return "";
    }
}

function SendRequest()
{
    $("btnOk").hide();
    if ($("email").checked || $("sms").checked)
    {
        var sedurPanel = $("SedurPanel");
        
        var userNotification,shiftDate,columnId;
        if ($("email").checked)
        {
            if($("sms").checked)
            {
                userNotification = 3;
            }
            else
            {
                userNotification = 1;            
            }
        }
        else
        {
            userNotification = 2;
        }
        
        shiftDate = $("shiftDate").value;
        columnId = $("columnId").value;

        sedurPanel.replace(SedurAJAX.SendUserNewRequest(shiftDate, columnId, userNotification, null).value);
        __doPostBack('ctl00$ContentPlaceHolder1$lnkRefresh', '');
    }
    else
    {
        $("btnOk").show();
        alert("אנא בחר באיזה אופן תרצה לקבל עדכונים לבקשתך.");
    }
}

function SendRemoveRequest()
{
    $("btnOk").hide();

    var sedurPanel = $("SedurPanel");
    
    var requestId = $("requestId").value;

    sedurPanel.replace(SedurAJAX.SendUserRemoveRequest(requestId).value);
    __doPostBack('ctl00$ContentPlaceHolder1$lnkRefresh', '');
}
