﻿<!-- 
// javascript functions used by mockart studio gallery (shur * 06.18.2009)

var visibleThumbnails = 6;
var currPictId = 0;
var firstThumbNailId = 0;
var image_mattrix_length = 0;
var disp_msg_ms = 5000;
var messagBoard = null;
var toutClearBrd = null;
var currContestActionLink = null;

var voteIcons      = null;
var dYourVote      = null;
var yourVote       = null;
var currThumbNail  = null;
var voteImgPreview = null;
var titleAndAuthor = null;
var saveTitle      = null;
var imageComment   = null;
var ckbStatus      = null;
var deleteLink     = null;
var statusLink     = null;
var statusLabel    = null;

var linkEditPicture    = null;
var linkEditPicture_lc = null;


var nbStepNext     = null;
var nbStepBack     = null;
var nbJumpNext     = null;
var nbJumpBack     = null;

var nbStepNext_locked = null;
var nbStepBack_locked = null;
var nbJumpNext_locked = null;
var nbJumpBack_locked = null;

function ClickThumbnail(tn)
{
    ShowNewPicture((firstThumbNailId + tn) - currPictId);
}

function ClickStepNavBut(step)
{
    var nextPictId = currPictId + step;
    
    if(nextPictId < firstThumbNailId || nextPictId >= firstThumbNailId + visibleThumbnails)
    {
        LoadThumbNails(step);
    }
    else
    {
        ShowNewPicture(step);
    }
}

function ShowNewPicture(step)
{
    if(voteImgPreview == null) voteImgPreview = GetObject('voteImgPreview');

    if(typeof image_mattrix === 'undefined' || image_mattrix == null) 
    {
        if(voteImgPreview != null) voteImgPreview.src = 'image/title_thank_you.png'
        return;
    }
    if(image_mattrix_length == 0) image_mattrix_length = image_mattrix.length;
    
    var nextPictId = currPictId + step;
    
    if(nextPictId < 0) nextPictId = 0;
    if(nextPictId >= image_mattrix_length)  document.location.href = document.location.href;

    currPictId = nextPictId;
    
    if(voteImgPreview != null) voteImgPreview.src = imgSrcPrefix + image_mattrix[currPictId][0];    
    
    HighlightActiveTumbNail();
    RepaintNavigationControls();
    RepaintDetails(step);
    RepaintRateBoard();
    RepaintComments();
}

function RepaintNavigationControls()
{
////////////////////////////////////////////////////////////////////////////////////////////
/// navigation controls

    if(nbStepNext == null) nbStepNext = GetObject('nbStepNext');
    if(nbStepBack == null) nbStepBack = GetObject('nbStepBack');
    if(nbJumpNext == null) nbJumpNext = GetObject('nbJumpNext');
    if(nbJumpBack == null) nbJumpBack = GetObject('nbJumpBack');

    if(nbStepNext_locked == null) nbStepNext_locked = GetObject('nbStepNext_locked');
    if(nbStepBack_locked == null) nbStepBack_locked = GetObject('nbStepBack_locked');
    if(nbJumpNext_locked == null) nbJumpNext_locked = GetObject('nbJumpNext_locked');
    if(nbJumpBack_locked == null) nbJumpBack_locked = GetObject('nbJumpBack_locked');

    if(voteIcons == null) voteIcons = GetObject('voteIcons');
    
    // JUMP BACK BUTON
    if(nbJumpBack != null && nbJumpBack_locked != null)
    {
        if( firstThumbNailId <= 0 || voteIcons != null) // lock
        { 
            nbJumpBack.style.display = 'none'; 
            nbJumpBack_locked.style.display = ''; 
        }
        else ///////////////////////////////////////////// unlock
        {
            nbJumpBack.style.display = ''; 
            nbJumpBack_locked.style.display = 'none'; 
        }
    }  
    
    // STEP BACK BUTON
    if(nbStepBack != null && nbStepBack_locked != null) 
    {
        if(currPictId == 0 || voteIcons != null) ///////// lock
        { 
            nbStepBack.style.display = 'none'; 
            nbStepBack_locked.style.display = ''; 
        }
        else ///////////////////////////////////////////// unlock
        {
            nbStepBack.style.display = ''; 
            nbStepBack_locked.style.display = 'none'; 
        }
    }  

    // STEP NEXT BUTON
    if(nbStepNext != null && nbStepNext_locked != null) 
    {
        if(currPictId >= (image_mattrix_length - 1)) ///////// lock
        { 
            nbStepNext.style.display = 'none'; 
            nbStepNext_locked.style.display = ''; 
        }
        else ///////////////////////////////////////////// unlock
        {
            nbStepNext.style.display = ''; 
            nbStepNext_locked.style.display = 'none'; 
        }
    }  


    // JUMP NEXT BUTON
    if(nbJumpNext != null && nbJumpNext_locked != null) 
    {
        if(firstThumbNailId + visibleThumbnails >= image_mattrix_length || voteIcons != null) // lock
        { 
            nbJumpNext.style.display = 'none'; 
            nbJumpNext_locked.style.display = ''; 
        }
        else ///////////////////////////////////////////// unlock
        {
            nbJumpNext.style.display = ''; 
            nbJumpNext_locked.style.display = 'none'; 
        }
    }  
}

function RepaintDetails(step)
{
    if(titleAndAuthor == null) titleAndAuthor = GetObject('titleAndAuthor');
    if(titleAndAuthor == null) { return; }
    
    if(step == 0)   toutClearBrd = window.setTimeout("ClearStudioMessage()", disp_msg_ms);
    else            ClearStudioMessage();
    
    var title  = Trim(image_mattrix[currPictId][3]);
    
    if( titleAndAuthor.type == 'text')
    {
        titleAndAuthor.value = title;
        
        RepaintStatus();
        RepaintContestActionLink();
        RepaintContestSentToName();
    }
    else
    {
        var author = Trim(image_mattrix[currPictId][4]);
        
        if((title != '' && title != '[new]') || author != '')
        {
            if(title == '' || title == '[new]') title = 'Picture';
            
            title = '<b>' + title + '</b><br/>';
        }

        titleAndAuthor.innerHTML = title + author;
    }
}

function RepaintContestActionLink()
{
    if(currContestActionLink == null)
    {
        if(GetObject('pfSpan_0') == null) return;
    }
    else 
    {
        currContestActionLink.style.display = 'none';
    }
    
    var status = Trim(image_mattrix[currPictId][5]);
    
    var pf = (status == '3' || status == '4') ? '4' : Trim(image_mattrix[currPictId][7]);
    
    currContestActionLink = GetObject('pfSpan_' + pf);
    
    if(currContestActionLink != null) currContestActionLink.style.display = '';
}

function RepaintContestSentToName()
{
    if(sentToBrd == null) sentToBrd  = GetObject('sentToBrd');
    if(sentToBrd != null) 
    {
        if(image_mattrix[currPictId][8] == '' && image_mattrix[currPictId][9] == '')
        {
            sentToBrd.innerHTML = '';
        }
        else
        {
            sentToBrd.innerHTML = 'You sent this piscture to: ' + image_mattrix[currPictId][8] + '&nbsp;'  + image_mattrix[currPictId][9];
        }
    }
    
}

function RepaintStatus()
{
    if(statusLink  == null) statusLink  = GetObject('Status_link');
    if(statusLabel == null) statusLabel = GetObject('Status_lable');
    if(ckbStatus   == null) ckbStatus   = GetObject('Status');
    if(deleteLink  == null) deleteLink  = GetObject('deleteLink');
    if(saveTitle   == null) saveTitle   = GetObject('saveTitle');
    
    if(titleAndAuthor     == null) titleAndAuthor     = GetObject('titleAndAuthor');
    if(linkEditPicture    == null) linkEditPicture    = GetObject('linkEditPicture');
    if(linkEditPicture_lc == null) linkEditPicture_lc = GetObject('linkEditPicture_lc');

    
    var status = Trim(image_mattrix[currPictId][5]);
    var rating = Trim(image_mattrix[currPictId][6]);

    if(isNaN(status))   status = '-100';
    if(rating == '' || isNaN(rating))   rating = '0';
    
    switch(status)
    {
        case '0':   //////////////////////// New
            ckbStatus.style.display   = '';
            ckbStatus.checked         = false;

            statusLink.style.display  = '';
            statusLabel.style.display = 'none';
            statusLabel.innerHTML     = '';

            deleteLink.style.display  = '';

            linkEditPicture.style.display    = '';
            linkEditPicture_lc.style.display = 'none';
            
            titleAndAuthor.style.border = 'solid 1px #c0c0c0';
            titleAndAuthor.readOnly = false;
            saveTitle.style.display = '';

        break;


        case '1':   //////////////////////// Finished
            ckbStatus.style.display   = '';
            ckbStatus.checked         = true;

            statusLink.style.display  = '';
            statusLabel.style.display = 'none';
            statusLabel.innerHTML     = '';

            deleteLink.style.display  = '';

            linkEditPicture.style.display    = 'none';
            linkEditPicture_lc.style.display = '';

            titleAndAuthor.style.border = 'solid 1px #ffffff';
            titleAndAuthor.readOnly = true;
            saveTitle.style.display = 'none';

        break;


        case '2':   //////////////////////// Published
            ckbStatus.style.display   = 'none';
            ckbStatus.checked         = true;

            statusLink.style.display  = 'none';
            statusLabel.style.display = '';
            statusLabel.innerHTML     = 'This Picture is Published <br/>It has a Rating of: <b>' + rating + '</b>';

            deleteLink.style.display  = '';

            linkEditPicture.style.display    = 'none';
            linkEditPicture_lc.style.display = '';

            titleAndAuthor.style.border = 'solid 1px #ffffff';
            titleAndAuthor.readOnly = true;
            saveTitle.style.display = 'none';

        break;


        case '3':   //////////////////////// Archived
            ckbStatus.style.display   = 'none';
            ckbStatus.checked         = true;

            statusLink.style.display  = 'none';
            statusLabel.style.display = '';
            statusLabel.innerHTML     = 'This Picture is Archived <br/>It has a Rating of: <b>' + rating + '</b>';
            
            deleteLink.style.display  = 'none';

            linkEditPicture.style.display    = 'none';
            linkEditPicture_lc.style.display = '';

            titleAndAuthor.style.border = 'solid 1px #ffffff';
            titleAndAuthor.readOnly = true;
            saveTitle.style.display = 'none';

        break;


        case '4':   //////////////////////// Blocked
            ckbStatus.style.display   = 'none';
            ckbStatus.checked         = false;

            statusLink.style.display  = 'none';
            statusLabel.style.display = '';
            statusLabel.innerHTML     = 'This Picture is Blocked';
            
            deleteLink.style.display  = 'none';

            linkEditPicture.style.display    = 'none';
            linkEditPicture_lc.style.display = '';

            titleAndAuthor.style.border = 'solid 1px #ffffff';
            titleAndAuthor.readOnly = true;
            saveTitle.style.display = 'none';

        break;

        case '5':   //////////////////////// Protected
            ckbStatus.style.display   = 'none';
            ckbStatus.checked         = true;

            statusLink.style.display  = 'none';
            statusLabel.style.display = '';
            statusLabel.innerHTML     = 'This Picture is Published <br/>It has a Rating of: <b>' + rating + '</b>';

            deleteLink.style.display  = 'none';

            linkEditPicture.style.display    = 'none';
            linkEditPicture_lc.style.display = '';

            titleAndAuthor.style.border = 'solid 1px #ffffff';
            titleAndAuthor.readOnly = true;
            saveTitle.style.display = 'none';

        break;

        default:
            ckbStatus.style.display   = 'none';
            ckbStatus.checked         = false;
            statusLink.style.display  = 'none';
            statusLabel.style.display = 'none';
            statusLabel.innerHTML     = '';
            deleteLink.style.display  = 'none';
            linkEditPicture.style.display    = 'none';
            linkEditPicture_lc.style.display = '';
            titleAndAuthor.readOnly = true;
            saveTitle.style.display = 'none';

    }
}


function RepaintRateBoard()
{
    // picRateMsgBrd
    if(image_mattrix[currPictId][2] == 0)
    {
        var picRateMsgBrd = GetObject('picRateMsgBrd');
        if(picRateMsgBrd != null) picRateMsgBrd.innerHTML = currPictId == 0 ? 'This Picture is the Leader!' : 'This Picture is #' + (currPictId + 1).toString();
    }
}

function LoadThumbNails(step)
{
    if(typeof image_mattrix === 'undefined' || image_mattrix == null) return;
    if(image_mattrix_length == 0) image_mattrix_length = image_mattrix.length;

    var tn = null, tf = null;
    var n = 0;
    
    if(visibleThumbnails > image_mattrix_length)                                    visibleThumbnails = image_mattrix_length;
    else if(firstThumbNailId + visibleThumbnails + step >= image_mattrix_length)    step = image_mattrix_length - firstThumbNailId - visibleThumbnails;
    else if(firstThumbNailId + step < 0)                                            step = - 1 * firstThumbNailId;

    
    firstThumbNailId += step;

    for(n = 0; n < visibleThumbnails; n++)
    {
        tn = GetObject('tn_' + n);
        if(tn != null) { tn.src = 'image/blank.png'; }
    }
    
    for(n = 0; n < visibleThumbnails; n++)
    {
        tn = GetObject('tn_' + n);
        tf = GetObject('tf_' + n);
        
        if(tn == null || tf == null) { continue; }

        if(firstThumbNailId + n >= image_mattrix_length) 
        {
            tn.src = 'image/blank.png';
            tf.style.display = 'none'; 
         
       }
        else
        {
            tn.src = tbnSrcPrefix + image_mattrix[firstThumbNailId + n][0];
            tf.style.display = ''; 
        }
    }

    ShowNewPicture(step);
}

function HighlightActiveTumbNail()
{
    var n = currPictId - firstThumbNailId;    
    
    if(n < 0) { n = 0; }
    if(n > visibleThumbnails) { n = visibleThumbnails; }

    if(currThumbNail != null) { currThumbNail.style.borderColor = '#ffffff'; }
    
    currThumbNail = GetObject('tn_' + n);
    if(currThumbNail != null) { currThumbNail.style.borderColor = '#fe9020'; }
}

function Vote(rate)
{
    if(jack_count != 0 || image_mattrix[currPictId][2] == '0') return;
    jack_count = 1;

    var attributes = vote_attributes.replace('[imgId]', image_mattrix[currPictId][2]).replace('[rate]', rate);

    image_mattrix[currPictId][1] = rate;
    image_mattrix[currPictId][2] = '0';
    
    LoadJack(attributes);

    DispErrMsg('','voteMsgSpan');
    
    jack_wt = window.setTimeout('GetGalleryVoteConfirmation()', jack_timeout * 2);
}

function GetGalleryVoteConfirmation()
{
    jack_count++;  
    if(jack_count > jack_limit) 
    {
        jack_count = 0;
        image_mattrix[currPictId][1] = 0;
        DispErrMsg('Vote failed.','voteMsgSpan');
    }
    else if(typeof jack_status !== 'undefined' && jack_status.indexOf('error: ') >= 0) 
    {
        jack_count = 0;
        image_mattrix[currPictId][1] = 0;
        DispErrMsg(jack_status.replace('error: ',''),'voteMsgSpan');
    }
    else if(typeof jack_status !== 'undefined' && jack_status == sent_status)
    {
        DispErrMsg('Vote Accepted','voteMsgSpan');
        ShowNewPicture(1);
        jack_count = 0;
        window.setTimeout("ClearVoteMessage()", disp_msg_ms);       
    }
    else
    {
        jack_wt = window.setTimeout("GetGalleryVoteConfirmation()", jack_timeout);       
    }
}

function ClearVoteMessage()
{
    DispErrMsg('','voteMsgSpan');
}

var mailMsgBoard = null;

function ClearMailMessage()
{
    if(mailMsgBoard == null) mailMsgBoard = GetObject('mailMsgBoard');
    if(mailMsgBoard == null) return;
    
    mailMsgBoard.style.display = 'none';
    mailMsgBoard.innerHTML = '';
}

function DispMailMessage(msg)
{
    if(mailMsgBoard == null) mailMsgBoard = GetObject('mailMsgBoard');
    if(mailMsgBoard == null) return;

    if(Trim(msg) == '')   
    {
        ClearMailMessage();
    }
    else
    {
        
        DispErrMsg(msg,'mailMsgBoard');
        mailMsgBoard.style.display = '';
        window.setTimeout("ClearMailMessage()", disp_msg_ms);
    }
}

function DispMailPanelMessage(msg)
{
    var mb = GetObject('send_page_pannel_err');
    if(mb == null) return;
    
    mb.innerHTML = msg;    
    mb.style.display = (msg == null || Trim(msg) == '' ? 'none' : '');

}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// CONTEST WINNERS
//
function ShowNewContestPicture(step)
{
    if(typeof image_mattrix === 'undefined' || image_mattrix == null) return;
    if(image_mattrix_length == 0) image_mattrix_length = image_mattrix.length;
    
    var nextPictId = currPictId + step;
    
    if(nextPictId < 0) nextPictId = 0;
    if(nextPictId >= image_mattrix_length)  document.location.href = document.location.href;
    
    if(voteImgPreview == null) voteImgPreview = GetObject('voteImgPreview');
    if(voteImgPreview == null)  return;

////////////////////////////////////////////////////////////////////////////////////////////
/// navigation controls
    if(nbStepNext  == null) nbStepNext  = GetObject('nbStepNext');
    if(nbStepBack  == null) nbStepBack  = GetObject('nbStepBack');

    if(nextPictId == 0) // first image
    {
        if(nbStepBack != null)  nbStepBack.style.display = 'none';
        if(nbStepNext != null)  nbStepNext.style.display = '';
        if(nbStepNext != null)  nbStepNext.src = 'image/vote_arrow_next_picture.png';
    }
    // last image - replace arrow NEXT with arrow FIRST
    else if(nextPictId >= (image_mattrix_length - 1)) // last image
    {
        if(nbStepBack != null)  nbStepBack.style.display = '';
        if(nbStepNext != null)  nbStepNext.style.display = '';
        if(nbStepNext != null)  nbStepNext.src = 'image/vote_arrow_first.png';
    }
    else
    {
        if(nbStepNext != null)  nbStepNext.src = 'image/vote_arrow_next.png';
        if(nbStepNext != null)  nbStepNext.style.display = '';
        window.setTimeout('ShowArrowBack()', 200);
    }
    
    // picRateMsgBrd
    if(image_mattrix[nextPictId][2] == 0)
    {
        var picRateMsgBrd = GetObject('picRateMsgBrd');
        if(picRateMsgBrd != null) picRateMsgBrd.innerHTML = nextPictId == 0 ? 'This Picture is the Winner!' : 'This Picture is #' + (nextPictId + 1).toString();
    }
    
    voteImgPreview.src = imgSrcPrefix + image_mattrix[nextPictId][0]
    currPictId = nextPictId;
}

function ShowArrowBack()
{
    if(nbStepBack == null) nbStepBack  = GetObject('nbStepBack');
    if(nbStepBack != null) nbStepBack.style.display = '';
}

function RepaintComments()
{
    if(imageComment == null) 
    {
        imageComment = GetObject('imageComment');
        if(imageComment == null) return;
    }
    
    var h = imageComment.src;
    var n = h.indexOf('comhgt=');
    if(n == -1)
    {
        h = '';
    }
    else
    {
        h = h.substr(n + 7);
        n = h.indexOf('&');
        if(n != -1)  { h = h.substr(0,n); }
        if(isNaN(h)) { h = '';            }
        else         { h = '&comhgt=' + h }
    }
    
    var src = 'default.aspx?mm=wfImageComments&imgId=' + image_mattrix[currPictId][2] + h;
    
    imageComment.src = src;
}

//-->