	
	var newwin;			
	var loop = 0;
	var maxloops = 1000;
	var warte;
	
	/*
	function uploadwin( fname, fwidth, fheight, fid ) {
		newwin = window.open("cropload.html", "TempFenster"); 
		var doc = newwin.document;
		doc.write('<form name="uploader" action="http://localhost/MyImageCreator/UploadForm.aspx" method="post">');
		doc.write('<input type="hidden" name="destfile" value="' + fname + '">');
		doc.write('<input type="hidden" name="txt_rahmen_breite" value="' + fwidth + '">');
		doc.write('<input type="hidden" name="txt_rahmen_hoehe" value="' + fheight + '">');
		doc.write('<input type="hidden" name="txt_serverPath" value="http://localhost/pbweb/requestinfo.aspx?ichkomme=zurueck">');
		doc.write('<input type="submit" name="OK" value="OK">');
		doc.write('</form>');
		newwin.document.uploader.submit();
	}
	*/

	function uploadwin( kdnr, fname, fwidth, fheight, fid ) {
		newwin = window.open("/pbweb/secured/meinewebsite/cropload.html", "TempFenster"); 
		var doc = newwin.document;
		var host = window.location.hostname;
		doc.write('<form name="uploader" action="http://' + host + '/KMF_Cropper/UploadForm.aspx" method="post">');
		doc.write('<input type="hidden" name="destfile" value="' + fname + '">');
		doc.write('<input type="hidden" name="width" value="' + fwidth + '">');
		doc.write('<input type="hidden" name="height" value="' + fheight + '">');
		doc.write('<input type="hidden" name="pathToServer" value="http://' + host + '/pbweb/requestinfo.aspx?kdnr=' + kdnr + '&destfile=' + fname + '&guid=' + fid + '">');
		doc.write('<input type="submit" name="OK" value="OK">');
		doc.write('</form>');
		newwin.document.uploader.submit();
	}

	function upload( kdnr, fname, fwidth, fheight, fid ) {
	
//		alert("In upload");
	
		uploadwin( kdnr, fname, fwidth, fheight, fid );
		warte = window.setInterval("CheckWindow('" + fname + "', '" + fid + "')", 1000);
	}
	
	function CheckWindow(fname, fid) {
		var boolFinished = false;
		var host = window.location.hostname;
		var targetfile = "http://" + host + "/KMF_Cropper/cropper.aspx";
		if( typeof newwin == 'undefined' || newwin.closed ) {
			window.clearInterval(warte);
			// alert("Fenster ist zu");
			location.href="?addimg=" + fname + "&addid=" + fid + "#" + fid;
		} else {
			if ( newwin.document.URL.substr(0, targetfile.length )==targetfile) {
				boolFinished = true;
			}
		}
		if( loop >= maxloops || boolFinished ) {
			window.clearInterval(warte);
			if (!boolFinished ) {
				alert( maxloops + " Sekunden gewartet");
			}
			location.href="?addimg=" + fname + "&addid=" + fid + "#" + fid;
			newwin.close();
		}
		loop = loop + 1;
	}
	
