﻿var WaitingForWithdrawResponse = false;
var WaitingForProfileSuccess = false;
var WaitingForFavResponse = false;
var targetProfileList;
var previousSelectedProfileList;
var m_lastFavContentId;


function Withdraw(contentId)
{
    if (WaitingForWithdrawResponse)
        return;
    if(confirm('Do you really want to delete this submission?'))
        {
            SubmissionManagementService.Withdraw(contentId, onWithdrawSuccess, onWithdrawTimeOut, onWithdrawError);
            WaitingForWithdrawResponse = true;            
        }
}


function onWithdrawSuccess(contentId)
{
  WaitingForWithdrawResponse = false;

   setSubmissionBlockText(contentId,'Submission deleted.'); 
}

function onWithdrawError()
{ 
   WaitingForWithdrawResponse = false;
}

function onWithdrawTimeOut()
{   
   WaitingForWithdrawResponse = false;
}



function onSetProfileSuccess(contentId)
{
  WaitingForProfileSuccess = false;
  setProfilePic(contentId)
  targetProfileList.selectedIndex=0;
  targetProfileList = null;
  
}


function onProfileAssign(contentId)
{
  WaitingForProfileSuccess = false;
 setSubmissionBlockText(contentId,'Moved to flirt. The change will be visible in a short while.'); 
  
}

function onProfileAssignPrivate(contentId)
{
  WaitingForProfileSuccess = false;
 
  setSubmissionBlockText(contentId,'Moved to private. The change will be visible in a short while.');
}

function onSetProfileError()
{

   WaitingForProfileSuccess = false;
}

function onSetProfileTimeOut()
{

   WaitingForProfileSuccess = false;
}



function ddlActionChange(ddList, contentId)
{
    var confirmed = false;
    if(!WaitingForProfileSuccess)
    {    
        targetProfileList = ddList;

        /*gives confirm */
        switch(ddList.options[ddList.selectedIndex].value.toLowerCase())
        {
            case 'profile':
               confirmed = confirm( "Do you really want to set this as your profile pic?");
               if(confirmed)
               {
                    /*change profile pic*/
                    WaitingForProfileSuccess = true;
                    SubmissionManagementService.SetProfileSubmission(contentId, onSetProfileSuccess, onSetProfileTimeOut, onSetProfileError);                
                    
                    
               }
               break;
            
            case 'moveflirt':
               confirmed = confirm( "Do you really want to move this to flirt?");
               if(confirmed)
               {
                    /*move to flirt*/
                    SubmissionManagementService.MoveFlirt(contentId, onProfileAssign, onSetProfileTimeOut, onSetProfileError);                
               }
               break;
            
            case 'moveprivate':
                confirmed = confirm( "Do you really want to move this to private?");                
                if(confirmed)
                {
                    /*move to private*/
                    SubmissionManagementService.MovePrivate(contentId, onProfileAssignPrivate, onSetProfileTimeOut, onSetProfileError);                
                }
                break;                     
        
        }
    }
    
    if(!confirmed)        
        ddList.selectedIndex = 0;
}


function RemoveFav(contentId)
{
    if (WaitingForFavResponse)
        return;
    
    m_lastFavContentId = contentId;
    ToggleFavService.ToggleFav(contentId, onRemoveFavSuccess, onRemoveFavTimeOut, onRemoveFavError);
    WaitingForFavResponse = true;
}



function onRemoveFavSuccess(isFav)
{ 
   if(!isFav)
   {
        setSubmissionBlockText(m_lastFavContentId,'Removed from Favs.')
  }
   WaitingForFavResponse = false;
}

function onRemoveFavError()
{ 
   WaitingForFavResponse = false;
}

function onRemoveFavTimeOut()
{   

   WaitingForFavResponse = false;
}


function setSubmissionBlockText(contentId,text)
{

var elementId = 's' + contentId;
    var element = document.getElementById(elementId)
    element.style.height = '174px';
    element.style.width = '194px';
    element.style.paddingTop = '60px';

    element.innerHTML = '<center><div id="pnlNetworkWarning" class="errorBox" style="width:110px;text-align:center;"><img src="images/warningAnim.gif" alt="" /><br /><span>' + text + '</span></div></center>';

}