﻿var MonitoringActive=false;var MonitorInterval=0;var RemainingImageCount=0;var lastRemainingImageCount=0;var DownloaderIdleCount=0;var completeImageSet=null;var completeImageSetCount=0;var currentImageIndex=0;var imagePopupViewerIsVisible=false;var imageSwapperInterval=0;var GetImageDownloadMonitorValueXHR=CreateXmlHttpRequestObject();function GetRemainingDownloadImageCountFromWS(){if(GetImageDownloadMonitorValueXHR){var WebSite=location.pathname;var endChar=WebSite.lastIndexOf("/");WebSite=WebSite.substring(0,endChar+1);var currentHostURL="http://"+location.host+WebSite+"wsDownloaderMonitorService.asmx/GetImageDownloadCountMonitor";try{GetImageDownloadMonitorValueXHR.open("POST",currentHostURL,true);}catch(e){writeDebug("Error in GetRemainingDownloadImageCountFromWS ["+e.name+"]: "+e.message,true);return;}try{GetImageDownloadMonitorValueXHR.onreadystatechange=onGetRemainingDownloadImageCountFromWSComplete;GetImageDownloadMonitorValueXHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");GetImageDownloadMonitorValueXHR.send();}catch(e){writeDebug("Error in GetRemainingDownloadImageCountFromWS ["+e.name+"]: "+e.message,true);}}};function onGetRemainingDownloadImageCountFromWSComplete(){try{if(GetImageDownloadMonitorValueXHR.readyState==READYSTATE_COMPLETE){if(GetImageDownloadMonitorValueXHR.status==HTTPSTATUS_OK){var xmlDoc=GetImageDownloadMonitorValueXHR.responseXML;if(xmlDoc!=null){var docElment=xmlDoc.documentElement;var AllStringElements=xmlDoc.getElementsByTagName("int");RemainingImageCount=AllStringElements[0].firstChild.nodeValue;if(RemainingImageCount<=0){MonitoringActive=false;RemainingImageCount=0;$get("pimImageDownloadViewID").style.visibility="hidden";$get("pimImageDownloadViewID").style.display="none";$get("pimMontageViewID").style.visibility="visible";$get("pimMontageViewID").style.display="block";completeImageSet=document.getElementsByName("pimMontageIMAGEName");completeImageSetCount=completeImageSet.length;currentImageIndex=0;}if(lastRemainingImageCount==RemainingImageCount){DownloaderIdleCount++;if(DownloaderIdleCount>10){MonitoringActive=false;RemainingImageCount=0;$get("pimImageDownloadViewID").style.visibility="hidden";$get("pimImageDownloadViewID").style.display="none";$get("pimMontageViewID").style.visibility="visible";$get("pimMontageViewID").style.display="block";completeImageSet=document.getElementsByName("pimMontageIMAGEName");completeImageSetCount=completeImageSet.length;currentImageIndex=0;}}else{lastRemainingImageCount=RemainingImageCount;}}}else{var Bugs=GetImageDownloadMonitorValueXHR.responseText;writeDebug("Error in onGetRemainingDownloadImageCountFromWSComplete! "+Bugs,true);}}}catch(e){writeDebug("Error in onGetRemainingDownloadImageCountFromWSComplete ["+e.name+"]: "+e.message,true);}}(function(){var swapper=function(suffleMe,el,all){var ran=Math.floor(Math.random()*all);var saver=suffleMe[el];suffleMe[el]=suffleMe[ran];suffleMe[ran]=saver;};Array.prototype.shuffle=function(){var i=this.length;var Total=i;while(i--){swapper(this,i,Total);}};})();function DoThePhotoMontagePanelRefresh(){if(MonitoringActive){return;}$get("pimMontageViewID").style.visibility="hidden";$get("pimMontageViewID").style.display="none";$get("pimImageDownloadViewID").style.visibility="visible";$get("pimImageDownloadViewID").style.display="block";MonitoringActive=true;RemainingImageCount=0;DownloaderIdleCount=0;lastRemainingImageCount= -1;};function ShowImageInModalPopup(imgObject){imagePopupViewerIsVisible=true;imageSwapperInterval=0;$get("masterPhotoImage").style.visibility="hidden";$get("masterPhotoImage").style.display="none";if($find('ModalPopupBehaviorID')!=null){$find('ModalPopupBehaviorID').show();}var imageURI=src=imgObject.src;imageURI=imageURI.split('&');var newImageUri=imageURI[0]+"&Size=XL&"+imageURI[2];$get("masterPhotoImage").src=newImageUri;$get("masterPhotoImage").style.visibility="visible";$get("masterPhotoImage").style.display="block";};function ShowNextImageInModalPopup(){if(completeImageSet==null){return;}imageSwapperInterval=0;var imageURI=src=completeImageSet[currentImageIndex].src;imageURI=imageURI.split('&');var newImageUri=imageURI[0]+"&Size=XL&"+imageURI[2];$get("masterPhotoImage").src=newImageUri;currentImageIndex++;if(currentImageIndex>=completeImageSetCount-1){currentImageIndex=0;}};function WeAreDone(){try{imagePopupViewerIsVisible=false;imageSwapperInterval=0;$get("masterPhotoImage").src="./Images/Black.png";}catch(e){writeDebug("Error in WeAreDone ["+e.name+"]: "+e.message,true);}};function DoTimerPOP(){if(MonitoringActive){MonitorInterval++;if(MonitorInterval>10){MonitorInterval=0;GetRemainingDownloadImageCountFromWS();}}if(imagePopupViewerIsVisible){imageSwapperInterval++;if(imageSwapperInterval>100){imageSwapperInterval=0;ShowNextImageInModalPopup();}}window.setTimeout('DoTimerPOP()',100);};function pageLoad(){};function load(){clearDebug();setCookie("XHRDomain","SFosterMurray",100);MonitoringActive=true;RemainingImageCount=0;DownloaderIdleCount=0;lastRemainingImageCount= -1;DoTimerPOP();};var debugDiv=null;var debugSpan=null;var debugShow=false;function toggleDebugView(){try{if(debugShow){debugShow=false;hideDebug();}else{debugShow=true;showDebug();}}catch(e){alert("toggleDebugView() call failed");}};function showDebug(){try{debugDiv=$get("debugDivContent");if(debugDiv!=null){debugDiv.style.display="block";debugDiv.style.visibility="visible";}}catch(e){alert("showDebug() call failed");}};function hideDebug(){try{debugDiv=$get("debugDivContent");if(debugDiv!=null){debugDiv.style.display="none";debugDiv.style.visibility="hidden";}}catch(e){alert("hideDebug() call failed");}};function clearDebug(){try{debugDiv=$get("debugDivContent");if(debugDiv!=null){debugDiv.innerHTML="";writeClearLink();}debugSpan=$get("debugSpanContent");if(debugSpan!=null){debugSpan.style.color="#009900";}}catch(e){alert("clearDebug() call failed");}};function writeDebug(MessageOut,AddTime){try{if(AddTime==null||AddTime==""){AddTime=false;}debugDiv=$get("debugDivContent");if(debugDiv!=null){if(AddTime){debugDiv.innerHTML+=Date()+"<br\/>"+MessageOut+"<br\/>";}else{debugDiv.innerHTML+=MessageOut+"<br\/>";}}debugSpan=$get("debugSpanContent");if(debugSpan!=null&&debugSpan.style.color!="#990000"){debugSpan.style.color="#990000";}}catch(e){alert("writeDebug() call failed");}};function writeEval(code){writeDebug(code+" = "+eval(code),true);};function writeDebugObject(myobject){var strCollection="";for(curObj in myobject){if(typeof myobject[curObj]=="object"){strCollection+=curObj+": "+myobject[curObj]+"<br\/>";}else{try{strCollection+=curObj+": "+myobject[curObj]+"<br\/>";}catch(e){strCollection+=curObj+": Unable to evaluate!<br\/>";}}}writeDebug(strCollection,false);};function writeClearLink(){writeDebug("<a href='#' title='Cleanup this mess!' onclick='clearDebug(); return false;'>Clear the Debug Window!</a>",false);};function dumpToPopup(x){var win=window.open();for(var i in x){try{win.document.write(i+" = "+x[i]+"<br>");}catch(e){win.document.write(i+": Unable to evaluate!<br>");}}}
