var exts = ".*";
//var exts = ".*"; //Use this to accept all Extensions

var UID,NF=0,cx=0;
function openStatusWindow()
{ 
 if(document.F1.popup.checked == true)
 { 
    win1 = window.open('/cgi-bin/upload_status.cgi?upload_id='+UID,'win1','width=350,height=240,resizable=1');
    win1.window.focus();
 } else {
   document.getElementById('status').style.left='0px';
   document.getElementById('status').src='/cgi-bin/upload_status.cgi?upload_id='+UID;
 }
}

function generateSID()
{
 UID = Math.round(10000*Math.random())+'0'+Math.round(10000*Math.random());
 var f1=document.F1;
 f1.action = f1.action.split('?')[0]+'?upload_id='+UID;
}

function StartUpload()
{
    NF=0;
    for (var i=0;i<document.F1.length;i++)
    {
     current = document.F1.elements[i];
     if(current.type=='file' && current.value!='')
      {
         if(!checkExt(current.value))return false;
         NF++;
      }
    }
    if(NF==0){alert('Select at least one file to upload');return false;};
    
    document.F1.action="/cgi-bin/upload.cgi?dir="+document.F1.dir+"&upload_id=";
    //document.F1.action="/cgi-bin/upload.cgi?upload_id=";
    generateSID();
    openStatusWindow();
    document.F1.target="upload";
    document.F1.submit();
    return true;
}

function checkExt(value)
{
    if(value=="")return true;
    var re = new RegExp("^.+\.("+exts+")$","i");
    if(!re.test(value))
    {
        alert("Extension not allowed for file: \"" + value + "\"\nOnly these extensions are allowed: "+exts.replace(/\|/g,',')+" \n\n");
        return false;
    }
    return true;
}

function submitToUpload_form()
{
        document.location.href = "upload_form.php?anz_uploads="+document.F1.anz_uploads.value;
        return true;
}
function submitToUpload_form2()
{
         var f = document.forms.F1;
        
        //f.mkdir.disabled = true;
        //document.F.location.href = "upload_form.php?a=new";

        f.action="upload_form.php?a=new";
        f.submit() ;
        return true;
}
           

