function editcap_show(photoId){if($('capStatus_'+photoId).style.display!='none')return;var editCapBox=$('editCapBox_'+photoId);var editCap=$('editCap_'+photoId);if(editCapBox.style.display=='none'){hide($('capBox_'+photoId));show(editCapBox);var cap=$('cap_'+photoId);editCap.value=cap.getAttribute('plainValue');}
editCap.focus();editCap.select();}
function editcap_hide(photoId){hide($('editCapBox_'+photoId));var editCap=$('editCap_'+photoId);editCap.value="";}
function editcap_cancel(photoId){editcap_hide(photoId);show($('capBox_'+photoId));}
function editcap_save(photoId){var editCap=$('editCap_'+photoId);var newCap=dojo.trim(editCap.value);var cap=$('cap_'+photoId);var oldCap=cap.getAttribute('plainValue');if(newCap==oldCap){editcap_cancel(photoId);return;}
editcap_hide(photoId);show($('capStatus_'+photoId));var post={photo_id:photoId,caption:newCap};sendXhrJson(heart.makeUrl("photos","setCaption"),post,dojo.partial(editcap_onSaveSuccess,photoId,newCap),dojo.partial(editcap_onSaveError,photoId));}
function photoviewercap_save(){var photoId=imageArr[curIdx].id;var editCap=$('editCap_1');var newCap=dojo.trim(editCap.value);var cap=$('cap_1');var oldCap=cap.getAttribute('plainValue');if(newCap==oldCap){editcap_cancel(1);return;}
editcap_hide(1);show($('capStatus_1'));var post={photo_id:photoId,caption:newCap};sendXhrJson(heart.makeUrl("photos","setCaption"),post,dojo.partial(editcap_onPVSaveSuccess,1,newCap),dojo.partial(editcap_onSaveError,1));}
function editcap_onSaveSuccessTest(photoId,newCap,result){setTimeout(dojo.partial(editcap_onSaveSuccess,photoId,newCap),1000);}
function editcap_onPVSaveSuccess(photoId,newCap,result){if(typeof result.caption=='undefined'){editcap_onSaveError(photoId);return;}
imageArr[curIdx].title=result.caption;imageArr[curIdx].plainTitle=newCap;cap_set(photoId,newCap,result.caption);capStatus_hide(photoId);}
function editcap_onSaveSuccess(photoId,newCap,result){if(typeof result.caption=='undefined'){editcap_onSaveError(photoId);return;}
cap_set(photoId,newCap,result.caption);capStatus_hide(photoId);}
function editcap_onSaveError(photoId){alert("Sorry, there was an error saving the caption. Please try again later.");capStatus_hide(photoId);}
function capStatus_hide(photoId){hide($('capStatus_'+photoId));show($('capBox_'+photoId));}
function cap_set(photoId,capVal,capValHtml){var cap=$('cap_'+photoId);cap.setAttribute('plainValue',capVal);cap.innerHTML=capValHtml;setDisplay(cap,capVal);setDisplay($('fakecap_'+photoId),!capVal);}