if(!Number.prototype.toFixed){Number.prototype.toFixed=function(b){var a=Math.pow(10,parseInt(b)),c;a=String(Math.round(this*a)/a);if(b>0){c=a.split(".");c[1]=(c[1]||"")+new Array(++b-(c[1]?c[1].length:0)).join("0");a=c.join(".")}return a}}var strMailEmpty="Enter your email address here";function inputOnFocus(a){if(a.nodeType&&a.value==strMailEmpty){a.value="";a.style.fontStyle="normal"}}function inputOnBlur(a){if(a.nodeType&&a.value.length==0){a.style.fontStyle="italic";a.value=strMailEmpty}}function toggleView(b,c){var a=document.getElementById(c);document.getElementById(b).style.visibility=(a.checked)?"visible":"hidden"}function validateEmail(b){var a=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;return a.test(b)}function validateUrl(a){var b=/(http:\/\/|https:\/\/|ftp:\/\/)?.+\..+\/.+\.+\w{2,8}/i;return b.test(a)}function SetSubmitBtnState(a){if(typeof a=="undefined"&&typeof MF!="undefined"&&MF!=null){a=MF.length>0}if(a===true){EnableSubmitBtn()}else{DisableSubmitBtn()}return a}function EnableSubmitBtn(){$("#submit").removeAttr("disabled");$("#submit-wrap").removeClass("disabled")}function DisableSubmitBtn(){$("#submit").attr("disabled","disabled");$("#submit-wrap").addClass("disabled")}var UP=null;var MF=null;var isFirstFileSelection=true;var iterator=0;var defaultInputSelect=null;var defaultOutputSelect=null;var $defaultFilelistRow=null;var FilelistRows=null;var Jobs=null;function initFakeSelect(){var b=document.getElementById("not-selected");var a=$(b).find("select");a.each(function(d,e){var c=new FakeSelect(e)})}function initUploadProgress(){UP=new UploadProgress("filesForm",{additionalFields:["convertTo+","originalFormat+","convert","preset+"],uploadingFields:["user-file+","user-url+"],beforeSubmit:BeforeSubmit,afterSubmit:AfterSubmit,onProgressChanged:ProgressChanged,onCompleted:Completed,onFinished:Finished})}function initMultipleFiles(){MF=new MultipleFile("user-file",{max:5,maxValueLength:38,beforeFileSelect:onFileSelect,onFileRemove:onFileRemove})}function initializeConverter(){FilelistRows=new Array();var a=document.getElementById("not-selected");var b=$(a);defaultInputSelect=b.find(".source-format-container .select-file-format").clone(true);defaultOutputSelect=b.find(".dest-format-container .select-file-format").clone(true);$defaultFilelistRow=b.clone(true).removeAttr("id");initFakeSelect();initUploadProgress();initMultipleFiles()}function OnClickAddUrl(){if(MF.isFull()){return}var a=document.getElementById("user-url");var b=a.value;if(validateUrl(b)){onFileSelect({currentTarget:a})}else{alert("Please enter a valid direct URL to your file.");a.value=""}}function CloneRow(){var a=$defaultFilelistRow.clone(true);a.prependTo(document.getElementById("filelist"));a.attr("id",MF.getSuffix()).addClass((iterator%2==0?"even":"odd"));iterator++;return a}function onInputFormatChange(d){var a=$(d.parentNode.parentNode).find(".dest-format-container .select-file-format");var c;var b=d.options[d.selectedIndex].value;if(a.length==1){c=a[0]}repopulateOutputFormat(b,c);PrependPresetSelection("null",b);c.redraw();if(typeof c!="undefined"&&inArray(b,unsupportedOriginalType)){c.innerHTML="";return}}function onFileSelect(a){var h=a.currentTarget;if(!checkFileType(h,true)){h.value=null;showError()}else{document.getElementById("not-selected").style.display="none";var e=CloneRow();setFilesType(h,true);var g=e.find(".select-file-format");var k=g[1].options[g[1].selectedIndex].value;var d=PrependPresetSelection(MF.getSuffix(),k);if(typeof d!="object"){d={value:"0"}}var j=e.find(".filename").empty();var f=new Object();var c=0;g.each(function(n,o){var l=$(o);var m=l.val(),p=l.attr("name");if(typeof d.formattype!="undefined"&&p=="convertTo"){m=d.formattype}f[n]={name:p,value:m};c=n;var i=new FakeSelect(o);if(n==0){i.fakeSelect.disable()}});var b;if($(h).is("input[type=text]")){b=h}f[++c]={name:"preset",value:d.value};MF.add(f,j,b);FilelistRows.push(e);for(c in FilelistRows){FilelistRows[c].removeClass("first")}FilelistRows[FilelistRows.length-1].addClass("first");
SetSubmitBtnState(true);if(MF.isFull()){OnQueueFull()}}return false}function OnQueueFull(){MF.disableLast();$("#btn-set-url").add("#btn-set-file").add("#fake-file").add("#user-url").addClass("disabled")}function onFileRemove(a){if(MF.isFull()){MF.enableLast();$("#btn-set-url").add("#btn-set-file").add("#fake-file").add("#user-url").removeClass("disabled")}var c=999,d=0;var b=a.currentTarget.parentNode.parentNode.parentNode;if(typeof FilelistRows=="object"){for(d in FilelistRows){if(b==FilelistRows[d].get(0)){c=parseInt(d)}}if(FilelistRows.length>c){MF.remove(c);FilelistRows[c].remove();FilelistRows.splice(c,1);iterator=0;if(FilelistRows.length==0){SetSubmitBtnState(false);document.getElementById("not-selected").style.display=""}else{for(d in FilelistRows){FilelistRows[d].removeClass("even").removeClass("odd").removeClass("first").addClass(iterator%2==0?"even":"odd");iterator++}FilelistRows[FilelistRows.length-1].addClass("first")}}}}function onSelectChange(l){var c=$(l);var b=c.attr("name");var j=$(l.parentNode.parentNode);var n=j.attr("id");var g=MF.getInputs();var d=false;var k;var m=null,a=null;for(var h in g){for(var e in g[h]){if(g[h][e].getAttribute("name")==(b+n)){g[h][e].value=l.options[l.selectedIndex].value;m=g[h][e];d=true}if(g[h][e].getAttribute("name")==("originalFormat"+n)){k=g[h][e].value}if(g[h][e].getAttribute("name")==("preset"+n)){a=g[h][e]}}if(d){break}}lastOutputFileType=l.options[l.selectedIndex].value;if(IsTemporaryUnavailable(k,lastOutputFileType)){AppendUnsupportedType(j.find(".dest-format-container"))}else{RemoveUnsupportedType(j)}var f=PrependPresetSelection(n,lastOutputFileType);if(typeof f=="object"&&m!=null&&a!=null){m.value=f.formattype;a.value=f.value}}function onPresetSelectChange(b){var a=$(b.parentNode.parentNode.parentNode.parentNode);var g=a.attr("id");var d=MF.getInputs();var c=false,h=b.options[b.selectedIndex].value;for(var e in d){for(var f in d[e]){if(d[e][f].getAttribute("name")==("preset"+g)){d[e][f].value=h;c=true}}if(c){break}}}function PrependPresetSelection(h,j){var f="";var i=document.getElementById(h);var g=$(i).find(".dest-format-container");var d="select-preset"+h;if(document.getElementById(d)){RemovePresetSelection(h)}if(typeof presets[j]=="object"){if(presets[j].length>0){f=presets[j][0]}var b='<div class="select-preset-wrap" style="display: block;"><span class="select-preset-label">Type:&nbsp;</span><div class="select-preset-container"><select class="select-file-preset" name="preset" id="'+d+'" onchange="onPresetSelectChange(this);">';var c;for(var a=0,e=presets[j].length;a<e;a++){c=presets[j][a];b+="<option value='"+c.value+"'>"+c.text+"</option>"}b+="</select></div><div class='clear'></div></div>";g.append(b);g.find(".select-file-preset").each(function(k,l){new FakeSelect(l)})}else{g.find(".select-preset-wrap").remove()}return f}function RemovePresetSelection(a){var b=document.getElementById(a);if(b){$(b).find(".select-preset-wrap").remove()}}function BeforeSubmit(){if(MF.length()==0){return false}var b=MF.getInputs();var d=null;if(document.getElementById("send-to-mail").checked===true){d=document.getElementById("email");if(validateEmail(d.value)===true){for(var c=0,a=b.length;c<a;c++){b[c].push($(d).clone())}}else{alert("Please enter a valid email address or uncheck checkbox with email address");return false}}UP.buildQueue(b);iterator=0;ResetProgressDiv();$("#results").prepend("<div class='outter-border' style='display: none;'><div class='inner-border'><div class='inner-shadow-top'></div><div class='results-path'></div><div class='inner-shadow-bottom'></div></div></div>");SetSubmitBtnState(false);UP.disableForm();$("#filelist").find(".select-file-format").each(function(e,g){try{g.disable()}catch(f){}});MF.disable();return true}function AfterSubmit(){if(UP){Jobs=new Array();var b=new Object();var a=UP.getUploadIds();if(typeof a!="object"||a.length<2){return}b={"upload_ids[]":a};var c=document.getElementById("email");if(c.nodeType&&c.value.length>0&&typeof strMailEmpty!="undefined"&&c.value!==strMailEmpty){b.email=c.value
}if(typeof a=="object"&&a.length>1){$.ajax({url:"/submit.php",type:"POST",async:false,data:b,success:function(d){if(d&&d>0){UP.addAdditionalData("batch",d)}},error:function(){}})}}}function AddToQueue(){if(typeof MF=="undefined"||MF==null){return}var a=new Object();$(".uploadForm").find("#originalFormatContainer .select-file-format:first, #convertToContainer .select-file-format:first").each(function(c,d){var b=$(d);a[c]={name:b.attr("name"),value:b.val()}});MF.add(a)}function ResetProgressDiv(){var a=MF.getFileName(iterator);var b="Uploading "+(a.length>0?a:"...");document.getElementById("apcUpload").style.display="block";document.getElementById("total").innerHTML=FormatUploadedSize(0);document.getElementById("loaded").innerHTML=FormatUploadedSize(0);document.getElementById("percentage").style.width="0px";document.getElementById("uploading").innerHTML=b}function HideProgressDiv(){document.getElementById("apcUpload").style.display="none"}function ProgressChanged(a){if(a&&a.upload_info){ParseUploadResult(document.getElementById("apcUpload"),a.upload_info)}}function ProgressCompleted(){document.getElementById("percentage").style.width="100%";document.getElementById("uploading").innerHTML="Completed"}function Completed(a){iterator++;ProgressCompleted();if(a&&(typeof a.error!="undefined"||typeof a.job_info["error"]!="undefined"||typeof a.upload_info["error"]!="undefined")){var b=a.error;if(typeof b=="undefined"||b==null){b=a.upload_info["error"]}if(typeof b=="undefined"||b==null){b=a.job_info["error"]}AddErrorItem("results-path",a,b)}else{if(a&&a.job_info&&a.job_info["jobID"]&&a.job_info["key"]){AddConversionItem("results-path",a.job_info["jobID"],a.job_info["outputPath"]);Jobs.push(a.job_info["jobID"]);RequestNewJobStatus(a.job_info["jobID"],a.job_info["key"])}}if(Jobs.length==0&&UP){UP.enableForm()}if(!UP.isQueueEmpty()){setTimeout(function(){ResetProgressDiv();UP.processNextTask()},300)}return false}function Finished(){setTimeout(HideProgressDiv,300);MF.enable();MF.removeAll();MF.enableLast();$("#filelist").find(".select-file-format").each(function(b,d){try{d.enable()}catch(c){}});$("#btn-set-url").add("#btn-set-file").add("#fake-file").add("#user-url").removeClass("disabled");if(typeof FilelistRows=="object"){for(var a in FilelistRows){FilelistRows[a].remove()}FilelistRows=new Array()}iterator=0;$(UP).find("input[name=batch]").remove();document.getElementById("not-selected").style.display=""}function ParseUploadResult(g,e,f){var b=0,d=0;if(!g.__rate){g.__rate={time:new Date().getTime(),value:0,percent:0}}if(e&&typeof e=="object"&&e.bytes_uploaded&&e.bytes_total){try{b=parseInt(e.bytes_uploaded);d=parseInt(e.bytes_total)}catch(c){d=0;b=0}}g.__rate.value=b-g.__rate.value;var a=g.__rate.percent;if(b>0&&d>0){g.__rate.percent=Math.round((b*100)/d);document.getElementById("total").innerHTML=FormatUploadedSize(d);document.getElementById("loaded").innerHTML=FormatUploadedSize(b);if(g.__rate.percent>a){$(document.getElementById("percentage")).animate({width:g.__rate.percent+"%"},250)}g.__rate.time=new Date().getTime()}if(f){f()}}function FormatUploadedSize(c){var b=["Bytes","KB","MB","GB","TB","ZB"],a=0;while(c>1024&&++a){c/=1024}return(a?c.toFixed(2):Math.ceil(c))+" "+b[a]}function RequestNewJobStatus(a,b){if(!a){return}setTimeout(function(){jQuery.ajax({async:true,cache:false,type:"GET",url:"./jobStatus.php?jobID="+a+"&key="+b,success:function(c){if(typeof c==="string"){c=JSON.parse(c);ParseJobStatusResult(c,a,b)}}})},1000)}function ParseJobStatusResult(b,a,e){if(!(b.jobStatus==="Successful"||b.jobStatus==="Stopped"||b.jobStatus==="Failure")){UpdateResultPathItem("results-path",b);RequestNewJobStatus(a,e)}else{UpdateResultPathItem("results-path",b);if(typeof b.archivePath!=="undefined"){var d=$("#result-"+b.jobID);if(d.length&&d.length>0){d=d.parent()}UpdateAttachmentsLink(d,b.archivePath);if(b.archivePath.lastIndexOf(".zip")==-1){RequestNewJobStatus(a,e)}}for(var c=0;c<Jobs.length;c++){if(parseInt(Jobs[c])==parseInt(b.jobID)){Jobs.splice(c,1)
}}if(Jobs.length==0&&UP){UP.enableForm()}}}function AddErrorItem(b,d,f){var a=$($("#results").find("."+b).get(0));if(a.length>0){a.parent().parent().show();var c=(typeof d.filename=="string"?decodeURIComponent(d.filename):"");var g=document.getElementById("result-"+d.uid);var e="<div id='result-"+d.uid+"'><div class='conversion-status inline-block failed'></div><span class='filename'>"+c+"</span><span class='status'>"+f+"</span></div>";if(g!=null&&g.nodeType){g.innerHTML=e}else{var h=$(e);a.prepend(h)}document.getElementById("list-files-text").style.display="block"}}function AddConversionItem(b,g,f){var d=document.getElementById("results");var a=$($(d).find("."+b).get(0));if(a.length>0&&f){a.parent().parent().show();var c=f.split("/");c=(c[c.length-1].length>0?c[c.length-1]:c[c.length-2]);var e=$("<div class='result-item' id='result-"+g+"' style='display:none;'><div class='oneline'><div class='conversion-status inline-block converting'></div><span class='filename'>"+decodeURIComponent(c)+"</span><span class='status'>Please wait. </span></div><div class='progress-result' style='display:none;'><span id='progress-result-text-"+g+"'></span><div class='progress-bar-wrap'><div id='progress-result-"+g+"' class='conversion-progress'></div></div></div></div>");a.prepend(e);e.fadeIn("normal");document.getElementById("list-files-text").style.display="block"}}function UpdateResultPathItem(b,d){var c="",i,g,a;var h=$("#result-"+d.jobID);if(h.length==0){return}a="";switch(d.jobStatus){case"Successful":c="Success";a=d.outputPath.split("/");a=(a[a.length-1].length>0?a[a.length-1]:a[a.length-2]);g=h.find(".filename");i="<a class='filename' href='"+d.outputPath+"' target='_blank'>"+decodeURIComponent(a)+"</a>";if(typeof d.filesize!="undefined"&&parseInt(d.filesize)>0){i+="<span>&nbsp;("+FormatUploadedSize(d.filesize)+")</span>"}$(i).insertAfter(g);g.remove();h.find(".conversion-status").removeClass("converting").addClass("success");h.find(".progress").html();break;case"Failure":c="Failed.";if(typeof d.jobError=="string"&&d.jobError.length>0){c+=" "+d.jobError}h.find(".conversion-status").removeClass("converting").addClass("failed");h.find(".progress").html();break;case"Stopped":c="Stopped";h.find(".conversion-status").removeClass("converting").addClass("failed");h.find(".progress").html();break;case"Idle":case"Running":if(d&&typeof d.progressPercentage!="undefined"){d.progressPercentage=parseInt(d.progressPercentage);if(isNaN(d.progressPercentage)){d.progressPercentage=0}if(d.progressPercentage>100){d.progressPercentage=100}else{if(d.progressPercentage<0){d.progressPercentage=0}}var f=document.getElementById("progress-result-"+d.jobID);var e=document.getElementById("progress-result-text-"+d.jobID);f.style.width=d.progressPercentage+"%";e.innerHTML="converted "+d.progressPercentage+"%";e.parentNode.style.display="block"}if(d.jobStatus=="Running"){c="Converting ..."}else{if(d.jobStatus=="Idle"){if(typeof d.queueIndex!="undefined"){c="Please wait. Queued at #"+(d.queueIndex+1)}else{c="Please wait. Queueing"}}}break}if(d.jobStatus=="Successful"||d.jobStatus=="Failure"||d.jobStatus=="Stopped"){document.getElementById("progress-result-text-"+d.jobID).parentNode.style.display="none"}if(c.length>0){h.find(".status").text(c)}}function UpdateAttachmentsLink(c,b){if(!c.length){return}var a=c.find(".download-all");if(a.length==0){a=$("<div class='download-all'></div>");c.prepend(a)}if(b.lastIndexOf(".zip")!=-1){a.html("<a href='"+b+"' target='_blank'>Download successfully converted files</a>")}else{a.html("Archiving successfully converted files ...<img style='display: inline;' alt='' src='/images/ajax-loader.gif' />")}};
