<!-- 
// javascript functions used by mockartstudio application
function SaveImageList(_form, _rows)
{
    var _r = 0, _rd = 0;
    var _c = null;
    
    for(; _r < _rows; _r++)
    {
        _c = GetObject('Delete_' + _r);
        
        if(_c == null)
        {
            if(_r > 1) break;
        }
        else if(_c.value == 1) _rd++;        
    }
 
    submitted = true;
    
    if(_rd == 0) document.forms[_form].submit();
    else
    {
        var confMsg = _rd > 1 ? ' Delete selected images?    ' : ' Delete selected image?    ';
        if(confirm(confMsg)) document.forms[_form].submit();
    }
    submitted = false;
}

function SaveImageList_OnEnter(e, updateFlagId, formId)
{
    var u = null;
    
    if(updateFlagId != null && updateFlagId != '')
    {
	    u = GetObject(updateFlagId);
	    if(u == null) return;
    }

    if(CtrlVPressed(e))
    {
        u.value = '1';
        return;
    }
    
    if(!EnterPressed(e))    return;
 	
	if(u == null || u.value == '1') SaveImageList(formId, 100);    
}

function UncheckDelete(row, col)
{
    // if the checkbox delete was checked - uncheck
    var _ckb = GetObject('ckbDummy' + col + '_' + row); 
    if(_ckb != null && _ckb.type == 'checkbox') { _ckb.checked = false; }
    
    // make sure the delete flag is not set, so the recodr will not be deleted
    var res = GetObject('Delete_' + row);    
    if(res != null) { res.value = 0;   }
}

var curRow = null;
var selectedRowBg = '#d9e9f9';
var oddRowBg = '';
var evenRowBg = '';

function HighlightGridRow(row)
{
    if(oddRowBg == '' || evenRowBg == '')
    {
        var sheets = document.styleSheets;
        var rules = new Array();
        var s = null;

        for(var x = 0; x < sheets.length; x++) 
        {
            if(sheets[x].cssRules)   rules = sheets[x].cssRules
            else if(sheets[x].rules) rules = sheets[x].rules
	        
	        
            if(rules != null && rules.length > 0)
            {
                for(var y = 0; y < rules.length; y++) 
                {
                
                    if(oddRowBg == '' && rules[y].selectorText == '.grdOddRow')
                    {
                        s = rules[y].style;
                        oddRowBg = ConvertRGBtoHEX(s['backgroundColor']);
                    }
                    
                    if(evenRowBg == '' && rules[y].selectorText == '.grdEvnRow')
                    {
                        s = rules[y].style;
                        evenRowBg = ConvertRGBtoHEX(s['backgroundColor']);
                    }
                }
            }
        }
    }

    var odd = true;
    if(curRow != null) 
    {
        odd = curRow.getAttribute('odd');
        curRow.style.backgroundColor = odd == 'True' ? oddRowBg : evenRowBg;
    }

    curRow = row;
    if(curRow != null) 
    {        
        curRow.style.backgroundColor = selectedRowBg;
        
        // set row id for rendering in case the form is submitted later
        var hidSelRow = GetObject('hidselrow'); 
        if(hidSelRow != null) hidSelRow.value = curRow.id;

        // fire click event on the pereview icon:
        var mg = GetObject('imgPrv_' + curRow.id.replace('gridRow_',''));
        if(mg != null) 
        { 
            if(mg.dispatchEvent) 
            {
	            var e = document.createEvent("MouseEvents"); 
	            e.initEvent("click", true, true);
	            mg.dispatchEvent(e); 
            }
            else
            {
	            mg.click(); 
            }
        }      
    }
}

function ClearErrorMessage()
{
    var mb = GetObject('errMsgSpan'); 
    if(mb != null && mb.innerHTML != '') mb.innerHTML = '&nbsp;';
}

function ConvertRGBtoHEX(_color)
{
    if(_color != null && _color.length > 5 && _color.indexOf('rgb(') == 0)
    {
        _color = _color.substr(4);
        _color = _color.replace(')','');
        
        var rgb = _color.split(',');
        
        var _dec = parseInt(rgb[2]) + 256 * parseInt(rgb[1]) + 65536 * parseInt(rgb[0]);    
        _color = '#' + _dec.toString(16);
    }
        
    return _color;
}

function CopyImage(ico, row, ckbDelCol)
{
    if(row <= 0) return;

    // make sure the image is not being deleted
    UncheckDelete(row, ckbDelCol);

    submitted = true;

    // write source image GUI to copy_image container and submit the form     
	var _c = GetObject('copyImgGui'); 
	var _g = GetObject('IID_' + row);
    
	if(_g != null && _c != null) 
	{ 
	    ico.style.cursor = 'progress';
	    _c.value = _g.value;
	    document.forms[0].submit(); 
	}
	else
	{
	    DispErrMsg('Unable to copy selected image', 'errMsgSpan');
	}
	
}	// ------------------------------------------------------

function EMailImageAsync(addrBoxId, txtFNId, txtLNId, txtMsgId, ckbDelCol, attributes)
{
    if(jack_row_id == 0) { ShowHidePanel('email_pannel', false); return; }

    var imgId = GetObject('imgId_' + jack_row_id);
    if(imgId == null) { ShowHidePanel('email_pannel', false); jack_row_id = 0; return; }
    
    if(!ValidEMailAddr(addrBoxId,'email_pannel_title')) return;
    
    var addres = GetObject(addrBoxId).value;
    var f_name = GetObject(txtFNId).value;
    var l_name = GetObject(txtLNId).value;
    var msg    = GetObject(txtMsgId).value;
    
    if(msg.length > 200)  { DispErrMsg('The Message is too long', 'email_pannel_title'); return; }
    
    // make sure the image is not being deleted
    if(ckbDelCol != 0)  UncheckDelete(jack_row_id, ckbDelCol);
    
    // ask jack to send the image:    
    if(jack_count != 0) { DispErrMsg('Communication conflict. Please try again.', 'errMsgSpan'); return; }

    LockScreen(true);   // lock screen to prevent double calls
    
    ShowHidePanel('email_pannel', false);
   
    attributes = attributes.replace('=[row]','=' + imgId.value);
    attributes = attributes.replace('=[addr]','=' + ProcessInput(addres));    
    attributes = attributes.replace('=[' + txtFNId  + ']','=' + ProcessInput(f_name));
    attributes = attributes.replace('=[' + txtLNId  + ']','=' + ProcessInput(l_name));
    attributes = attributes.replace('=[' + txtMsgId + ']','=' + ProcessInput(msg));
    
    LoadJack(attributes);
    
    jack_row_id = 0;
        
    jack_wt = window.setTimeout("GetMailImageConfirmation()", jack_timeout);
	
}	// ------------------------------------------------------

function EMailGalleryImageAsync(attributes)
{
    var email_to    = GetObject('E_Mail_to');
    var fn_to       = GetObject('First_Name_to');
    var ln_to       = GetObject('Last_Name_to');
    
    var email_from  = GetObject('E_Mail_from');
    var fn_from     = GetObject('First_Name_from');
    var ln_from     = GetObject('Last_Name_from');
    
    var msg         = GetObject('message');
    var imgId       = -1;

    if(typeof image_mattrix !== 'undefined' && image_mattrix != null)
    {
        imgId = image_mattrix[currPictId][2];
    }
    
    if(imgId <= 0 || email_to == null || fn_to == null || ln_to == null || email_from == null || fn_from == null || ln_from == null || msg == null)   { ShowHidePanel('send_page_pannel', false); return; }
    
    if(!HasValue(fn_to,'send_page_pannel_title'))               return false;
    if(!ValidEMailAddr('E_Mail_to','send_page_pannel_title'))   return false;
    
    if(!HasValue(fn_from,'send_page_pannel_title'))             return false;
    if(!ValidEMailAddr('E_Mail_from','send_page_pannel_title')) return false;

    if(msg.value.length > 200)  { DispErrMsg('The Message is too long', 'send_page_pannel_title'); return false; }
    
    // ask jack to send the image:    
    if(jack_count != 0) { DispErrMsg('Communication conflict. Please try again.', 'errMsgSpan'); return false; }
    
    ShowHidePanel('send_page_pannel', false);

    LockScreen(true);   // lock screen to prevent double calls
    
    attributes += ('&eato=' + ProcessInput(email_to.value)); 
    attributes += ('&fnto=' + ProcessInput(fn_to.value)); 
    attributes += ('&lnto=' + ProcessInput(ln_to.value)); 
    attributes += ('&eafr=' + ProcessInput(email_from.value)); 
    attributes += ('&fnfr=' + ProcessInput(fn_from.value)); 
    attributes += ('&lnfr=' + ProcessInput(ln_from.value)); 
    attributes += ('&msg='  + ProcessInput(msg.value)); 
    attributes += ('&imgId='+ ProcessInput(imgId)); 

    LoadJack(attributes);
    
    jack_wt = window.setTimeout("GetMailSentConfirmation()", jack_timeout * 2);
	
	return true;
}	// ------------------------------------------------------    


function PreviewImg(url, appGui, imgGui, appType, row, statusPrefix)
{
    var img = GetObject('imgPreview'); if(img == null) return;
    var iig = GetObject('dispImgGui'); if(iig != null) iig.innerHTML = imgGui;
    
    // if the checkbox finished was checked - lock edit function
    var lock_edit = false;
    if(statusPrefix != '')
    {
        DisplayMessage('&nbsp;<br/>&nbsp;<br/>&nbsp;', 'imgErrMsgSpan', false);

        var _st = GetObject(statusPrefix + row); 
        lock_edit = _st != null && _st.value != '0';
    }
	 
//    img.setAttribute('appType', appType);
//    img.setAttribute('appGui',  appGui);
//    img.setAttribute('imgGui', (lock_edit ? 'locked_image' : imgGui));

    img.appGui = appGui;
    img.appType = appType;
    img.imgGui = (lock_edit ? 'locked_image' : imgGui);
    
    img.src = url;    
}

function EditMyImage(url, appGui, imgGui, appType, imgId)
{
	if(url == null || appGui == null || imgGui == null || appType == null || url == '' || appGui == '' || imgGui == '' || appType == '' ) return;
	
	if(imgGui == 'locked_image')    { DispErrMsg('The image is marked Finished, so it can not be edited anymore. You can make a copy of the image and edit the copy. You can delete the original image then and keep the copy, however, the image rating will be lost.', 'imgErrMsgSpan');  }
	else                            { openIGDesigner(url + '?AID=' + appGui + '&IID=' + imgGui , 'IG_Designer_' + appType, imgId); }
}
 
function UpdateStatus(src, resId, rowUpdFlag, grdUpdFlag)
{
	var res = GetObject(resId);
	if(src != null && res != null && res != '')	
	{
		res.value = src.checked ? -1 : 1;
	}

	SetUpdateFlag(rowUpdFlag, grdUpdFlag);
}

function ShowConfSave(show, hide, form)
{
    var f = GetObject('gridUpdFlag');
    
    if(f == null) return;
    
    if(f.value != 0)   
    {
	    ShowObject(show, true);
	    ShowObject(hide, false);
	}   
    else if(form != null)	{	document.forms[form].submit();	}
	else					{	document.forms[0].submit();	 	}

}	// ------------------------------------------------------ 

function LoadUserAdminFormContainers(id)
{
    var userFN = GetObject('First_Name_' + id); 
    var userLN = GetObject('Last_Name_' + id); 
	var lbl = GetObject('userName'); 
	var pwdRow = GetObject('grRow');
	
	lbl.innerHTML = 'for ' + userFN.value + ' ' + userLN.value;
	pwdRow.value = id;
	
	
	// clear password controls
	var pwd1 = GetObject('pwd1');
	var pwd2 = GetObject('pwd2');
	pwd1.value='';
	pwd2.value='';
}	// ------------------------------------------------------

function HighlightLink(img, regSrc, selSrc, select)
{
	var src = img.src;
	if(src == null || src == '') return;

    if(select)  { src = src.replace(regSrc, selSrc);  }
    else        { src = src.replace(selSrc, regSrc);  }
    
	img.src = src;
	
}	// ------------------------------------------------------

function ChangePWD()
{
	var pwd = document.getElementById('pwd1').value;	
    var pwdRow = GetObject('grRow');    
    var userPWD = GetObject('PWD_' + pwdRow.value); 
	
	if(pwd == null || pwd == '')
	{
		document.getElementById('errDialogMsg').innerHTML = 'Please type the password!';
	}
	else
	{
		while(pwd.indexOf(' ') != -1) { pwd = pwd.replace(' ',''); }
		
		if(pwd.length < 5)
		{
			document.getElementById('errDialogMsg').innerHTML = 'Please type at least 5 characters.';
		}

		else if(pwd != document.getElementById('pwd2').value)
		{
			document.getElementById('errDialogMsg').innerHTML = 'Please re-type the password!';
		}
		else
		{
			userPWD.value = pwd; 
			SetUpdateFlag('rowUpdFlag_' + pwdRow.value, 'gridUpdFlag');
			SwitchObjects(null,'changePwd')
			document.forms[0].submit();
		}
	}
}	// ------------------------------------------------------

function ChangeFontColor(txt)
{
   txt.style.color = '#004080';
}	// ------------------------------------------------------	

function HighlightBorder(txt, select, bgcolor)
{
    if(select) 
    {
       txt.style.border = 'solid 1px #d0d0d0';
    }  
    else  
    {
     if(bgcolor=='blue')  txt.style.border = 'solid 1px #8dbbd8';
     else                 txt.style.border = 'solid 1px #ffffff';
    }
          
}	// ------------------------------------------------------

function AddImage(FlagId, val, frmName)
{
    if(submitted) return;
    
	var c = GetObject(FlagId);
	if(c == null) return;
	
	c.value = val;
	submitted = true;
	document.forms[frmName].submit();
	
}	// ------------------------------------------------------

function CompareDatesAndSubmit(d0, d1, target)
{
	var start = Date.parse(d0.value);
	var end =   Date.parse(d1.value);
	
	if(start > end) 
	{ 
		DisplayMessage('Start Date should preceed the End date', 'errMsgSpan', true);
		target.style.color='#ff0000';
	}
}

function ValidateTermsCond(checkBox)
{
	var err = 0;
	var new_err = 0;
	var b, c;

	c = GetObject(checkBox);
	if(c == null || c == '') return true;
			
	if(c.checked)
	{
        PaintValid(c);
        DispErrMsg('Processing ...', 'errMsgSpan');
        return true;		
	}
	else
	{
		DispErrMsg('Please read and accept our Terms and Conditions', 'errMsgSpan');
		PaintInvalid(c);
		return false;
	}
}	// ------------------------------------------------------

var topZIndex = 1200;
function PopUpMe(o)
{
    o.style.zIndex = topZIndex;
    topZIndex++;
}

var htw_rounds = 0, ln = 0;
var htw = null;
function OpenHowTo(line)
{
    ln = line;
   htw = window.open('howto.htm', 'HowTo', 'location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=580,height=500');

   htw_rounds = 100;
   window.setTimeout('ExpandQuestion()', 100);
 
   htw.focus();
   return false;
}

function ExpandQuestion()
{
    if(--htw_rounds <= 0)       return; 
    else if(htw.loaded == 1)    htw.OpenLine(ln)
    else                        window.setTimeout('ExpandQuestion()', 100);
}


///////////////////////////////////// FADING IMAGES ////////////////////////////////////

var mk = null;
var min_opacity = 0.001;
var max_opacity = 1.2;
var opacity = min_opacity;
var step = 0.02;
var fade_interval = 10;
var max_disp_time = 10000; 
var disp_time = max_disp_time; 
var intro = 0;
var intro_imgId = -1;
var intro_limit = 10;

function AnimOff()
{
    var a = GetObject('anim_off');
    return a != null && a.checked;
}

function ShowMakingOf(id)
{
    if(AnimOff()) return; // animation supressed
    
    if(mk != null) // hide old image
    {
        if(mk.id == id) return;
        
        window.clearTimeout();
        mk.style.display = 'none';
        //mk = null;
    }
    
    opacity = min_opacity;
    disp_time = max_disp_time;

    mk = GetObject(id);    
    if(mk == null) return;
    
    SetOpacity();  
    mk.style.display = '';
}

function HideMakingOf(speed)
{
    if(AnimOff()) return; // animation supressed

    intro = 0;
    
    if(mk == null || mk.style.display == 'none') return;
    
    if(speed == 'fast')
    {
        window.clearTimeout();
        mk.style.display = 'none';
        mk = null;
        
        opacity = min_opacity;
        disp_time = max_disp_time;        
    }
    else
    {
        disp_time = 0;
    }
}

function SetOpacity() 
{
    //status = 'mk = ' + ( mk == null ? 'null' : mk.id ) + ' disp_time = ' + disp_time + ' opacity = ' + opacity + ' intro = ' + intro; 
    
    if(mk == null) return;
    
    disp_time -= fade_interval;
    opacity = ( disp_time > 0 ? opacity + step : opacity - step );
    
    if(opacity > max_opacity) 
	{
	    opacity = max_opacity;
	    if(intro == 1)  { disp_time = 0.05; }
	    
	    window.setTimeout('SetOpacity()', fade_interval); 
	    
	    return;
	} 
	
	if(opacity < min_opacity)
	{
	    if(intro == 1)  
	    { 
	        RunIntro(); 
	    }
	    else
	    {
	        window.clearTimeout();
	        mk.style.display = 'none';
	        mk = null;
	    }
	}
	else
	{
	    mk.style.opacity = opacity;
	    mk.style.MozOpacity = opacity;
	    mk.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
	    
        window.setTimeout('SetOpacity()', fade_interval);
	} 
}

function SaveAnimStatus(ckb, hidId, frm)
{
    var o = GetObject(hidId);
    if(o == null) return;
    o.value = ckb.checked ? '1' : '0';    
    document.forms[frm].submit();
}

///////////////////////////////////// INTRO ////////////////////////////////////////////
function RunIntro()
{
    if(AnimOff()) return; // animation supressed
    
    intro = 1;    
    intro_imgId++;
    
    var test_mk = GetObject('mk_' + intro_imgId);
    while(test_mk == null && intro_imgId < intro_limit)
    {
        intro_imgId++;
        test_mk = GetObject('mk_' + intro_imgId);
    }
    
    if(test_mk == null) 
    { 
        HideMakingOf('fast'); 
    }
    else
    {
        ShowMakingOf('mk_' + intro_imgId);
    }
    
    
}


////////////////////////////////////////////////////////////////////////////////////////


function ResetTemplFile(cboMsgType, cboTemplFileId, hidSendTestMessageId)
{
    var cboTemplFile = GetObject(cboTemplFileId);
    var hidSendTestMessage = GetObject(hidSendTestMessageId);
    
    if(cboMsgType == null || cboTemplFile == null || hidSendTestMessage == null) return;
    
    hidSendTestMessage.value = 0;   // request sending a new test message
    
    // var msgType = cboMsgType.options[cboMsgType.selectedIndex].value;
    
    cboTemplFile.selectedIndex = 0;
    
}

function SendMessages(cboMsgTypeId, cboTemplFileId, hidSendTestMessageId, _form)    
{
    if(!ValidMessageSettings(cboMsgTypeId, cboTemplFileId, null)) return;

    var hidSendTestMessage = GetObject(hidSendTestMessageId);
    if(hidSendTestMessage == null || hidSendTestMessage.value == '0') 
    {
        DispErrMsg('Please send the test message first!','errMsgSpan');
        return false;
    }
    
    submitted = true;
    
    if(confirm('   Send messages to multiple addresses?      '))   
    {
        GetObject('gridUpdFlag').value = 1;
        hidSendTestMessage.value = 2;
        document.forms[_form].submit();
    }
    else submitted = false;
}


function SendTestMessage(cboMsgTypeId, cboTemplFileId, txtTestMsgToId, hidSendTestMessageId, _form)
{
    var hidSendTestMessage = GetObject(hidSendTestMessageId);
    if(hidSendTestMessage == null) return;
    
    if(!ValidMessageSettings(cboMsgTypeId, cboTemplFileId, txtTestMsgToId)) return;
    
    submitted = true;
    hidSendTestMessage.value = 1;
    GetObject('gridUpdFlag').value = 1;
    
    document.forms[_form].submit();
}


function ValidMessageSettings(cboMsgTypeId, cboTemplFileId, txtTestMsgToId)
{
    var cboMsgType   = GetObject(cboMsgTypeId);
    var cboTemplFile = GetObject(cboTemplFileId);
    
    if(cboMsgType == null || cboTemplFile == null) 
    {
        DispErrMsg('Missing Screen Objects','errMsgSpan');
        return false;
    }

    // check e-mail address
    if(txtTestMsgToId != null && !ValidEMailAddr(txtTestMsgToId,'errMsgSpan')) return false;
    
    // check template name selection:
    if(cboTemplFile.selectedIndex == 0)
    {
        DispErrMsg('Please select Template File','errMsgSpan');
        return false;
    }
    else
    {
        DispErrMsg('&nbsp;','errMsgSpan');
        return true;
    }
}

function ShowTopBanner(id, show)
{
    var b = GetObject(id);
    if(b != null) b.style.display = show ? '' : 'none';
}

function InviteKidToGallery()
{
    ShowCustomEMailPannel('250px', '180px', 'Invite Your Friend:', 'Check out this link! It\'s the new cool online art, everybody is talking about.\nThey are holding kid\'s contest too. Take a look!', false);
}

function InviteKid()
{
    ShowCustomEMailPannel('150px', '180px', 'Invite Kid:', 'Check out this link! It\'s the new cool art, everybody\'s talking about.\nThey are holding kid\'s contest now. The prizes are Wii console and $300 Gift Card! Go get them!', false);
}

function InviteKidToVote()
{
    ShowCustomEMailPannel('350px', '420px', 'Invite Kid To Vote:', 'Check out this link! It\'s the new cool art, everybody\'s talking about.\nThey are holding kid\'s contest this month.\nCould you please register there and vote?', false);
}

function ChallengeFriend()
{
    ShowCustomEMailPannel('150px', '300px', 'Challenge Your Friend:', 'Check out this link! It\'s a new cool art. I love it.\nI bet I\'m better than you at it :)', false);
}

function InviteVoter()
{
    ShowCustomEMailPannel('150px', '420px', 'Invite Voter:', 'Check out this link! It\'s a pretty cool new art technique.\nThey are holding kid\'s contest this month.\nCould you please register there and vote?', false);
}

function SendPictureFriend()
{
    ShowCustomEMailPannel('120px', '700px', 'Send Picture:', '', true);
}

function UpdateClient() 
{
    if(currThumbNail == null)  return;

	var imgSrc = currThumbNail.src;
	var ref = '&refreh=';
	var refId = 0;
	var i = imgSrc.indexOf(ref);
	if(i == -1)
	{
		imgSrc = imgSrc + ref + '0';
	}
	else
	{
		i += ref.length;
		refId = parseInt(imgSrc.substring(i));
		refId++;
		imgSrc = imgSrc.substring(0,i) + refId;	
	}
	 
	currThumbNail.src = imgSrc;
}


///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////

function SavePictureTitle()
{
    if(titleAndAuthor == null) titleAndAuthor = GetObject('titleAndAuthor');
    if(jack_count != 0 || titleAndAuthor == null) return;
    
    if(titleAndAuthor.value == '')
    {
        PostStudioMessage('The Title can not be empty');
        return;
    }
    LockScreen(true);   // lock screen to prevent double calls
    jack_count = 1;

    newTitle = titleAndAuthor.value;
    var attributes = save_title_attributes.replace('[imgId]', image_mattrix[currPictId][2]).replace('[title]', ProcessInput(newTitle));

    LoadJack(attributes);

    ClearStudioMessage();
    window.clearTimeout(toutClearBrd);
    
    jack_wt = window.setTimeout('GetSaveTitleConfirmation()', jack_timeout * 2);

}

function GetSaveTitleConfirmation()
{
    jack_count++;  
    if(jack_count > jack_limit) 
    {
        jack_count = 0;
        LockScreen(false);  // unlock screen 
        PostStudioMessage('Can not save Picture Title.');
    }
    else if(typeof jack_status !== 'undefined' && jack_status.indexOf('error: ') >= 0) 
    {
        jack_count = 0;
        LockScreen(false);  // unlock screen 
        PostStudioMessage(jack_status.replace('error: ',''));
    }
    else if(typeof jack_status !== 'undefined' && jack_status == sent_status)
    {
        PostStudioMessage('Your Picture Title is Saved.');
        image_mattrix[currPictId][3] = newTitle;
        jack_count = 0;
        LockScreen(false);  // unlock screen 
        toutClearBrd = window.setTimeout("ClearStudioMessage()", disp_msg_ms);       
    }
    else
    {
        jack_wt = window.setTimeout("GetSaveTitleConfirmation()", jack_timeout);       
    }
}

function ClearStudioMessage()
{
    PostStudioMessage('');
}

function PostStudioMessage(msg)
{
    if(messagBoard == null) messagBoard = GetObject('msgBrd');
    if(messagBoard == null) return;
    
    messagBoard.innerHTML = msg;     
    messagBoard.style.display = ( Trim(msg) == '' ? 'none' : '' );

    
}

function EditPicture(appType)
{
    if(Trim(image_mattrix[currPictId][5]) != '0') return;
    
    openIGDesigner(editSrcPrefix + image_mattrix[currPictId][0] , 'IG_Designer_' + appType, 'voteImgPreview');
}

function ShowAnimation(animId, dispLinkId, h, show)
{
    if(show) 
    {
        document.location.href = document.location.href;
    }
    else
    {
        var a = GetObject(animId);
        var d = GetObject(dispLinkId);
        
        if(a == null || d == null || h == null) return;
        
        a.style.display = (show ? '' : 'none');
        d.style.display = '';
        h.style.display = 'none';

        //if(show)
        //{
        //    a.GotoFrame(10);
        //    a.Play();
        //}
    }
}

var newStatus = 0;
var newTitle = '';

function FinishMyPicture(lblClicked)
{

    if(ckbStatus == null) ckbStatus = GetObject('Status');    
    if(jack_count != 0 || ckbStatus == null) return;

    LockScreen(true);   // lock screen to prevent double calls
    jack_count = 1;

    if(lblClicked) ckbStatus.checked = !ckbStatus.checked;
    
    newStatus = ckbStatus.checked ? '1' : '0';
    var attributes = save_status_attributes.replace('[imgId]', image_mattrix[currPictId][2]).replace('[status]', newStatus);

    LoadJack(attributes);

    ClearStudioMessage();
    window.clearTimeout(toutClearBrd);
    
    jack_wt = window.setTimeout('GetSaveStatusConfirmation()', jack_timeout * 2);
}

function GetSaveStatusConfirmation()
{
    jack_count++;  
    if(jack_count > jack_limit) 
    {
        jack_count = 0;
        LockScreen(false);  // unlock screen 
        ckbStatus.checked = !ckbStatus.checked; // restore checkbox status
        if(newStatus == 1)  PostStudioMessage('Can not mark the picture Finished.');
        else                PostStudioMessage('Can not Unlock the picture.');
    }
    else if(typeof jack_status !== 'undefined' && jack_status.indexOf('error: ') >= 0) 
    {
        jack_count = 0;
        LockScreen(false);  // unlock screen 
        ckbStatus.checked = !ckbStatus.checked; // restore checkbox status
        PostStudioMessage(jack_status.replace('error: ',''));
    }
    else if(typeof jack_status !== 'undefined' && jack_status == sent_status)
    {
        if(newStatus == 1)  PostStudioMessage('Your Picture is Finished.');
        else                PostStudioMessage('Your Picture is Unlocked.');
        image_mattrix[currPictId][5] = newStatus;
        RepaintStatus();
        jack_count = 0;
        LockScreen(false);  // unlock screen 
        toutClearBrd = window.setTimeout("ClearStudioMessage()", disp_msg_ms);       
    }
    else
    {
        jack_wt = window.setTimeout("GetSaveStatusConfirmation()", jack_timeout);       
    }
}

//-->
