var ALREADY_ADDED_FILE="Error: File has already been added\nPlease select another one or hit the convert button";
var NO_EXTENSION="Error: File has no extension\nPlease select one that has and try again";
var MISMATCHED_EXTENSION="Error: When selecting multiple files, ensure that they all have the same extension";
var UNSUPPORTED_EXTENSION="Filetype conversion is not currently supported for \"";
var NO_FILES_SELECTED="Error: Upload at least one file before trying to convert";
var CONVERT_CANCELLED_MESSAGE="Please modify your information or file selections and try again";
var EXCEEDED_MAX_FILES1="Error: The maximum number of files you can upload is "
var EXCEEDED_MAX_FILES2="\nJust remove ";
var EXCEEDED_MAX_FILES3=" and try again\n";
var NOTOEXT_ERROR_MSG = "Please select a file format to convert to";
var FILELIST_HEADER_STYLE="fileListHeader";
var FILELIST_UPLOAD_STYLE="body";
var FILELIST_TEXT="<span class='"+FILELIST_HEADER_STYLE+"'>Files to convert:</span>"
var REMOVE_BUTTON_TEXT="Remove File"
var STATUS_SCRIPT="cgi-bin/getStatus.pl";
var CONVERSION_SCRIPT="cgi-bin/handleFileUpload.pl";
var BACKGROUND_COLOUR_DARK="#CCCCCC";
var BACKGROUND_COLOUR_LIGHT="#F2F2F2";
var toExt="";
var toEmail="";
var noLogErrorCount=0;
var formKeyErrorCount=0;
var badXMLErrorCount=0;
var badHTTPRespCount=0;
var currentUploadedTotalSizeKB=0;
var titleOrig=document.title;
var sendSessionID=false;
function fileArrayAdd(fileName){
fileName=untaintString(fileName);
fileArray.push(fileName);
}
function fileArrayRemove(fileName){
fileName=untaintString(fileName);
for (i=0;i< fileArray.length; i+=1){
if(fileArray[i] == fileName){
fileArray[i]="";
}
}
}
function getNextFileFromFileArray(){
var fileName="null";
for (i=0;i< fileArray.length; i+=1){
if(fileArray[i] != ""){
return fileArray[i];
}
}
return fileName;
}   
function fileArraySearch(fileName){
fileName=untaintString(fileName);
var found=false;
for (i=0;i< fileArray.length; i+=1){
if(fileArray[i] == fileName){
found=true;
break;
}
}
return found;
}
function fileExtensionCheck(fileExtension){
var match=false;
for (i=0;i< fileArray.length; i+=1){
if(fileArray[i].toUpperCase().indexOf(fileExtension.toUpperCase()) != -1){
match=true;
break;
}
}
return match;
}
function getFileExtension(fileName){
fileName=untaintString(fileName);
var extension="";
var extensionIndex=fileName.lastIndexOf('.');
if (extensionIndex != -1){
extension=fileName.slice(fileName.lastIndexOf('.')+1);
}
return extension;
}
function isFileSupported(fileExtension){
var retn;
var isSupported = false;
eval("try { if(isNaN(retn = eval(fileExtension))) retn=-1; } catch (e) { retn=-2; }");
if(retn == -1) isSupported=true;
return isSupported;
}
function doFuzzyMatch(fileExtension){
for(var i=0; i<fuzzyMatchArray.length; i+=2){
if (fuzzyMatchArray[i] == fileExtension){
fileExtension=fuzzyMatchArray[i+1];
break;
}
}
return fileExtension;
}
function inputFieldRemove(fieldToRemove){
for (var i=0 ;i< document.fileForm.elements.length ;i+= 1){
if (fieldToRemove == document.fileForm.elements[i].value){
var fileInputElementParent=document.getElementById("fileInputElementParent");
fileInputElementParent.removeChild(document.fileForm.elements[i]);
}
}
}
function resetFileForm(uploadTableCell){
for (var i=0 ;i< document.fileForm.elements.length ;i+= 1){
document.fileForm.elements[i].disabled=false;
}
document.getElementById("headerDiv1").innerHTML="<div class='ruler'></div>";
document.getElementById("headerDiv2").innerHTML=FILELIST_TEXT;
uploadTableCell.innerHTML="";
document.title=titleOrig;
disableAds();
}
function disableFileFormBrowseButton(){
document.fileForm.elements[0].disabled=true;
}
function enableFileFormBrowseButton(){
document.fileForm.elements[0].disabled=false;
}
function hideSelectList(){
document.getElementById("toExtensionSel").style.visibility="hidden";
}
function showSelectList(){
document.getElementById("toExtensionSel").style.visibility="visible";
}
function FileList( list_target ){
this.list_target=list_target;
count=0;
this.id=0;
fileArray=new Array();
var headerDiv1=document.getElementById("headerDiv1");
var headerDiv2=document.getElementById("headerDiv2");
var fileInputElementParent=document.getElementById("fileInputElementParent");
var fileTable=document.getElementById("fileTable");
var fileCounter=document.getElementById("fileCounter");
document.getElementById("uid").value=clientUID;
function clearTextBox(element){
var myForm=element.form;       
var myInput=document.createElement( 'input' );
myInput.type='file';
myInput.size='12';
myInput.name=element.name;
myInput.id=element.id;
myInput.multi_selector=element.multi_selector;
myInput.value=null;
myInput.className='bodyBig';     
myInput.onchange=function(){
var fileExtension=getFileExtension(myForm.elements[0].value).toLowerCase();
if (fileExtension == ""){
clearTextBox(myForm.elements[0]);
alert(NO_EXTENSION);
return false;
}
fileExtension=doFuzzyMatch(fileExtension);
if (!isFileSupported(fileExtension)){
clearTextBox(myForm.elements[0]);
alert(UNSUPPORTED_EXTENSION + fileExtension + "\"");
return;
}
if (count == 0){ 
changeFormExtensionValue(fileExtension);
}
if (fileArraySearch(myForm.elements[0].value)){ 
clearTextBox(myForm.elements[0]);
alert(ALREADY_ADDED_FILE);                    
return;
}        
if (count != 0 && fileExtensionCheck(fileExtension) != true){                     
clearTextBox(myForm.elements[0]);
alert(MISMATCHED_EXTENSION);                    
return false;
}
var new_element=document.createElement( 'input' );
this.style.position='absolute';
this.style.left='-1000px';
new_element.type='file';
new_element.size='12';
new_element.className='bodyBig';
this.parentNode.insertBefore( new_element, this );
this.multi_selector.addElement( new_element );
this.multi_selector.addListRow( this );
};
fileInputElementParent.replaceChild(myInput, element);
}
this.addElement=function( element ){        
if( element.tagName == 'INPUT' && element.type == 'file' ){    
element.name='file_' + this.id++; 
element.multi_selector=this;
element.onchange=function(){
var fileExtension=getFileExtension(element.value).toLowerCase();
if (fileExtension == ""){
clearTextBox(element);
alert(NO_EXTENSION);                    
return false;
}
fileExtension=doFuzzyMatch(fileExtension);
if (!isFileSupported(fileExtension)){
clearTextBox(element);
alert(UNSUPPORTED_EXTENSION + fileExtension + "\"");                    
return;
}
if (count == 0){ 
changeFormExtensionValue(fileExtension);
}
if (fileArraySearch(element.value)){ 
clearTextBox(element);
alert(ALREADY_ADDED_FILE);                    
return;
}        
if (count != 0 && fileExtensionCheck(fileExtension) != true){                     
clearTextBox(element);
alert(MISMATCHED_EXTENSION);
return false;
}
var new_element=document.createElement( 'input' );
this.style.position='absolute';
this.style.left='-1000px';
new_element.type='file';
new_element.size='12';
new_element.className='bodyBig';
this.parentNode.insertBefore( new_element, this );
this.multi_selector.addElement( new_element );
this.multi_selector.addListRow( this );
};
this.current_element=element;
} 
};
this.addListRow=function( element ){
fileArrayAdd(element.value);     
fileCounter.value=count;
count++;
var new_row_button=document.createElement( 'input' );
new_row_button.type='button';
new_row_button.className='bodyBig';
new_row_button.value=REMOVE_BUTTON_TEXT;
if(count == 1){
headerDiv1.innerHTML="<div class='ruler'></div>";
headerDiv2.innerHTML=FILELIST_TEXT;
}       
tr0=fileTable.insertRow(0);
tr0.id=untaintString(element.value) + "tr0";
tr1=fileTable.insertRow(1);
tr2=fileTable.insertRow(2);
tr2.id=untaintString(element.value) + "tr2";
var backgroundImageColor="dk";
var backgroundColor=BACKGROUND_COLOUR_DARK;
tr1.style.backgroundColor=backgroundColor; 
if (fileTable.rows[3] != null){
if (fileTable.rows[3].childNodes[0].style.backgroundImage.indexOf("corner_dk") != -1){
backgroundImageColor="lt";
backgroundColor=BACKGROUND_COLOUR_LIGHT;
tr1.style.backgroundColor=backgroundColor;
}
}
td1=tr0.insertCell(0);
td1.style.backgroundImage="url(images/corner_" + backgroundImageColor + "_tl.gif)";
td1.innerHTML="<img src='images/clear.gif' height='7' width='7'>";
td1.style.width=7 + "px";;
td2=tr0.insertCell(1);
td2.style.backgroundColor=backgroundColor; 
td3=tr0.insertCell(2);
td3.style.backgroundColor=backgroundColor; 
td4=tr0.insertCell(3);
td4.style.backgroundColor=backgroundColor; 
td5=tr0.insertCell(4);
td5.style.backgroundColor=backgroundColor; 
td6=tr0.insertCell(5);
td6.style.backgroundImage="url(images/corner_" + backgroundImageColor + "_tr.gif)";
td6.innerHTML="<img src='images/clear.gif' height='7' width='7'>";
td6.style.width=7 + "px";
td7=tr1.insertCell(0);
td8=tr1.insertCell(1);
if(element.value.length < 100) {
td8.className = "nowrapping";
}
td8.innerHTML = element.value;
td9 = tr1.insertCell(2);
td9.className = "nowrapping";
td9.innerHTML = "&nbsp;&nbsp;&nbsp;";
td9.appendChild(new_row_button);
td10=tr1.insertCell(3);
td10.innerHTML="&nbsp;&nbsp;";
td11=tr1.insertCell(4);
td11.width="100%";
td11.id=untaintString(element.value) + "uploadTableCell"; 
td12=tr1.insertCell(5);
td13=tr2.insertCell(0);
td13.style.backgroundImage="url(images/corner_" + backgroundImageColor + "_bl.gif)";
td13.innerHTML="<img src='images/clear.gif' height='7' width='7'>";
td13.style.width=7 + "px";
td14=tr2.insertCell(1);
td14.style.backgroundColor=backgroundColor; 
td15=tr2.insertCell(2);
td15.style.backgroundColor=backgroundColor; 
td16=tr2.insertCell(3);
td16.style.backgroundColor=backgroundColor; 
td17=tr2.insertCell(4);
td17.style.backgroundColor=backgroundColor;
td18=tr2.insertCell(5);
td18.style.backgroundImage="url(images/corner_" + backgroundImageColor + "_br.gif)";
td18.innerHTML="<img src='images/clear.gif' height='7' width='7'>";
td18.style.width=7 + "px";
if (count >= MAXFILEUPLOADNUMBER){ 
disableFileFormBrowseButton();
}
new_row_button.onclick= function(){
var rowRefNum=this.parentNode.parentNode.rowIndex;
if (rowRefNum != fileTable.rows.length && rowRefNum != 1){
if ((fileTable.rows[rowRefNum].style.backgroundColor.indexOf("cccccc") == 1) || (fileTable.rows[rowRefNum].style.backgroundColor.indexOf("204") == 4)){
convertRowsToLight(rowRefNum, fileTable);
convertRowsToDark(rowRefNum + 3, fileTable);
} else{
convertRowsToDark(rowRefNum, fileTable);
convertRowsToLight(rowRefNum + 3, fileTable);
}
}
fileArrayRemove(element.value); 
fileCounter.value=count;
this.parentNode.parentNode.parentNode.removeChild( document.getElementById(untaintString(element.value) + "tr0"));
this.parentNode.parentNode.parentNode.removeChild( document.getElementById(untaintString(element.value) + "tr2"));
this.parentNode.parentNode.parentNode.removeChild( this.parentNode.parentNode );
count--;   
inputFieldRemove(element.value);
if(count == 0){
headerDiv1.innerHTML="";
headerDiv2.innerHTML="";
resetToExtensionValues();
}
if(count < MAXFILEUPLOADNUMBER){
enableFileFormBrowseButton();
}
return false;
};
};
};
function changeFormExtensionValue(fileExtension){
var optionArray=eval(fileExtension);
var toExtensionSel=document.fileForm.toExtensionSel;
for(var i=0; i<optionArray.length; i++){
toExtensionSel.options.length=0;
for(var j=0; j<optionArray.length; j++){
var toValue=optionArray[j];
toExtensionSel.options[j]=new Option(toValue,toValue);
}
}
toExtensionSel.value=toExtensionSel.options[1].value;
currentFromValue=fileExtension;
}
function resetToExtensionValues() {
var toExtensionSel=document.fileForm.toExtensionSel;
for(var i=0;i<toArray.length;i++) {
toExtensionSel.options.length=0;
for(var j=0;j<toArray.length;j++) {
var toValue=toArray[j];
toExtensionSel.options[j]=new Option(toValue,toValue);
if (toExtensionSel.options[j].value.indexOf("--") != -1){
toExtensionSel.options[j].className="optionHeader";
}
}
}
toExtensionSel.value=toExtensionSel.options[0].value;
}
var http_request=null;
var xml=null;
function displayState(){
if (http_request.readyState == 4){
if (http_request.status == 200){
if (typeof window.ActiveXObject == 'undefined'){
xml=http_request.responseXML;
} else{
xml=new ActiveXObject('Microsoft.XMLDOM');
xml.loadXML(http_request.responseText)
}
var statusType=xml.getElementsByTagName("type")[0].firstChild.nodeValue;
var status=xml.getElementsByTagName("status")[0].firstChild.nodeValue;
var fileName=xml.getElementsByTagName("filename")[0].firstChild.nodeValue;
var uploadTableCell=document.getElementById(fileName + "uploadTableCell");
var uploadStatusDiv=document.getElementById("uploadStatusDiv"); 
var uploadTextDiv=document.getElementById("uploadText");
if (noLogErrorCount > 20){
alert(genErr("101-"+sn+"-"+tcs));
fileArray.reverse();
resetFileForm(uploadTableCell);
noLogErrorCount=0;
return false;
}
if (formKeyErrorCount > 100){
alert(genErr("102-"+sn+"-"+tcs));
fileArray.reverse(); 
resetFileForm(uploadTableCell);
formKeyErrorCount=0; 
return false;
}
if (statusType.indexOf("noLogError") != -1){
submitAjaxReq(STATUS_SCRIPT + "?action=&uid=" + clientUID + "&fileName=" + escape(fileName) + "&type=upload&toExtensionSel=" + toExt + "&fileCounter=" + count + "&tcs=" + tcs);
noLogErrorCount ++; 
}
if (statusType.indexOf("maxFileError") != -1){
if (status.indexOf("0 MB") != -1){
submitAjaxReq(STATUS_SCRIPT + "?action=&uid=" + clientUID + "&fileName=" + escape(fileName) + "&type=upload&toExtensionSel=" + toExt + "&fileCounter=" + count + "&tcs=" + tcs);
} else{
alert(status + "\nPlease amend your file selections and try again.");
fileArray.reverse(); 
resetFileForm(uploadTableCell);
}
}
if (statusType.indexOf("maxSizeError") != -1){
alert(status + "\n\nTo convert bigger files signup for a Zamzar account (supports up to 1 GB)");
fileArray.reverse(); 
resetFileForm(uploadTableCell);
}
if (statusType.indexOf("formKeyError") != -1){
submitAjaxReq(STATUS_SCRIPT + "?action=&uid=" + clientUID + "&fileName=" + escape(fileName) + "&type=upload&toExtensionSel=" + toExt + "&fileCounter=" + count + "&tcs=" + tcs);
formKeyErrorCount ++; 
}
if(statusType.indexOf("invalidEmailError") != -1){
alert(status + "\n\nPlease check the email address you entered and try converting again.");
fileArray.reverse();
resetFileForm(uploadTableCell);
}
if(statusType.indexOf("upload")!=-1){
var estimatedTimeRemaining=0;
var percentComplete=-1;
var us=xml.documentElement.getElementsByTagName("uploadSize")[0].firstChild;
var et=xml.documentElement.getElementsByTagName("elapsedTime")[0].firstChild;
var tus=xml.documentElement.getElementsByTagName("totalUploadSize")[0].firstChild;
if(us&&et&&tus){
var uploadSizeKB=bytesToKB(us.nodeValue);
var elapsedTime=et.nodeValue;
var totalUploadSizeKB=bytesToKB(tus.nodeValue);
if(isNaN(elapsedTime)||elapsedTime==0){
var KBPerSecond=10;
}else{
var KBPerSecond=Math.ceil(uploadSizeKB/elapsedTime);
}
elapsedTime=secsToMins(elapsedTime);
var percentComplete=Math.ceil((100 / totalUploadSizeKB) * (currentUploadedTotalSizeKB + uploadSizeKB));
var estimatedTimeRemaining=secsToMins((totalUploadSizeKB - (currentUploadedTotalSizeKB + uploadSizeKB)) / KBPerSecond);
if (totalUploadSizeKB > 1024) var totalUploadSizeText=KBtoMB(totalUploadSizeKB) + " MB";
else var totalUploadSizeText=totalUploadSizeKB + " KB";
if ((currentUploadedTotalSizeKB + uploadSizeKB) > 1024) currentUploadedTotalSizeText=KBtoMB((currentUploadedTotalSizeKB + uploadSizeKB)) + " MB";
else var currentUploadedTotalSizeText=(currentUploadedTotalSizeKB + uploadSizeKB) + " KB";
}else{
badXMLErrorCount++;
if(badXMLErrorCount>30){
alert(genErr("103-"+sn+"-"+tcs));
fileArray.reverse(); 
resetFileForm(uploadTableCell);
badXMLErrorCount=0; 
return false;
}
}
if(percentComplete != -1 && uploadStatusDiv.innerHTML.indexOf("100%") == -1){
uploadStatusDiv.innerHTML=percentComplete + "% completed (" + currentUploadedTotalSizeText + " of " + totalUploadSizeText + ")";
setProgressBarPercent(percentComplete);
setTitlePercent(percentComplete);
}
if(estimatedTimeRemaining != 0 && uploadTextDiv.innerHTML.indexOf("complete") == -1){
uploadTextDiv.innerHTML="<span class='"+FILELIST_UPLOAD_STYLE+"'>Uploading - Estimated time left: " + estimatedTimeRemaining
}
if(status.indexOf("complete") != -1){
if(uploadSizeKB > 1024) uploadSizeText=KBtoMB(uploadSizeKB) + " MB";
else uploadSizeText=uploadSizeKB + " KB";
currentUploadedTotalSizeKB += uploadSizeKB;
uploadTableCell.innerHTML="<span class='nowrapping'>Upload complete</span><br/><span class='nowrapping'>" + uploadSizeText + " in " + elapsedTime;
fileArrayRemove(fileName);
fileName=getNextFileFromFileArray();
tempFileName=fileName;
if(fileName.indexOf("null") == -1){
uploadTableCell=document.getElementById(fileName + "uploadTableCell");;
uploadTableCell.innerHTML="Uploading&nbsp;&nbsp;" + PROGRESS_CIRCLE_IMAGE;
submitAjaxReq(STATUS_SCRIPT + "?action=&uid=" + clientUID + "&fileName=" + escape(fileName) + "&type=upload&toExtensionSel=" + toExt + "&fileCounter=" + count + "&tcs=" + tcs);
}else{
document.getElementById("uploadText").innerHTML="<span class='"+FILELIST_UPLOAD_STYLE+"'>Upload complete</span>";
uploadStatusDiv.innerHTML="100% completed (" + totalUploadSizeText + " of " + totalUploadSizeText + ")";
setProgressBarPercent(100);
setTitlePercent(100);
if(count == 1){
window.setTimeout('window.location="uploadComplete.php?convertFile="+currentFromValue+"&to="+toExt', 3000);
}else{
window.setTimeout('window.location="uploadComplete.php?convertFiles="+currentFromValue+"&to="+toExt', 3000);
}
}
}else{
submitAjaxReq(STATUS_SCRIPT + "?action=&uid=" + clientUID + "&fileName=" + escape(fileName) + "&type=upload&toExtensionSel=" + toExt + "&fileCounter=" + count + "&tcs=" + tcs);
}
}
}else if(http_request.status==500){
badHTTPRespCount++;
if(badHTTPRespCount>20){
alert(genErr("104-"+sn+"-"+tcs));
fileArray.reverse();
uploadTableCell=document.getElementById(tempFileName + "uploadTableCell");
resetFileForm(uploadTableCell);
badHTTPRespCount=0; 
return false;
}else{
submitAjaxReq(STATUS_SCRIPT + "?action=&uid=" + clientUID + "&fileName=" + escape(fileName) + "&type=upload&toExtensionSel=" + toExt + "&fileCounter=" + count + "&tcs=" + tcs);
}
}
}
}
function submitAjaxReq(script){
if (typeof window.ActiveXObject != 'undefined'){
try{
http_request=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e){
try{
http_request=new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){}
}   
http_request.onreadystatechange=displayState;
} else{
http_request=new XMLHttpRequest();
http_request.onload=displayState;
if(http_request.overrideMimeType){
http_request.overrideMimeType('text/xml');
}
}
http_request.open( "GET", script, true );
window.setTimeout('http_request.send(null)', 2000);
}
function handleFormSubmit(){
var filetext="";
if (count == 1){
fileText= " file";
} else{
fileText= " files";
}
if (count != 0){
if (count > MAXFILEUPLOADNUMBER){
var maxFileAlert=EXCEEDED_MAX_FILES1 + MAXFILEUPLOADNUMBER + EXCEEDED_MAX_FILES2 + (count-MAXFILEUPLOADNUMBER) + EXCEEDED_MAX_FILES3;
var isEmailValidMessage=checkValidEmail(document.fileForm.toEmail.value);
if (isEmailValidMessage.indexOf("false") == -1){
maxFileAlert += "\n\nAlso please note - " + isEmailValidMessage;
}
alert(maxFileAlert);
} else{  
var isEmailValidMessage=checkValidEmail(document.fileForm.toEmail.value);
if (isEmailValidMessage.indexOf("false") == -1){
alert(isEmailValidMessage);
} else{
if (document.fileForm.toExtensionSel.value.indexOf (CHOOSE_TEXT) != -1) {
alert(NOTOEXT_ERROR_MSG);
return;
} else {
currentFromValue=normaliseFromValue(currentFromValue);
var PRE_CONVERT_MESSAGE="About to convert " +
count + fileText + " from " +
currentFromValue.toUpperCase() + " to " +
document.fileForm.toExtensionSel.value.toUpperCase() +
"\n\nThe link to your converted" + fileText + confirmMsg + document.fileForm.toEmail.value +
"\n\nPress \"OK\" to start or \"Cancel\" to amend your details";
}
if (confirm(PRE_CONVERT_MESSAGE)){
toExt=document.fileForm.toExtensionSel.value;
toEmail=document.fileForm.toEmail.value;
var actionString=CONVERSION_SCRIPT + '?' + currentFromValue + ';' + toExt + ';' + clientUID + ';' + toEmail + ';' + count + ';' + sessionID + ';' + fk;
if(sendSessionID){
actionString += ";"+sessionID;
} else{
actionString += ";0";
}
actionString+=";tcs"+tcs;
document.fileForm.action=actionString;
fileArray.reverse();
enableAds();
var fileName=getNextFileFromFileArray();
tempFileName=fileName;
var uploadTableCell=document.getElementById(fileName + "uploadTableCell");
uploadTableCell.innerHTML="<span class='"+FILELIST_UPLOAD_STYLE+"'>Uploading&nbsp;&nbsp;</span>" + PROGRESS_CIRCLE_IMAGE;
document.getElementById("headerDiv1").innerHTML="<div class='ruler'></div>";
document.getElementById("headerDiv2").innerHTML=FILELIST_TEXT + "<br/>&nbsp;<br/><div id='uploadText'>Uploading - Please wait ...<br></div>" + progressBarInit() + "<br>";
submitAjaxReq(STATUS_SCRIPT + "?action=&uid=" + clientUID + "&fileName=" + escape(fileName) + "&type=upload&toExtensionSel=" + toExt + "&fileCounter=" + count + "&tcs=" + tcs);
window.setTimeout('disableForm(\'fileForm\')',500);
} else{
alert(CONVERT_CANCELLED_MESSAGE);
sendSessionID=true;
}
}
}
} else{
alert(NO_FILES_SELECTED);
}    
}
function untaintString(myString){
var re=/^.*(\/|\\)/;
myString=myString.replace(re,"");
re=/[,`\*\?\|<>'"’]/g;
myString=myString.replace(re,"");
re=/\+/g;
myString=myString.replace(re," ");
return myString;
}
function bytesToKB(bytes){
var kb=Math.ceil(bytes/1024);
return kb;
}
function KBtoMB(kb){
var mb=kb/1024;
if (mb.toFixed){
mb=mb.toFixed(1);
} else{
mb=Math.ceil(mb);
}
return mb;
}
function secsToMins(seconds){
seconds=Math.floor(seconds);
var timeString=seconds + " secs";
if (seconds >= 60){
var mins=Math.floor(seconds/60);
seconds=seconds%60;
timeString=mins + " mins " + seconds + " secs";
if (mins == 1){
timeString=mins + " min " + seconds + " secs";
}
if (seconds == 1){
timeString=mins + " mins " + seconds + " sec";
}
if (mins == 1 && seconds == 1){
timeString=mins + " min " + seconds + " sec";
}
}
return timeString;
}

function convertRowsToDark(rowRefNum, fileTable){
for (var i=rowRefNum;i< fileTable.rows.length ;i+= 6){
fileTable.rows[i].style.backgroundColor=BACKGROUND_COLOUR_DARK;
fileTable.rows[i-1].childNodes[0].style.backgroundImage="url(images/corner_dk_tl.gif)";
fileTable.rows[i-1].childNodes[5].style.backgroundImage="url(images/corner_dk_tr.gif)";
fileTable.rows[i+1].childNodes[0].style.backgroundImage="url(images/corner_dk_bl.gif)";
fileTable.rows[i+1].childNodes[5].style.backgroundImage="url(images/corner_dk_br.gif)";
for (var j=1; j < 5; j += 1){
fileTable.rows[i-1].childNodes[j].style.backgroundColor=BACKGROUND_COLOUR_DARK;
fileTable.rows[i+1].childNodes[j].style.backgroundColor=BACKGROUND_COLOUR_DARK;
}
}
}
function convertRowsToLight(rowRefNum, fileTable){
for (var i=rowRefNum;i< fileTable.rows.length ;i+= 6){
fileTable.rows[i].style.backgroundColor=BACKGROUND_COLOUR_LIGHT;
fileTable.rows[i-1].childNodes[0].style.backgroundImage="url(images/corner_lt_tl.gif)";
fileTable.rows[i-1].childNodes[5].style.backgroundImage="url(images/corner_lt_tr.gif)";
fileTable.rows[i+1].childNodes[0].style.backgroundImage="url(images/corner_lt_bl.gif)";
fileTable.rows[i+1].childNodes[5].style.backgroundImage="url(images/corner_lt_br.gif)";
for (var j=1; j < 5; j += 1){
fileTable.rows[i-1].childNodes[j].style.backgroundColor=BACKGROUND_COLOUR_LIGHT;
fileTable.rows[i+1].childNodes[j].style.backgroundColor=BACKGROUND_COLOUR_LIGHT;
}
}
}
function setTitlePercent(percent){
document.title=percent + "% Complete - Zamzar";
}
function enableAds() {
if(document.getElementById("uname")==null){
af=document.getElementById("adframe");
af.src="/zamzar-news.php";
af.style.visibility="visible";
af.style.width="400px";
af.style.height="80px";    
}
}
function disableAds() {
af=document.getElementById("adframe");
af.style.visibility="hidden";
af.style.width="0px";
af.style.height="0px";
}
function normaliseFromValue(fromValue){
if(fromValue.indexOf("threegp")!=-1)fromValue="3gp";
if(fromValue.indexOf("threegtwo")!=-1)fromValue="3g2";
return fromValue;
}
function genErr(msgNo){
return "There has been an internal error processing your request (Error "+msgNo+")\n\nPlease try re-submitting it";
}