/* download dialog: (c) Attention Solutions */
function debugObj(C){if(typeof C=="object"){var B="[",A;
for(A in C){B+=A+": ";
B+=debugObj(C[A])+", "
}return B+"]"
}else{return C
}}var download={convertUrl:"download/SetConversionParams.jsp",convertMultiUrl:"download/SetConversionParams_all.jsp",progressUrl:"downloadprogress.tk",downloadUrl:"DownloadServlet/",interval:5000,autoClose:0,recordView:null,timer:null,init:function(){var A=$("#downloadDialog");
if(!A.length){A=$("<div/>").attr("id","downloadDialog").hide().appendTo("body")
}return A
},start:function(E,C){var B=download.init(),A="download/downloadBasket.jsp",D={};
if(E&&C){A="download/downloadpopup.jsp",D={catalogID:E,recordID:C}
}B.empty().load(A,D,function(){setTimeout(function(){var F=$("#downloadDialog").height(),G=$("#modalContainer").height();
if(F>G){$("#modalContainer").height(F)
}},50)
});
B.css("background","#fff");
B.modal({onClose:download.close,closeTitle:lang.close})
},download:function(A){$("#dwStatus").html("<p>"+lang.startingDownload+'</p><div><img src="../images/spinner.gif"</div>');
download.recordView=A.recordView;
$.ajax({dataType:"text",url:download.convertUrl+"?recordView="+A.recordView+"&catalogID="+A.catalogID+"&recordID="+A.recordID+"&assetAction="+A.assetAction+"&packaging=None",success:download.startUpdate,error:function(D,B,C){alert("Failed: "+B)
}})
},downloadMulti:function(B){var A=download.init();
A.append("<div/>").attr("id","dwStatus").css("text-align","center").html("<p>"+lang.startingDownload+'</p><div><img src="../images/spinner.gif"</div>').modal();
download.recordView="CollBasket_DetailsView";
$.ajax({dataType:"text",url:download.convertMultiUrl+"?recordView="+download.recordView+"&assetAction="+B,success:download.startUpdate,error:function(E,C,D){alert("Failed: "+C)
}})
},startUpdate:function(A,B){download.timer=setTimeout(function(){download.updateTick($.trim(A))
},download.interval)
},updateTick:function(A){$.getJSON(download.progressUrl,{processID:A},function(C,D){switch(C.dpState){case 0:case 1:$("#dwStatus p:first").text(C.dpStateStr+" ("+C.progress+"%)");
download.startUpdate(A);
break;
case 2:var B=download.downloadUrl+escape(C.downloadname)+"?processID="+A+"&recordView="+download.recordView;
$("#dwStatus").html("<p>"+lang.downloadReady.replace(/\%0/,B)+'</p><div><img src="../images/spinner-stop.gif"</div>');
self.InvisibleFrame.document.location=B;
if(download.autoClose){setTimeout(download.close,download.autoClose)
}break;
case 3:case 4:break;
case 5:case 6:default:$("#dwStatus").html('<p style="color: #c00">'+lang.downloadFailed+'</p><div><img src="../images/spinner-stop.gif"</div>');
$("#dwStatus p:first span:first").click(function(){download.showErr(C)
});
break
}})
},close:function(){if(download.timer){clearTimeout(download.timer);
download.timer=null
}$.modal.close()
},showErr:function(A){$("#downloadDialog > *[id!=dwHeader]").remove();
$("#dwHeader").after($("<p/>").text(debugObj(A)))
}};