		var currentMousePosition = new Array();
		currentMousePosition["x"] = 0;
		currentMousePosition["y"] = 0;
		
		var currentImagePosition = new Array;
		currentImagePosition["top"] = 0;
		currentImagePosition["left"] = 0;
		
		var imagePosition = new Array();
		imagePosition["top"] = 0;
		imagePosition["left"] = 0;
		
		var currentImageSize = new Array();
		currentImageSize["width"] = 200;
		currentImageSize["height"] = 240;
		
		var imageWidth = 200;
		var imageHeight = 240;

		var websiteCounter = 0;
		var IMAccountCounter = 0;
		
		var uploadComplete = false;
		var imageId;
		var uploadedImage;
		
		var addCardMessageWindowEventHandler = false;
		var addZiemoCardWindow = false;
		
		function makeImageEditable() {
			var width = imageWidth;
			var height = imageHeight;
			
			document.getElementById("userImageCurtain").onmousedown = function(evt) { onDragStart(evt); };
			document.getElementById("userImageCurtain").onmouseup = function(evt) { onDragStop(evt); };
			document.getElementById("userImageCurtain").onmouseout = function(evt) { onDragStop(evt); };
			
			var imageTopBarrier = document.createElement("DIV");
			imageTopBarrier.id = 'imageTopBarrier';
			imageTopBarrier.className = 'userImageBarrier userImageTopBarrier';
			imageTopBarrier.style.top = '0px';
			imageTopBarrier.style.left = '20px';
			imageTopBarrier.style.width = width + 'px';
			imageTopBarrier.style.height = '20px';

			var imageBottomBarrier = document.createElement("DIV");
			imageBottomBarrier.id = 'imageBottomBarrier';
			imageBottomBarrier.className = 'userImageBarrier userImageBottomBarrier';
			imageBottomBarrier.style.top = Math.round(height + 20) + 'px';
			imageBottomBarrier.style.left = '20px';
			imageBottomBarrier.style.width = width + 'px';
			imageBottomBarrier.style.height = '20px';			

			var imageLeftBarrier = document.createElement("DIV");
			imageLeftBarrier.id = 'imageLeftBarrier';
			imageLeftBarrier.className = 'userImageBarrier userImageLeftBarrier';
			imageLeftBarrier.style.top = '20px';
			imageLeftBarrier.style.left = '0px';
			imageLeftBarrier.style.width = '20px';
			imageLeftBarrier.style.height = height + 'px';	

			var imageRightBarrier = document.createElement("DIV");
			imageRightBarrier.id = 'imageRightBarrier';
			imageRightBarrier.className = 'userImageBarrier userImageRightBarrier';
			imageRightBarrier.style.top = '20px';
			imageRightBarrier.style.left = Math.round(width + 20) + 'px';
			imageRightBarrier.style.width = '20px';
			imageRightBarrier.style.height = height + 'px';	

			var imageTopLeftBarrier = document.createElement("DIV");
			imageTopLeftBarrier.id = 'imageTopLeftBarrier';
			imageTopLeftBarrier.className = 'userImageBarrier';
			imageTopLeftBarrier.style.top = '0px';
			imageTopLeftBarrier.style.left = '0px';
			imageTopLeftBarrier.style.width = '20px';
			imageTopLeftBarrier.style.height = '20px';	

			var imageTopRightBarrier = document.createElement("DIV");
			imageTopRightBarrier.id = 'imageTopRightBarrier';
			imageTopRightBarrier.className = 'userImageBarrier';
			imageTopRightBarrier.style.top = '0px';
			imageTopRightBarrier.style.left = Math.round(width + 20) + 'px';
			imageTopRightBarrier.style.width = '20px';
			imageTopRightBarrier.style.height = '20px';	

			var imageBottomLeftBarrier = document.createElement("DIV");
			imageBottomLeftBarrier.id = 'imageBottomLeftBarrier';
			imageBottomLeftBarrier.className = 'userImageBarrier';
			imageBottomLeftBarrier.style.top = Math.round(height + 20) + 'px';
			imageBottomLeftBarrier.style.left = '0px';
			imageBottomLeftBarrier.style.width = '20px';
			imageBottomLeftBarrier.style.height = '20px';

			var imageBottomRightBarrier = document.createElement("DIV");
			imageBottomRightBarrier.id = 'imageBottomRightBarrier';
			imageBottomRightBarrier.className = 'userImageBarrier';
			imageBottomRightBarrier.style.top = Math.round(height + 20) + 'px';
			imageBottomRightBarrier.style.left = Math.round(width + 20) + 'px';
			imageBottomRightBarrier.style.width = '20px';
			imageBottomRightBarrier.style.height = '20px';	

			document.getElementById("imageEditContainer").appendChild(imageTopBarrier);
			document.getElementById("imageEditContainer").appendChild(imageBottomBarrier);
			document.getElementById("imageEditContainer").appendChild(imageLeftBarrier);
			document.getElementById("imageEditContainer").appendChild(imageRightBarrier);
			document.getElementById("imageEditContainer").appendChild(imageTopLeftBarrier);
			document.getElementById("imageEditContainer").appendChild(imageTopRightBarrier);
			document.getElementById("imageEditContainer").appendChild(imageBottomLeftBarrier);
			document.getElementById("imageEditContainer").appendChild(imageBottomRightBarrier);

			var userImageControls = document.createElement("DIV");
			userImageControls.className = 'userImageControls';
			
			var zoomInButton = document.createElement("A");
			zoomInButton.href = 'JavaScript:userImageZoomIn()';
			zoomInButton.innerHTML = '+';
			
			var zoomOutButton = document.createElement("A");
			zoomOutButton.href = 'JavaScript:userImageZoomOut()';
			zoomOutButton.innerHTML = '-';
			
			userImageControls.appendChild(zoomInButton);
			userImageControls.appendChild(document.createElement("BR"));
			userImageControls.appendChild(zoomOutButton);
			
			document.getElementById("imageEditContainer").appendChild(userImageControls);			
		}
		
		function initEditImageContainer(imagePath, width, height) {
			var userImageContainer = document.createElement("DIV");
			userImageContainer.id = 'userImageContainer';
			userImageContainer.className = 'userImageScrollContainer';
			userImageContainer.style.height = Math.round(height + 40) + 'px';	
			userImageContainer.style.width = Math.round(width + 40) + 'px';
			
			var userImageInnerContainer = document.createElement("DIV");
			userImageInnerContainer.id = 'userImageInnerContainer';
			userImageInnerContainer.className = 'userImageInnerContainer';
			userImageInnerContainer.style.height = height + 'px';
			userImageInnerContainer.style.width = width + 'px';
			
			var userImageFile = document.createElement("IMG");
			userImageFile.id = 'userImageFile';
			
			if(imagePath) {
				userImageFile.src = imagePath;
			} else {
				userImageFile.src = '/images/noImages.jpg';
			}
			userImageFile.className = 'userImageFile';
			
			var userImageCurtain = document.createElement("DIV");
			userImageCurtain.id = 'userImageCurtain';
			userImageCurtain.className = 'userImageCurtain';
			userImageCurtain.style.height = height + 'px';
			userImageCurtain.style.width = width + 'px';
			userImageCurtain.onmousedown = null;
			userImageCurtain.onmouseup = null;
			userImageCurtain.onmouseout = null;
			
			userImageInnerContainer.appendChild(userImageFile);
			userImageInnerContainer.appendChild(userImageCurtain);
			
			userImageContainer.appendChild(userImageInnerContainer);

			document.getElementById("imageEditContainer").appendChild(userImageContainer);
								
			// Somehow prevents from actually dragging the fullsized Image (TODO)
			userImageZoomIn();
			userImageZoomOut();
		}
		
		function newImageUpload() {
			jsonGetData('json/imageUploader/createImageUpload.php?userId=Stefan', 'newImageUploadInt');				
		}
		
		function newImageUploadInt(Object) {
			if(Object["status"]=='ok') {
				if(Object["imageId"]) {
					document.getElementById("userImageUploadForm").innerHTML = '';
					imageId = Object["imageId"];
					var imageUploadForm = document.createElement("IFRAME");
					imageUploadForm.src = '/utilities/imageUploader/imageUploadForm.php?imageId=' + Object["imageId"] + '&type=userSettings';
							
					document.getElementById("userImageUploadForm").appendChild(imageUploadForm);
					
					uploadCompleted = false;
					
					setTimeout('checkImageUploadStatus()', 4000);
				}
			}		
		}

		function checkImageUploadStatus() {
			if(!uploadCompleted) {
				jsonGetData('json/imageUploader/checkUploadStatus.php?imageId=' + imageId, 'checkImageUploadStatusInt');
			}
		}

		function checkImageUploadStatusInt(Object) {
			if(Object["status"] == 'completed') {
				uploadCompleted = true;
				uploadedImage = new Image();
				uploadedImage.src = '/uploads/images/' + imageId + '.jpg';
				uploadedImage.className = 'userImageFile';			

				document.getElementById("imageId").value = imageId;
				
				document.getElementById("imageEditContainer").innerHTML = '';
				document.getElementById("imageEditContainer").appendChild(uploadedImage);				
				document.getElementById("userImageUploadForm").innerHTML = '';	
			} else if(Object["status"] == 'active') {
				setTimeout('checkImageUploadStatus()', 4000);	
				uploadCompleted = false;
			} else if(Object["status"] == 'canceled') {	
				imageId = false;
				uploadCompleted = false;
				document.getElementById("userImageUploadForm").innerHTML = '';
				document.getElementById("imageId").value = '';				
			} else {
				imageId = false;
				uploadCompleted = true;
			}
		}
		
		function checkImageUploadStatusIntInt() {
			if(uploadedImage.complete) {
				currentImageSize["width"] = uploadedImage.width;
				currentImageSize["height"] = uploadedImage.height;

				document.getElementById("imageEditContainer").innerHTML = '';		
			} else {
				setTimeout('checkImageUploadStatusIntInt()', 1000);				
			}
		}
		
		function getMousePosition(evt) {
			// Returns the Mouse-Position of the given Event 
			var mousePosition = new Array;
			
			if(!evt) {
				// If no Event is given => set Event
				evt = window.event
			}
		
			// Retrieve Mouse-Position
			if(evt.pageX || evt.pageY) {
				// Mozilla / Webkit-Browser
				mousePosition["x"] = evt.pageX;
				mousePosition["y"] = evt.pageY; 
			} else if(evt.clientX || evt.clientY) {
				// Microsoft-Browser
				mousePosition["x"] = evt.clientX + document.documentElement.scrollLeft;
				mousePosition["y"] = evt.clientY + document.documentElement.scrollTop;
			} 
		
			// Return MousePosition
			return(mousePosition);
		} 	
	
		function onDragStart(evt) {
			currentMousePosition = getMousePosition(evt);
			currentImagePosition["top"] = imagePosition["top"];
			currentImagePosition["left"] = imagePosition["left"];
			
		  	document.onmousemove = mousemoveEventHandler;
		  	document.onmouseup = onDragStop;			
		}
		
		function onDragStop(evt) {
			document.onmousemove = null;
			document.onmouseup = null;
		}
		
		function mousemoveEventHandler(evt) {
			var mousePosition = getMousePosition(evt);
			
			mousePositionDiff = new Array();			
			mousePositionDiff["x"] = mousePosition["x"] - currentMousePosition["x"];
			mousePositionDiff["y"] = mousePosition["y"] - currentMousePosition["y"];
		
			setImagePosition(currentImagePosition["left"] + mousePositionDiff["x"], currentImagePosition["top"] + mousePositionDiff["y"]);
		}
			
		function userImageZoomIn() {

		}
		
		function userImageZoomOut() {

		}

		function addIMAccount(type, account) {
			var icqSelected = '';
			var msnSelected = '';
			var gtalkSelected = '';
			var skypeSelected = '';
			var chooseSelected = '';
			var jabberSelected = '';
			
			if(type=='1') {
				icqSelected = 'SELECTED';
			} else if(type=='2') {
				msnSelected = 'SELECTED';
			} else if(type=='3') {
				gtalkSelected = 'SELECTED';
			} else if(type=='4') {
				skypeSelected = 'SELECTED';
			} else if(type=='5') {
				jabberSelected = 'SELECTED';
			} else {
				chooseSelected = 'SELECTED';
			}

			var imContainer = document.createElement("DIV");
			imContainer.className = 'inputArrayEntry';
			imContainer.id = 'imContainer' + IMAccountCounter;
			
			var inputSelectBox = document.createElement("SPAN");
			inputSelectBox.innerHTML = '<select id="IMType' + IMAccountCounter + '" name="IMType' + IMAccountCounter + '" class="imTypeSelect"><option value="0" ' + chooseSelected + '>Typ:</option><option value="1" ' + icqSelected + '>ICQ</option><option value="2" ' + msnSelected + '>MSN</option><option value="3" ' + gtalkSelected + '>GTalk</option><option value="4" ' + skypeSelected + '>Skype</option><option value="5" ' + jabberSelected + '>Jabber</option>';
		
			var inputTextfield = document.createElement("INPUT");
			inputTextfield.type = 'text';
			inputTextfield.id = 'IMAccount' + IMAccountCounter;
			inputTextfield.name = 'IMAccount' + IMAccountCounter;
			inputTextfield.className = 'textField imAccountTextField';
			if(account) {
				inputTextfield.value = account;
			} else {
				inputTextfield.value = 'Benutzername...';
				eval("inputTextfield.onfocus = function() { document.getElementById('IMAccount" + IMAccountCounter + "').value = ''; };");
			}
	
			var inputButton = document.createElement("INPUT");
			inputButton.type = 'button';
			inputButton.className = 'inputDeleteButton';
			inputButton.value = '-';
			eval("inputButton.onclick = function() { removeIMAccount(" + IMAccountCounter + "); };");

			imContainer.appendChild(inputSelectBox);
			imContainer.appendChild(inputTextfield);
			imContainer.appendChild(inputButton);
			
			document.getElementById("userIMAccounts").insertBefore(imContainer, document.getElementById("addIMAccountLink"));			
			
			document.getElementById("imAccountCounter").value = IMAccountCounter;
					
			IMAccountCounter++;
		}
		
		function removeIMAccount(id) {
			if(IMAccountCounter >= 0) {
				var z2 = 0;
				var IMAccounts = new Array;
				for(z1=0; z1 < IMAccountCounter; z1++) {
					if(z1!=id) {
						IMAccounts[z2] = new Array;
						IMAccounts[z2]['type'] = document.getElementById("IMType" + z1).value;
						IMAccounts[z2]['account'] = document.getElementById("IMAccount" + z1).value;
						z2++;
					}
				}
								
				document.getElementById("userIMAccounts").innerHTML = '<a class="addIMAccountLink" id="addIMAccountLink" href="JavaScript:addIMAccount(false, false);">Einen Account hinzuf&uuml;gen &raquo;</a>';

				document.getElementById("imAccountCounter").value = false;
				IMAccountCounter = 0;
				
				for(z1=0; z1 < IMAccounts.length; z1++) {
					addIMAccount(IMAccounts[z1]['type'], IMAccounts[z1]['account']);
				}
			}
		}
			
		function addWebsite(url) {
			var websiteContainer = document.createElement("DIV");
			websiteContainer.className = 'inputArrayEntry';
			websiteContainer.id = 'websiteContainer' + websiteCounter;
		
			var inputTextfield = document.createElement("INPUT");
			inputTextfield.type = 'text';
			inputTextfield.id = 'website' + websiteCounter;
			inputTextfield.name = 'website' + websiteCounter;
			inputTextfield.className = 'textField websiteTextField';
			if(url) {
				inputTextfield.value = url;
			} else {
				inputTextfield.value = 'http://';			
			}
			
			var inputButton = document.createElement("INPUT");
			inputButton.type = 'button';
			inputButton.className = 'inputDeleteButton';
			inputButton.value = '-';
			eval("inputButton.onclick = function() { removeWebsite(" + websiteCounter + "); };");
			
			websiteContainer.appendChild(inputTextfield);
			websiteContainer.appendChild(inputButton);
			
			document.getElementById("userWebsites").insertBefore(websiteContainer, document.getElementById("addWebsiteLink"));			
			
			document.getElementById("websiteCounter").value = websiteCounter;
			websiteCounter++;
		}
		
		function removeWebsite(id) {
			if(websiteCounter >= 0) {
				var z2 = 0;
				var websites = new Array;
				for(z1=0; z1 < websiteCounter; z1++) {
					if(z1!=id) {
						websites[z2] = document.getElementById("website" + z1).value;
						z2++;
					}
				}
								
				document.getElementById("userWebsites").innerHTML = '<a class="addWebsiteLink" id="addWebsiteLink" href="JavaScript:addWebsite(false);">Eine Webseite hinzuf&uuml;gen &raquo;</a>';

				document.getElementById("websiteCounter").value = 'false';
				websiteCounter = 0;
				
				for(z1=0; z1 < websites.length; z1++) {
					addWebsite(websites[z1]);
				}
			}
		}
		
		function hideMessageBox() {
			document.getElementById("messageBox").style.display = 'none';
		}
		
		function removeCard() {
			document.getElementById("action").value = 'remove';
			document.getElementById("ziemoCardForm").submit();
		}
		
		function selectTown() {
			document.getElementById("noTownSelectedContainer").style.display = 'none';
			document.getElementById("townSelectedContainer").style.display = 'none';
			document.getElementById("addTownContainer").style.display = 'none';
			document.getElementById("townSelectorContainer").style.display = 'block';					
		}

		function stateSelected() {
			selectedStateId = document.getElementById("stateSelectorInputField").value;
			document.getElementById("stateSelectorInputField").className = 'inputSelect opacity05';
			document.getElementById("leadingCharacter").className = 'inputSelect';
		}

		function characterSelected() {
			indexCharacter = document.getElementById("leadingCharacter").value;
			selectedStateId = document.getElementById("stateSelectorInputField").value;			
			if(indexCharacter && selectedStateId) {
				var output = new Object();
				output.state = selectedStateId;
				output.character = indexCharacter;
				
				outputString = JSONstring.make(output);
			}
			
			jsonPostData('json/geoData/getCitiesByLeadingCharacter.php', escape(outputString), 'displayCities');	
		}
		
		function displayCities(Object) {
			if(Object) {
				if(Object["status"]) {
					if(Object["status"]=='ok') {
						if(Object["cities"]) {
							cityHtmlString = '<select name="citySelector" id="citySelector" onChange="citySelected()" class="inputSelect citySelectorInputField"><option value="0">Bitte ausw&auml;hlen...</option>';
							for(cityCnt=0; cityCnt < Object["cities"].length; cityCnt++) {
								cityHtmlString = cityHtmlString + '<option value="' + Object["cities"][cityCnt]["Name"] + '">' + Object["cities"][cityCnt]["Name"] + '</option>';
							}
							cityHtmlString = cityHtmlString + '</select>';
							
							document.getElementById("citySelectorBox").innerHTML = cityHtmlString;
						}
					}
				}
			}
			
			document.getElementById("stateSelectorInputField").className = 'inputSelect opacity05';
			document.getElementById("leadingCharacter").className = 'inputSelect opacity05';
			document.getElementById("citySelector").className = 'inputSelect';
		}					

		function citySelected() {
			cityName = document.getElementById("citySelector").value;

			document.getElementById("city").value = cityName;
			
			if(GBrowserIsCompatible()) {			
				geocoder = new GClientGeocoder();	
				eval("geocoder.getLatLng('" + cityName + "', function(point) { foundCityLocation(point); });");
			}	
		}
		
		function foundCityLocation(location) {
			if(location) {
				var cityCoordString = location.toUrlValue(13);
		
				var coords = cityCoordString.split(",");		
		
				var latitude = coords[0];
				var longitude = coords[1];

				document.getElementById("lat").value = latitude;
				document.getElementById("long").value = longitude;

				cityName = cityName.replace(/\\/g,'\\\\');
				cityName = cityName.replace(/\'/g,'\\\'');
				cityName = cityName.replace(/\"/g,'\\"');
				cityName = cityName.replace(/\0/g,'\\0');
				
				document.getElementById("townSelectedContainer").innerHTML = cityName + ' (<a href="JavaScript:selectTown();"><b>Ort &auml;ndern</b></a>)';
				
				document.getElementById("noTownSelectedContainer").style.display = 'none';
				document.getElementById("townSelectorContainer").style.display = 'none';
				document.getElementById("addTownContainer").style.display = 'none';						
				document.getElementById("townSelectedContainer").style.display = 'block';
			}	
		}

		function addCity() {
			document.getElementById("addTownContainer").style.display = 'block';
			document.getElementById("noTownSelectedContainer").style.display = 'none';
			document.getElementById("townSelectorContainer").style.display = 'none';						
			document.getElementById("townSelectedContainer").style.display = 'none';			
		}

		function saveNewCity() {
			selectedStateId = document.getElementById("stateSelectorInputFieldSnd").value;
			cityName = document.getElementById("addCityTextField").value;
			
			if(selectedStateId!=0 && cityName.length>=2 && cityName!='2. Name der Stadt...') {
				if(GBrowserIsCompatible()) {			
					geocoder = new GClientGeocoder();	
					eval("geocoder.getLatLng('" + escape(cityName) + "', function(point) { saveNewCityInt(point); });");
				}
			} else {
				messageWindow = new MessageWindowClass();
				messageWindow.className = 'photoUploadMessageWindow';
				messageWindow.title = 'Ein Fehler ist aufgetreten...';
				messageWindow.message = 'Bitte w&auml;hle ein Bundesland aus und gebe einen Stadtnamen ein um eine neue Stadt anzulegen.';
				messageWindow.name = 'messageWindow';
				messageWindow.displayCurtain = false;
				messageWindow.display();	
			}
		}		

		function saveNewCityInt(location) {
			var output = new Object();
			output.state = selectedStateId;
			output.cityName = cityName;

			if(location) {
				var cityCoordString = location.toUrlValue(13);			
				var coords = cityCoordString.split(",");
				output.latitude = coords[0];
				output.longitude = coords[1];
			} else {
				output.latitude = false;
				output.longitude = false;
			}
			
			outputString = JSONstring.make(output);
		
			jsonPostData('json/geoData/saveCity.php', escape(outputString), 'saveNewCityIntInt');	
		}

		function saveNewCityIntInt(Object) {
			if(Object) {
				if(Object["status"] && Object["cityName"]) {
					if(Object["status"]=='ok') {
						cityName = Object["cityName"];

						document.getElementById("city").value = cityName;
						
						if(GBrowserIsCompatible()) {			
							geocoder = new GClientGeocoder();	
							eval("geocoder.getLatLng('" + cityName + "', function(point) { foundCityLocation(point); });");
						}	
					}
				}
			}
		}		
