(function(){var a;window.vision=window.vision||{};vision.ugc={init:function(){if(a.isSupported){if(document.getElementById("vision-ugc-add")){var b=a.embed.Flash.version();if(vision.ugc.flash=="false"){vision.ugc.hideFlashControls();a.dom.get("#vision-ugc-add").addClass("flash-enabled");flashMode="false"}else{if(b.major=="9"||b.major=="10"){vision.ugc.hideFallbackcontrols();if(vision.ugc.sourcecategory=="true"){vision.ugc.getSource()}a.dom.get("#vision-ugc-uploadButton").attr("disabled","disabled");a.dom.get("#vision-ugc-uploadButton").addClass("disabled");flashMode="true";a.dom.get("#vision-ugc-indicator").html("<p>status: <span id='vision-ugc-sent-bytes'>0</span> / <span id='vision-ugc-total-bytes'>0mb</span></p><div id='vision-ugc-progress'><span id='vision-ugc-progressbar'></span>")}else{vision.ugc.hideFlashControls();a.dom.get("#vision-ugc-add").addClass("flash-enabled");flashMode="false"}}var c=new a.widgets.InfoPanel(a.dom.create('<h2 class="hd">Which formats can I submit?</h2><div></div>'),{context:"#tooltip-formats",width:300,autoPosition:true,anim:"fade"});c.body.html("<p>We accept files with the following extensions:</p><p>"+vision.ugc.filetype+"</p>");a.events.addListener(a.dom.get("#tooltip-formats"),"click",function(){c.show();return false});a.dom.get("#vision-ugc-add").addClass("js-enabled");vision.ugc.getPopup();vision.ugc.onLoad();vision.ugc.validate()}}},version:"1_4",filesAttached:false,bridge:null,flashmode:true,onLoad:function(){if(vision.ugc.flash!="false"){var b=a.embed.Flash.version();if(b.major=="9"||b.major=="10"){new a.embed.Flash("/apps/vision/"+vision.ugc.version+"/ugc/js/visionuploadbridge.swf","#UploadBridgeContainer","9",{height:"22px",width:"92px",id:"UploadBridge",params:{wmode:"transparent"}}).embed();a.dom.create("<span>Choose</span>").prependTo("#UploadBridgeContainer");flashMode="true"}}},getSource:function(){a.events.addListener("#vision-ugc-source-categories","change",function(){var b=a.dom.get("#vision-ugc-source-categories").val();vision.ugc.bridge.setSource(b)})},callback:function(e){var d=document.getElementById("vision-ugc-form");var c=d.innerHTML;var b=a.dom.get("#vision-ugc-form").height();d.innerHTML="<h3>"+e+"</h3><p><a href='#vision-ugc-add' id='vision-ugc-formreturn'>Upload</a> another image.";a.dom.get("#vision-ugc-form").height(b);a.events.addListener("#vision-ugc-formreturn","click",function(){d.innerHTML=c;vision.ugc.toggleFields("enabled");vision.ugc.resetForm();a.dom.get(".vision-ugc-submit").html('<input id="vision-ugc-uploadButton" type="submit" value="Upload" name="submit" />')})},getPopup:function(){var d=document.getElementsByTagName("a"),c,b;for(c=0,b=d.length;c<b;c++){if(d[c].className=="popup"){d[c].onclick=function(){return vision.ugc.pop(this.href)}}}},pop:function(b){newwindow=window.open(b,"term","height=auto,width=auto,resizable=yes,scrollbars=yes");if(window.focus){newwindow.focus()}return false},onBridgeReady:function(){a.dom.get("#vision-ugc-add").addClass("bridge-upload")},onBrowse:function(){vision.ugc.bridge.setFileFilter(vision.ugc.fileset,vision.ugc.filetype);vision.ugc.bridge.browse("Image","vision.ugc.onBrowseCompleted")},onUnsetSelectedFiles:function(){a.dom.get("#vision-ugc-filelist").html("");a.dom.get("#vision-ugc-uploadButton").attr("disabled","disabled");a.dom.get("#vision-ugc-uploadButton").addClass("disabled")},onBrowseCompleted:function(b){if(b){var e=Math.round(vision.ugc.filelimit/1048576*100000)/100000;var d=vision.ugc.bridge.selectedFiles();for(i=0;i<d.length;i++){if(d[i].size>vision.ugc.filelimit){alert("The file you have chosen is too large. Please select a smaller file (max "+e+"mb).");var d="";return false}else{vision.ugc.filesAttached=true;a.dom.get("#vision-ugc-uploadButton").removeAttr("disabled");a.dom.get("#vision-ugc-uploadButton").removeClass("disabled");var c="Selected: "+d[i].name;c+=' <a href=\'\' id="vision-ugc-remove" onclick="vision.ugc.bridge.unsetSelectedFiles(\'vision.ugc.onUnsetSelectedFiles\');return false" title="remove file selection"><img src="/apps/vision/'+vision.ugc.version+'/ugc/css/f/remove.gif" alt="remove file" /></a>';a.dom.get("#vision-ugc-filelist").html(c);vision.ugc.set_enabled("vision-ugc-uploadButton",true)}}}else{vision.ugc.filesAttached=false}},validate:function(){var b=new a.forms.Form("#vision-ugc-form");if(vision.ugc.title=="required"){b.addTests("user_title",["required",{on:"submit change idle",message:"Please complete this field"}])}b.addTests("source",["required",{on:"submit change idle",message:"Please choose a category"}]);if(vision.ugc.description=="required"){b.addTests("user_description",["required",{on:"submit change idle",message:"Please complete this field"}])}if(vision.ugc.category=="required"){b.addTests("user_category",["required",{on:"submit change idle",message:"Please complete this field"}])}if(vision.ugc.additional=="required"){b.addTests("user_additional",["required",{on:"submit change idle",message:"Please complete this field"}])}if(vision.ugc.name=="required"&&a.dom.get("#vision-ugc-name")[0]){b.addTests("user_name",["required",{on:"submit change idle",message:"Please complete this field"}])}if(vision.ugc.location=="required"){b.addTests("user_location",["required",{on:"submit change idle",message:"Please complete this field"}])}if(vision.ugc.datefrom=="required"){b.addTests("user_datefrom",["required",{on:"submit change idle",message:"Please complete this field"}])}if(vision.ugc.dateto=="required"){b.addTests("user_dateto",["required",{on:"submit change idle",message:"Please complete this field"}])}if(vision.ugc.email=="required"){b.addTests("user_email",["required",{on:"submit change idle",message:"Please complete this field"}],["isEmail",{on:"submit change idle",message:"Please correct this field"}])}b.addTests("terms_agreed",["required",{on:"submit change idle",message:"You must accept the terms and conditions"}]);a.events.addListener(b,"validate",function(c){if(c.eventName=="submit"&&c.errorCount==0){if(flashMode=="true"){vision.ugc.onUpload();return false}else{return}}})},onUpload:function(){var b=a.dom.get("#vision-ugc-form").val();vision.ugc.toggleFields("disabled");a.dom.get(".vision-ugc-submit").html('<input id="vision-ugc-cancelButton" type="button" value="Cancel" name="cancel" onclick="return vision.ugc.onAbort();" />');a.dom.get("#vision-ugc-progressbar").css("width","0%");vision.ugc.bridge.upload(b,"vision.ugc.onItemCompleted","vision.ugc.onUploadCompleted","vision.ugc.progressHandler")},toggleFields:function(b){if(b=="disabled"){a.dom.get("#vision-ugc-form input").attr("disabled","disabled");a.dom.get("#vision-ugc-form input").addClass("disabled");a.dom.get("#vision-ugc-form textarea").attr("disabled","disabled");a.dom.get("#vision-ugc-form textarea").addClass("disabled")}else{if(b=="enabled"){a.dom.get("#vision-ugc-form input").removeAttr("disabled");a.dom.get("#vision-ugc-form input").removeClass("disabled");a.dom.get("#vision-ugc-form textarea").removeAttr("disabled");a.dom.get("#vision-ugc-form textarea").removeClass("disabled")}else{return}}},onAbort:function(){vision.ugc.bridge.abort()},onUploadCompleted:function(f,d){var e=document.getElementById("vision-ugc-form");var c=e.innerHTML;var b=a.dom.get("#vision-ugc-form").height();vision.ugc.bridge=null;setTimeout(function(){e.innerHTML="<h3>"+vision.ugc.thankyou+"</h3><p>"+vision.ugc.thankstext+"</p><p>"+vision.ugc.thanksmsg+"</p><p><a href='"+vision.ugc.thanksreturn+"' id='vision-ugc-formreturn'>Upload</a> another "+vision.ugc.assettype+".";a.dom.get("#vision-ugc-form").height(b);if(vision.ugc.thanksreturn=="#vision-ugc-add"){a.events.addListener("#vision-ugc-formreturn","click",function(){e.innerHTML=c;vision.ugc.toggleFields("enabled");a.dom.get("#vision-ugc-filelist").html("");vision.ugc.resetForm();a.dom.get(".vision-ugc-submit").html('<input id="vision-ugc-uploadButton" type="submit" value="Upload" name="submit" />');a.dom.get("#vision-ugc-sent-bytes").html("0");a.dom.get("#vision-ugc-total-bytes").html("0mb");a.dom.get("#vision-ugc-progressbar").css("width","0%");if(vision.ugc.sourcecategory=="true"){vision.ugc.getSource()}a.dom.get("#vision-ugc-uploadButton").addClass("disabled");a.dom.get("#vision-ugc-uploadButton").attr("disabled","")})}},0);if(vision.ugc.formclear!="false"){}a.dom.get("#vision-ugc-filelist").html("Selected: ")},resetForm:function(){var b=a.dom.get("#vision-ugc-form input");b.each(function(){if(this.type=="text"||this.type=="file"||this.type=="password"){this.value=""}})},onItemCompleted:function(){},errorHandler:function(b){alert(b);vision.ugc.echo("ActionScript says error: "+b)},progressHandler:function(c){a.dom.get(".vision-panel-bd").html("<p><strong><span id='vision-ugc-status'>Uploading</span></strong> <br>"+c.fileName+"</p>");var e=Math.round(c.bytesLoaded/1048576*100000)/100000;var b=Math.round(c.bytesTotal/1048576*100000)/100000;var f=Math.round(e*Math.pow(10,2))/Math.pow(10,2);var d=Math.round(b*Math.pow(10,2))/Math.pow(10,2);a.dom.get("#vision-ugc-sent-bytes").html(f);a.dom.get("#vision-ugc-total-bytes").html(d+"mb");percentage=(c.bytesLoaded/c.bytesTotal)*100;a.dom.get("#vision-ugc-progressbar").css("width",percentage+"%")},getMovie:function(b){return document.getElementById(b)},echo:function(b){document.getElementById("vision-ugc-output").innerHTML+=b+"\n"},echoFiles:function(b){document.getElementById("vision-ugc-filelist").innerHTML+=b+"\n"},set_enabled:function(c,b){document.getElementById(c).disabled=b?false:true},bridgeLoaded:function(){vision.ugc.bridge=new VisionUpload(vision.ugc.getMovie("UploadBridge"),"vision.ugc.onBridgeReady",{Server:"bbc.co.uk",ErrorCallback:"vision.ugc.errorHandler"},vision.ugc.source,"vision.ugc.onBrowseCompleted","Image");if(vision.ugc.sourcecategory=="true"){var b=a.dom.get("#vision-ugc-source-categories").val();vision.ugc.bridge.setSource(b)}},confirmAbort:function(){var b=confirm("Are you sure you want to cancel this upload?");if(b){vision.ugc.onAbort()}else{return}},hideFlashControls:function(){a.dom.get("#vision-ugc-add").addClass("non-flash");a.dom.get("#vision-ugc-browseButton").css("display","none");a.dom.get("#vision-ugc-filelist").css("display","none");a.dom.create("<iframe name='hiframe' id='hiframe'></iframe>").appendTo("#vision-ugc-form");a.dom.get("#vision-ugc-successpage").attr("value","/apps/vision/"+vision.ugc.version+"/ugc/includes/end.shtml");var b=a.dom.get("#vision-ugc-form");b.attr("target","hiframe");vision.ugc.filesAttached=true},hideFallbackcontrols:function(){a.dom.get("#vision-ugc-submitnonflash").css("display","none");a.dom.get("#vision-ugc-filenonflash").css("display","none")}};gloader.load(["glow","1","glow.dom","glow.events","glow.data","glow.net","glow.embed","glow.forms","glow.widgets.Panel","glow.widgets.InfoPanel","glow.anim"],{async:true,onLoad:function(b){a=b;a.ready(vision.ugc.init)}})})();