//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//	FUNCTION	uploadUserImage()
//	DESC		Opens window with existing content inside (Image upload form and an Iframe)
//	PARAMS		imageNum	::	The Specific imageNumber to upload
//	NOTES		The content set inside window is a form and Iframe w/ the form targetting the Iframe...
//	AUTHOR		Sune Lundby [SL]
//	DATE		July 12th 2006
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function uploadUserImage(imageNum) {

	uploadFORM = $('uploadFORM').innerHTML;
	$('imageNum').value = imageNum;

	contentWin = new Window('imgUploadWin', {
								resizable: true,
								hideEffect:Element.hide,
								showEffect:Element.show,
								className: "alphacube",
								minWidth: 220,
								minHeight: 50,
								maximizable: false,
								minimizable: false })
	
	contentWin.setContent('imageUpload', true, false);
	contentWin.toFront();
	contentWin.showCenter();
	contentWin.setDestroyOnClose();

	//
	// SET UP WINDOWS OBSERVER WHEN DESTROYING THE WINDOW...
	myObserver = {

		onDestroy: function(eventName, win) {

			if (win == contentWin) {

				contentWin = null;
				Windows.removeObserver(this);

			} // END IF...

		} // END FUNCTION onDestroy

	} // END OBSERVER

	Windows.addObserver(myObserver);

} // END FUNCTION uploadUserImage()
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//	FUNCTION	uploadUserImage()
//	DESC		Submits image upload form (inside Iframe) and sets a loading anim while image is uploading
//	NOTES		Function is called in a window opened by uploadIMG()
//	AUTHOR		Sune Lundby [SL]
//	DATE		July 12th 2006
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function uploadUserImage(){

	imageNum = $('imageNum').value; // Read hidden value...
	
	// add image progress
	var imgContainer = $('imgContainer' + imageNum);
	var new_img = document.createElement('img');

	new_img.src = myBasePath + '_images/gfx/loading.gif';

	imgContainer.appendChild(new_img);

	$('imageUpload').submit();

} // END FUNCTION uploadUserImage()
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//	FUNCTION	deleteUserImage()
//	DESC		Deletes an Image and sets a new BTN...
//	PARAMS		imageNum	::	The Specific imageNumber to delete
//				id			::	Specific item connected to image (detarmined by content)
//				content		::	Identifier so we can delete from DB
//				doAction	::	If add then we don't have an entry in DB
//								=> used in PHP to delete the image...
//	NOTES		The physical image is deleted by PHP from an Ajax.Request
//	AUTHOR		Sune Lundby [SL]
//	DATE		July 12th 2006
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function deleteUserImage(imageNum, id, content, doAction) {

	//
	// FIND AND REMOVE THE IMAGE...
	var imgContainer =  $('imgContainer' + imageNum);
	arrImages = imgContainer.getElementsByTagName('img');
	imgContainer.removeChild(arrImages[0]); 

	//
	// SET ADD BTN...
	$('imgAction' + imageNum).innerHTML = '<a href="#" title="Tilføj" onclick="uploadIMG(' + imageNum + ')"><img src="_images/icon/add.gif" alt="Slet" title="Slet" /></a>';

	//
	// CALL PHP TO DELETE THE PHYSICAL IMAGE...
	var randNum = Math.random()*370;
	var opt		= {

			method: 'post',
			postBody: 'imageNum=' + imageNum + '&id=' + id + '&content=' + content + '&doAction=' + doAction,
	
			onSuccess: function(t) {
				//alert(t.responseText);
			},
	
			on404: function(t) {
				//alert('Error 404: location "' + t.statusText + '" was not found.');
			},
	
			onFailure: function(t) {
				//alert('Error ' + t.status + ' -- ' + t.statusText);
			}

	}

	new Ajax.Request(myBasePath + '/_ajax/_scripts/delete_image.php?rand=' + randNum, opt);

} // END FUNCTION deleteUserImage()
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
