//var exts = "jpg|gif|png|bmp|mp3|mpg|mpeg|avi|rar|zip|7z|gz|txt";
var exts = "jpg|jpeg";
//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('http://www.textilio.com/cgi-bin/upload_status.cgi?upload_id='+UID,'win1','width=320,height=240,resizable=1');
   win1.window.focus();
 }
}

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('Bitte zuerst eine Datei ausw\u00e4hlen!');return false;};
    generateSID();
    openStatusWindow();
}

function checkExt(value)
{
    if(value=="")return true;
    var re = new RegExp("^.+\.("+exts+")$","i");
    if(!re.test(value))
    {
		document.getElementById("check-own-image").style.visibility = "hidden";
		document.getElementById("uploadbutton").style.visibility = "hidden";
        alert("Die Datei \"" + value +"\" kann nicht hochgeladen werden.  \nDu kannst nur Dateien mit folgenden Dateiendungen hochladen: "+exts.replace(/\|/g,',')+" \n\n");

        return false;
    }
	else {
	//document.getElementById("check-own-image").style.visibility = "visible";
	document.getElementById("uploadbutton").style.visibility = "visible";
    return true;
	}
}

