var browser = navigator.appName;
var version = navigator.appVersion.substring(0, 1);
var ie = ((browser == "Microsoft Internet Explorer") &&  (version >= 4));
var ns = ((browser == "Netscape") && (version >= 4 && version < 5));

function setHomePage(siteURL) {
  if (ie) {
    document.body.style.behavior = "url(#default#homepage)";
    document.body.setHomePage(siteURL);
  } else alert('Die Seite konnte nicht automatisch als Startseite eingestellt werden, tun Sie dies bitte manuell!');
}

function addToFavorites(siteURL, description) {
  if (ie) window.external.AddFavorite(siteURL, description);
  else if (ns) alert('Drücken Sie Strg+D zum Bookmarken dieser Seite!');
  else alert('Die Seite kann nicht automatisch den Favoriten hinzugefügt werden!');
}

function new_window(theURL,winName,features,myWidth,myHeight,isCenter) {
  if(window.screen)if(isCenter)if(isCenter == 'true') {
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function new_imagepopup(theURL,winName,altName,features,myWidth,myHeight,isCenter) {
  if(window.screen)if(isCenter)if(isCenter == 'true') {
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  imagepopup = window.open('','',features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
  with (imagepopup) {
    document.open();
    document.write('<title>'+winName+'</title>');
    document.write('<meta http-equiv="imagetoolbar" content="no">');
    document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll="no">');
    document.write('<a href="javascript:self.close()">');
    document.write('<img src="'+theURL+'" border="0" alt="'+altName+'" title="'+altName+'">');
    document.write('</a></body>');
    document.close();
  }
}

function newImage(arg) {
  if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;
  }
}

var preloadFlag = false;
function preloadImages() {
  if (document.images) {
    for (var i=0; i<preloadImages.arguments.length; i++) {
      rslt = newImage(preloadImages.arguments[i]);
    }
    preloadFlag = true;
  }
}

function changeImages() {
  if (document.images && (preloadFlag == true)) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
    }
  }
}

var rt = {
	swf_success: function(file, data) {
		var progress = new FileProgress(file, this.customSettings.upload_target);
		var json = eval('('+data+')');
		eval(json.init);
	},
	swf_complete: function(file) {
		if (this.getStats().files_queued > 0) this.startUpload();
		else {
			var progress = new FileProgress(file,  this.customSettings.upload_target);
			progress.setComplete();
			progress.setStatus('');
			progress.toggleCancel(false);
		}
	},
	swf_startupload: function(count, files) {
		if (count > 0) this.startUpload();
	},
	swf_fileerror: function(file, errorCode, message) {
		var imageName = "error.gif";
		var errorName = '';
		if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) errorName = "You have attempted to queue too many files.";
		if (errorName !== '') {
			alert(errorName);
			return;
		}
		switch (errorCode) {
		case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
			imageName = 'zerobyte.gif';
			break;
		case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
			imageName = 'toobig.gif';
			break;
		case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
		case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
		default:
			alert(message);
			break;
		}
		//addImage("images/" + imageName);
	},
	swf_progress: function(file, bytesLoaded) {
		var percent = Math.ceil((bytesLoaded / file.size) * 100);
		var progress = new FileProgress(file,  this.customSettings.upload_target);
		progress.setProgress(percent);
		if (percent === 100) {
			progress.setStatus("Datei wird für die Ausgabe vorbereitet...");
			progress.toggleCancel(false, this);
		} else {
			progress.setStatus("Datei wird an RegioTrends übermittelt...");
			progress.toggleCancel(true, this);
			$('#submit_files')[0].disabled = true;
			$('#submit_files').val('Bitte warten, Dateien werden an RegioTrends übermittelt.');
		}
	},
	swf_error: function(file, errorCode, message) {
		var imageName = 'error.gif';
		var progress;
		switch (errorCode) {
		case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
			progress = new FileProgress(file, this.customSettings.upload_target);
			progress.setCancelled();
			progress.setStatus('Cancelled');
			progress.toggleCancel(false);
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
			progress = new FileProgress(file,  this.customSettings.upload_target);
			progress.setCancelled();
			progress.setStatus("Stopped");
			progress.toggleCancel(true);
		case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
			imageName = 'uploadlimit.gif';
			break;
		default:
			alert(message);
			break;
		}
		//addImage("images/" + imageName);
	}
};

/* ******************************************
 *	FileProgress Object
 *	Control object for displaying file info
 * ****************************************** */

function FileProgress(file, targetID) {
	this.fileProgressID = "divFileProgress";

	this.fileProgressWrapper = document.getElementById(this.fileProgressID);
	if (!this.fileProgressWrapper) {
		this.fileProgressWrapper = document.createElement("div");
		this.fileProgressWrapper.className = "progressWrapper";
		this.fileProgressWrapper.id = this.fileProgressID;

		this.fileProgressElement = document.createElement("div");
		this.fileProgressElement.className = "progressContainer";

		var progressCancel = document.createElement("a");
		progressCancel.className = "progressCancel";
		progressCancel.href = "#";
		progressCancel.style.visibility = "hidden";
		progressCancel.appendChild(document.createTextNode(" "));

		var progressText = document.createElement("div");
		progressText.className = "progressName";
		progressText.appendChild(document.createTextNode(file.name));

		var progressBar = document.createElement("div");
		progressBar.className = "progressBarInProgress";

		var progressStatus = document.createElement("div");
		progressStatus.className = "progressBarStatus";
		progressStatus.innerHTML = "&nbsp;";

		this.fileProgressElement.appendChild(progressCancel);
		this.fileProgressElement.appendChild(progressText);
		this.fileProgressElement.appendChild(progressStatus);
		this.fileProgressElement.appendChild(progressBar);

		this.fileProgressWrapper.appendChild(this.fileProgressElement);

		document.getElementById(targetID).appendChild(this.fileProgressWrapper);
		//fadeIn(this.fileProgressWrapper, 0);

	} else {
		this.fileProgressElement = this.fileProgressWrapper.firstChild;
		this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
	}

	this.height = this.fileProgressWrapper.offsetHeight;

}
FileProgress.prototype.setProgress = function (percentage) {
	this.fileProgressElement.className = "progressContainer green";
	this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
	this.fileProgressElement.childNodes[3].style.width = percentage + "%";
};
FileProgress.prototype.setComplete = function () {
	this.fileProgressElement.className = "progressContainer blue";
	this.fileProgressElement.childNodes[3].className = "progressBarComplete";
	this.fileProgressElement.childNodes[3].style.width = "";
	$('#submit_files')[0].disabled = false;
	$('#submit_files').val('Alles fertig? Hier klicken > gesendet!');
};
FileProgress.prototype.setError = function () {
	this.fileProgressElement.className = "progressContainer red";
	this.fileProgressElement.childNodes[3].className = "progressBarError";
	this.fileProgressElement.childNodes[3].style.width = "";
	$('#submit_files')[0].disabled = false;
	$('#submit_files').val('Alles fertig? Hier klicken > gesendet!');
};
FileProgress.prototype.setCancelled = function () {
	this.fileProgressElement.className = "progressContainer";
	this.fileProgressElement.childNodes[3].className = "progressBarError";
	this.fileProgressElement.childNodes[3].style.width = "";
	$('#submit_files')[0].disabled = false;
	$('#submit_files').val('Alles fertig? Hier klicken > gesendet!');
};
FileProgress.prototype.setStatus = function (status) {
	this.fileProgressElement.childNodes[2].innerHTML = status;
};

FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {
	this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
	if (swfuploadInstance) {
		var fileID = this.fileProgressID;
		this.fileProgressElement.childNodes[0].onclick = function () {
			swfuploadInstance.cancelUpload(fileID);
			return false;
		};
	}
};
//http://www.featureblend.com/license.txt
var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE='1.0.4';