// widget global vars var uid = gup("uid"); var channel_name = gup("channel_name"); var channel_email = gup("channel_email"); var skinname = gup("skinname"); var acct_id = gup("acct_id"); var folder_id = gup("folder_id"); var currentCount = 0; var selectedCount = 0; var currentStatus = "We are sending your files to the server."; var currentUploadPerc = 0; var redirect_url = removeParms(window.location.href); var upload_step = "upload"; var upload_status = gup("upload_status"); var upload_more = gup("um"); var error_occurred = false; var error_text = ""; // internal constants var UPLOAD_QUOTA_HIT_IND = "Q"; var UPLOAD_INVALID_FROM = "invldfrom"; var UPLOAD_LIMIT_HIT_IND = "L"; var UPLOAD_PROCESSING_STARTED = "P"; var UPLOAD_PROCESSING_DONE = "F"; var UPLOAD_PROCESSING_ERROR = "E"; var UPLOAD_COULD_NOT_GET_STATUS_MSG = "Retrieving upload status"; var UPLOAD_COULD_NOT_GET_STATUS = "N"; var UPLOAD_PROCESSING_ERROR_MSG = "These files could not be processed:"; var UPLOAD_STEP = "upload"; var UPLOAD_PROCESSING_STEP = "processing"; function submitUpload(from_email,to_email,sub_acct_id,sub_folder_id,sub_channel_name,sub_channel_email, skin_name, uid_seq) { if(checkFiles() && document.getElementById("uploadstatuslayer").style.visibility=="hidden") { location.hash=""; acct_id = sub_acct_id; folder_id = sub_folder_id; channel_name = sub_channel_name; channel_email = sub_channel_email; redirect_url = addParm(redirect_url,"acct_id",acct_id); redirect_url = addParm(redirect_url,"folder_id",folder_id); redirect_url = addParm(redirect_url,"channel_name",channel_name); redirect_url = addParm(redirect_url,"channel_email",channel_email); redirect_url = addParm(redirect_url,"skinname",skin_name); if (document.getElementById("moreupload").style.display=="block") redirect_url = addParm(redirect_url,"um","Y"); upload_step = UPLOAD_STEP; selectedCount = getSelectedFileCount(); uid=(uid_seq+"."+acct_id+"."+folder_id); document.forms.pickleupload.action = upload_url + "?redirect="+escape(addParm(redirect_url,"uid",uid))+ //+"#puw")+ "&uploadmethod=452"+ "&fromea="+from_email+ "&toea="+to_email+ "&uid="+uid+ "&cq=y"+ "&fc="+selectedCount; displayStatus("Pickle is sending your files",0); showStatusLayer(); try { document.forms.pickleupload.submit(); } catch (err) { hideStatusLayer(); alert ("One of the files selected to upload does not exist."); return false; } getStatusHtml(); } else return false; } function showUploadWidget() { if (upload_more!="") showUploadMore(); if (upload_status!="") { //document.location.hash="puw"; checkAndShowErrors(); } if (uid!="") { //document.location.hash="puw"; upload_step = UPLOAD_PROCESSING_STEP; displayStatus("Pickle is processing your files"); showStatusLayer(); getStatusHtml(); } else upload_step = UPLOAD_STEP; } function displayStatus(currentStatusHtml) { var statlayer = document.getElementById("uploadstatuslayer"); statlayer.innerHTML = "
"+ "
"+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " " + "
"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "

Upload Status...

"+currentStatusHtml+"
"+ " "+ " "+ "
"+getBar()+"
"+ "
"+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ "
"+ "
"+ "
"+ "
"; } function displayErrorStatus(errorStatusHtml) { var statlayer = document.getElementById("uploadstatuslayer"); statlayer.innerHTML = "
"+ "
"+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ " " + "
"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ " "+ "

Upload Status...

"+errorStatusHtml+"
"+ " "+ " "+ "
 
"+ "
"+ "
"+ " "+ " "+ " "+ " "+ " "+ " "+ "
"+ "
"+ "
"+ "
"+ "
"; } function getSelectedFileCount() { var count=0; for (var c=0;c0) count++; } return count; } function checkFiles() { if (getSelectedFileCount()==0) { widgetLayerOnOff("pickleplayerobject","on"); alert("Please select at least one item to upload."); return false; } allowSubmit = false; extArray = new Array(".gif", ".jpg", ".jpeg", ".avi", ".wmv", ".mov", ".qtl", ".mpg", ".mpeg", ".3g2", ".3gp", ".mp4" ); for(var j=0 ;j < file_count; j++) { fileName = document.getElementById('pickleuploadfile'+j).value; while (fileName.indexOf("\\") != -1) { fileName = fileName.slice(fileName.indexOf("\\") + 1); } ext = fileName.slice(fileName.lastIndexOf(".")).toLowerCase(); for (var i = 0; i < extArray.length; i++) { if (extArray[i] == ext) { allowSubmit = true; break; } } if (!allowSubmit) { widgetLayerOnOff("pickleplayerobject","on"); alert("Please only upload files that end in types: " + (extArray.join(" ")) + "\nPlease select a new " + "file to upload and submit again."); break; } } return(allowSubmit); } function getStatusHtml() { var requester = null; try { requester = new XMLHttpRequest(); } catch (error) { try { requester = new ActiveXObject("Microsoft.XMLHTTP"); } catch (error) { requester = null; } } // ajaxCount variable prevents caching of Ajax results var ajaxCount=(new Date()).getTime(); requester.onreadystatechange = function(){ if (requester!=null && requester.readyState==4) { var responseArray = requester.responseText.split(";"); currentCount = responseArray[0]; selectedCount = responseArray[1]; currentStatus = responseArray[2]; currentUploadPerc = responseArray[3]; if (upload_step == UPLOAD_STEP && currentCount=="P") currentUploadPerc = 100; if (upload_step == UPLOAD_PROCESSING_STEP && currentCount>=0) currentUploadPerc = currentCount/selectedCount*100; // check for quota or limit or permissions error if (currentCount==UPLOAD_QUOTA_HIT_IND|| currentCount==UPLOAD_INVALID_FROM|| currentCount==UPLOAD_LIMIT_HIT_IND) { document.location = addParm(redirect_url,"upload_status",currentCount); setTimeout("redirect()",2500); return; } // check for processing error if (currentStatus==UPLOAD_PROCESSING_ERROR_MSG) { document.location = addParm(redirect_url,"upload_status",UPLOAD_PROCESSING_ERROR); setTimeout("redirect()",2500); return; } // check for error when status cannot be retrieved if (currentStatus==UPLOAD_COULD_NOT_GET_STATUS_MSG) { document.location = addParm(redirect_url,"upload_status",UPLOAD_COULD_NOT_GET_STATUS); setTimeout("redirect()",2500); return; } // display current status if (currentStatus!=null){ if (currentStatus==UPLOAD_COULD_NOT_GET_STATUS_MSG) displayStatus("Retrieving upload status"); else displayStatus(currentStatus); }else{ displayStatus("Your files have been processed."); } // get new status if (currentCount!="F") setTimeout("getStatusHtml()",3000); else { if (currentStatus.indexOf("could not be processed")>-1) { //redirect_url = addParm(redirect_url,"upload_status",UPLOAD_PROCESSING_ERROR); upload_status = UPLOAD_PROCESSING_ERROR; checkAndShowErrors(); return; } else setTimeout("redirect()",2500); } } } requester.open("GET",status_url+"?uid="+uid+ "&step="+upload_step+ "&fc="+currentCount+ "&ajaxCount="+ajaxCount); requester.send(null); return true; } function gup( name ) { var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var tmpURL = window.location.href; var results = regex.exec( tmpURL ); if( results == null ) return ""; else return results[1]; } function showStatusLayer() { widgetLayerOnOff("uploadstatuslayer", "on"); } function hideStatusLayer() { widgetLayerOnOff("uploadstatuslayer", "off"); } function widgetLayerOnOff(layerName, layerState) { if (layerState == "on") { if (document.getElementById) { document.getElementById(layerName).style.visibility = 'visible'; } else if (document.layers && document.layers[layerName]) { document.layers[layerName].visibility = 'visible'; } else if (document.all) { document.all[layerName].style.visibility = 'visible'; } } else { if (document.getElementById) { document.getElementById(layerName).style.visibility = 'hidden'; } else if (document.layers && document.layers[layerName]) { document.layers[layerName].visibility = 'hidden'; } else if (document.all) { document.all[layerName].style.visibility = 'hidden'; } } } function addParm(url,key,val) { if (url.indexOf("?")>-1) url = url + "&" + key + "=" + val; else url = url + "?" + key + "=" + val; return url; } function removeParms(url) { if (url.indexOf("?")>-1) return url.substring(0,url.indexOf("?")); else return url; } function redirect() { if (window.final_url) { redirect_url = final_url; } else if (redirect_url.indexOf("folder_id")==-1) { redirect_url = addParm(redirect_url,"acct_id",acct_id); redirect_url = addParm(redirect_url,"folder_id",folder_id); redirect_url = addParm(redirect_url,"channel_name",channel_name); redirect_url = addParm(redirect_url,"channel_email",channel_email); redirect_url = addParm(redirect_url,"skinname",skinname); if (document.getElementById("moreupload").style.display=="block") redirect_url = addParm(redirect_url,"um","Y"); } if (window.final_url) document.location = redirect_url; else document.location=redirect_url+"#puw"; } function getBar() { remainingBox=""; remainingPercentage = 100-currentUploadPerc; donePercentage = currentUploadPerc; if (currentUploadPerc<100) remainingBox = "" ; if (donePercentage==0) donePercentage=1; if (currentUploadPerc==100) colspan="2"; else colspan="1"; bar=""+ " "+ " " + " " + "
"+ " "+ " "+ " "+ remainingBox + " " + "
" + "
"; return bar; } function cancel() { document.location=upload_cancelled_url; } function checkAndShowErrors() { if (upload_status==UPLOAD_QUOTA_HIT_IND) { error_text="Sorry, this channel's monthly upload limit has been exceeded."; error_occurred=true; } if (upload_status==UPLOAD_LIMIT_HIT_IND) { error_text="You cannot upload more than 100MB.
  Please select under 100MB and upload again.
"; error_occurred=true; } if (upload_status==UPLOAD_INVALID_FROM) { error_text="You do not have permission to upload to the selected box."; error_occurred=true; } if (upload_status==UPLOAD_PROCESSING_ERROR) { error_text="Your upload was not processed successfully.
Please try again.
"; error_occurred=true; } if (upload_status==UPLOAD_COULD_NOT_GET_STATUS) { error_text="Your upload was not received. Please try again."; error_occurred=true; } if (error_occurred) { displayErrorStatus(error_text); showStatusLayer(); return; } } function getNewUid() { var requester = null; var uid = null; try { requester = new XMLHttpRequest(); } catch (error) { try { requester = new ActiveXObject("Microsoft.XMLHTTP"); } catch (error) { requester = null; } } // ajaxCount variable prevents caching of Ajax results var ajaxCount=(new Date()).getTime(); requester.onreadystatechange = function(){ if (requester!=null && requester.readyState==4) { uid = requester.responseText; } } requester.open("GET","generateuid.do?ajaxCount="+ajaxCount,false); requester.send(null); return uid; } showUploadWidget();