// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth()
{
	return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pageHeight()
{
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function posLeft()
{
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function posTop()
{
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}
	
function posRight()
{
	return posLeft() + pageWidth();
}

function posBottom()
{
	return posTop() + pageHeight();
}
                    
var MFGajaxPath = "";
var MFGgalleryId = -1;
var MFGeditedImage = -1;

function mfg_SetAjaxPath(ap)
{
	MFGajaxPath = ap;
}

//////////////////////////////////////////////////////////////////////////////////////
// Send AJAX response to server, with response to be handled by specified callback function
//////////////////////////////////////////////////////////////////////////////////////

function mfg_SendAjaxCallback(url,callbackfunction)
{
	// Add a time code onto the end of the request URL so that it will always be
	// different, even if we're asking for the same thing as something else
	// that we may have done in the recent past, in order to prevent browser caching.
	d = new Date()
	t = d.getTime();
	url = url + "&nc=" + t;
	
	var AjaxRequest = null;
	// Get a request object	
	try
	{
		AjaxRequest = new XMLHttpRequest();
	}
	catch (trymicrosoft)
	{
		try
		{
			AjaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft)
		{
			try
			{
				AjaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed)
			{
				AjaxRequest = null;
				alert("Your web browser is incompatible with the editing functions on this page.");
			}
		}
	}

	// Send the request
	AjaxRequest.open("GET", url, true);
	
	// Use anonymous inner function as callback
	AjaxRequest.onreadystatechange = function() 
	{
		if (AjaxRequest.readyState == 4)
		{	
			// Check for zero because of stupid goddamn fucking Firefox
			if ( (AjaxRequest.status == 0) || (AjaxRequest.status == 200) )
			{
				if( callbackfunction )
					callbackfunction(AjaxRequest.responseText);
			}
			else if (AjaxRequest.status == 404 )
			{
				// file not found?
				msg = "Error!  Status = " + AjaxRequest.status + "\n";
			}
			else
			{
				//alert("Error! Request status is " + AjaxRequest.status);
			}
		}
	}
	
	AjaxRequest.send(" ");	// Firefox doesn't like NULL so send a space	
}

function mfg_GetGalleryList()
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGallery_ListGalleries";
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText)
											{ 
											 	document.body.style.cursor = "default";
												document.getElementById("mfgallerylist").innerHTML = theText;
											} );
}

function mfg_SelectGallery()
{
	var theMenu = document.getElementById('mfgGalleryMenu');
	
	//alert( "Item Selected = " + theMenu.options[theMenu.selectedIndex].value );
	
	if( theMenu.options[theMenu.selectedIndex].value == -1 )
		return;
	
	mfg_DisplayGallery(theMenu.options[theMenu.selectedIndex].value);
}

function mfg_EditGallery(id)
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryGetGalleryInfo";
	requestUrl += "&id=" + id;
	document.body.style.cursor = "wait";
	
	//alert(requestUrl);
	
	mfg_SendAjaxCallback( requestUrl, function(theText) 
										{ 
											 //alert(theText);
											 theGallery = eval("(" + theText + ")");
											 document.getElementById("galleryid").value = theGallery.id;
											 document.getElementById("gallerynumber").innerHTML = theGallery.id;
											 document.getElementById("galleryname").value = theGallery.name;
											 document.getElementById("imageurl").value = theGallery.imageurl;
											 document.getElementById("showname").checked = (theGallery.showname>0) ? true : false;
											 document.getElementById("autoslideshow").checked = (theGallery.autoslideshow>0) ? true : false;
											 document.getElementById("membersonly").checked = (theGallery.membersonly>0) ? true : false;
											 document.getElementById("published").checked = (theGallery.published>0) ? true : false;
											 document.getElementById("showthumbdesc").checked = (theGallery.showthumbdesc>0) ? true : false;
											 document.getElementById("autoresize").checked = (theGallery.autoresize>0) ? true : false;
											 document.getElementById("maxwidth").value = theGallery.maxwidth;
											 document.getElementById("maxheight").value = theGallery.maxheight;	
											 
											 document.getElementById("embedcode").value = "[MFGallery:" + theGallery.id + "]";
											 
											 document.getElementById("submit").value = "Save Changes";
											 document.body.style.cursor = "default";
										} );
}

function mfg_DisplayGallery(id)
{
	MFGgalleryId = id;
	document.getElementById("mfgallerydisplay").innerHTML = "<span style='font-size:200%;'>Loading...</span>";

	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryDisplayGallery";
	requestUrl += "&id=" + id;
	
	//alert(requestUrl);
	
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) 
										{ 
											 //alert(theText);
											 document.getElementById("mfgallerydisplay").innerHTML = theText;
											 document.body.style.cursor = "default";
										} );
}

function mfg_ShowGallery(id)
{
	if( MFGgalleryId == -1 )
		return;
		
	MFGgalleryId = id;
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryGetGalleryInfo";
	requestUrl += "&id=" + id;
	document.body.style.cursor = "wait";
	//alert(requestUrl);
	mfg_SendAjaxCallback( requestUrl, function(theText) 
										{ 
											 //alert(theText);
											 //theGallery = eval("(" + theText + ")");
											 document.body.style.cursor = "default";
											 mfg_DisplayGallery(id);
										} );
}
/*
function mfg_ShowLogfiles()
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryDumpLogs";
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) 
										{ 
											 document.getElementById("mfgallery_uploadlog").innerHTML = theText;
											 document.body.style.cursor = "default";
										} );
}
*/
////////////////////////////
function mfg_SaveGallery()
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGallerySaveGalleryInfo";
	requestUrl += "&id=" + escape(document.getElementById("galleryid").value);
	requestUrl += "&name=" + escape(document.getElementById("galleryname").value);
	requestUrl += "&imageurl=" + escape(document.getElementById("imageurl").value);
	requestUrl += "&maxwidth=" + escape(document.getElementById("maxwidth").value);
	requestUrl += "&maxheight=" + escape(document.getElementById("maxheight").value);
	
	requestUrl += "&autoslideshow=" + (document.getElementById("autoslideshow").checked ? "1" : "0");
	requestUrl += "&showname=" + (document.getElementById("showname").checked ? "1" : "0");
	requestUrl += "&membersonly=" + (document.getElementById("membersonly").checked ? "1" : "0");
	requestUrl += "&showthumbdesc=" + (document.getElementById("showthumbdesc").checked ? "1" : "0");
	requestUrl += "&published=" + (document.getElementById("published").checked ? "1" : "0");
	requestUrl += "&autoresize=" + (document.getElementById("autoresize").checked ? "1" : "0");
	
	//alert(requestUrl);	
	mfg_SendAjaxCallback( requestUrl, function(theText) { //alert(theText);
														//document.getElementById("debuginfo").innerHTML = theText;
														mfg_ClearGalleryForm();
														mfg_GetGalleryList(); 
													  } );
}


function mfg_ClearGalleryForm()
{
	document.getElementById("galleryid").value = -1
	document.getElementById("gallerynumber").innerHTML = "NEW";
	document.getElementById("galleryname").value = "";
	document.getElementById("imageurl").value = "";
	document.getElementById("autoslideshow").checked = false;
	document.getElementById("showname").checked = false;
	document.getElementById("membersonly").checked = false;
	document.getElementById("published").checked = false;
	document.getElementById("autoresize").checked = false;
	document.getElementById("maxwidth").value = "";
	document.getElementById("maxheight").value = "";

	document.getElementById("submit").value = "Save New Gallery";
	document.getElementById("embedcode").value = "";
}
////////////////////////////

function mfg_GetElementHeight(e)
{
	var elem = document.getElementById(e);
	
	if( elem.style.pixelHeight )
		return elem.style.pixelHeight;
	else
		return elem.offsetHeight;
}

function mfg_GetElementWidth(e)
{
	var elem = document.getElementById(e);
	
	if( elem.style.pixelHeight )
		return elem.style.pixelWidth;
	else
		return elem.offsetWidth;
}

function mfg_ResizeWindow()
{
	var newLeft = (pageWidth() - mfg_GetElementWidth("mfgalleryphotoform")) / 2;
	document.getElementById("mfgalleryphotoform").style.left = newLeft + "px";
	
	var newTop = (pageHeight() -  mfg_GetElementHeight("mfgalleryphotoform")) / 2;
	document.getElementById("mfgalleryphotoform").style.top = newTop + "px";
}

function mfg_isParent( element, parent )
{
	var elem = element;
	while( elem != parent && elem.nodeName != "BODY" )
		elem = elem.parentNode;
		
	if( elem == parent )
		return true;
	else
		return false;
}

function mfg_ClickHandler(e)
{
	var clickedElement = e.target || e.srcElement;
	if( ! mfg_isParent( clickedElement, document.getElementById("mfgalleryphotoform") ) )
		mfg_ClearPhotoForm();
}

function mfg_EditImageInfo(id)
{
	MFGeditedImage = id;
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryGetPhotoInfo";
	requestUrl += "&id=" + id;
	
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 	document.body.style.cursor = "default";
															//thePhotoInfo = eval("(" + theText + ")");															
															document.getElementById("mfgalleryphotoform").innerHTML = theText;
															document.getElementById("mfgalleryphotoform").style.visibility = "visible";
															document.getElementById("mfgalleryphotoform").style.display = "block";
															
															var copyright = document.getElementById("copyright").value;
															document.getElementById("copyright").value = copyright.replace("%26copy%3B", "&copy;");
															
															mfg_ResizeWindow();															
															
															if (window.attachEvent)
															{
																window.attachEvent("onresize", mfg_ResizeWindow );
																document.body.attachEvent("onclick", mfg_ClickHandler );
															}
															else
															{
																window.addEventListener("resize", mfg_ResizeWindow, false);
																document.body.addEventListener("click", mfg_ClickHandler, false);
															}
													  	} );
}

function mfg_SavePhotoInfo()
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGallerySavePhotoInfo";
	requestUrl += "&id=" + escape(document.getElementById("photoid").value);
	requestUrl += "&thumbdesc=" + escape(document.getElementById("thumbdesc").value);
	requestUrl += "&modelname=" + escape(document.getElementById("modelname").value);
	requestUrl += "&photographer=" + escape(document.getElementById("photographer").value);
	requestUrl += "&copyright=" + escape(document.getElementById("copyright").value);
	requestUrl += "&description=" + escape(document.getElementById("description").value);
	requestUrl += "&taglist=" + escape(document.getElementById("taglist").value);
	
	//alert(requestUrl);	
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 	document.body.style.cursor = "default";
															//alert("Image Information Saved!");
															mfg_ClearPhotoForm();
													  } );
}

function mfg_ClearPhotoForm()
{
	document.getElementById("photoid").value = -1
	document.getElementById("photonumber").innerHTML = "NEW";
	document.getElementById("thumbdesc").value = "";
	document.getElementById("modelname").value = "";
	document.getElementById("photographer").value = "";
	document.getElementById("copyright").value = "";
	document.getElementById("description").value = "";

	document.getElementById("submit").value = "Save Photo";
	
	document.getElementById("mfgalleryphotoform").innerHTML = "";
	document.getElementById("mfgalleryphotoform").style.visibility = "hidden";
	document.getElementById("mfgalleryphotoform").style.display = "none";
	if( window.detachEvent )
	{
		window.detachEvent( "onresize", mfg_ResizeWindow );
		document.body.detachEvent("onclick", mfg_ClickHandler );
	}
	else
	{
		window.removeEventListener("resize", mfg_ResizeWindow, false );
		document.body.addEventListener("click", mfg_ClickHandler, false);
	}
	MFGeditedImage = -1;
}
////////////////////////////

function mfg_DeleteImage(id)
{
	if( confirm( "Are you sure you want to delete this image?" ) )
	{
		requestUrl = MFGajaxPath;
		requestUrl += "?action=MFGalleryDeleteImage";
		requestUrl += "&id=" + id;
		//alert(requestUrl);
		document.body.style.cursor = "wait";
		mfg_SendAjaxCallback( requestUrl, function(theText) { document.body.style.cursor = "default";
															mfg_DisplayGallery(MFGgalleryId);															
														  } );
	}
}

function mfg_ShowImage(imgpath, displayelem, galleryelem, w, h, mw, mh, caption)
{
	mfg_displayelem = displayelem;
	mfg_galleryelem = galleryelem;
	
	document.getElementById(galleryelem).style.visibility = 'hidden';
	document.getElementById(galleryelem).style.display = 'none';

	var wratio = w / mw;
	var hratio = h / mh;
	var multiplier = 1 / ((wratio > hratio) ? (wratio) : (hratio));

	w *= multiplier;
	h *= multiplier;

	imagecode = "Click image to return to thumbnail view<br />";
	imagecode += "<img class='mfgalleryimagedisplay' width='" + w + "' height='" + h + "' src='" + imgpath + "' onClick='mfg_HideImage(" + '"' + displayelem + '", "' + galleryelem + '");' + "'>";
	
	imagecode += unescape(caption);
	
	//alert(imagecode);
	document.getElementById(displayelem).innerHTML = imagecode;
	
	document.getElementById(displayelem).style.visibility = 'visible';
	document.getElementById(displayelem).style.display = 'block';
	
}

function mfg_HideImage(displayelem, galleryelem)
{
	document.getElementById(displayelem).innerHTML = "";
	
	document.getElementById(galleryelem).style.visibility = 'visible';
	document.getElementById(galleryelem).style.display = 'block';
	document.getElementById(displayelem).style.visibility = 'hidden';
	document.getElementById(displayelem).style.display = 'none';
}

function mfg_RebuildThumbnails(id,displayflag)
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryRebuildGalleryThumbnails";
	requestUrl += "&id=" + id;
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 
											   			//if( theText.length > 0 )
															//alert(theText);
														
														if( displayflag )
															mfg_DisplayGallery(id);															
															
											   			document.body.style.cursor = "default";
													    alert("The thumbnails for this gallery have been rebuilt!");
													  } );
}


function mfg_RebuildGalleryXML(id)
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryRebuildGalleryXML";
	requestUrl += "&id=" + id;
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { document.body.style.cursor = "default";
													      alert(theText + "\n\nThe slideshow XML for this gallery has been rebuilt!");
													  } );
}

function mfg_DeleteGallery(id)
{
	if( confirm( "Are you sure you want to delete gallery #" + id + "?\nThis will also delete all images associated with this gallery." ) )
	{
		requestUrl = MFGajaxPath;
		requestUrl += "?action=MFGalleryDeleteGallery";
		requestUrl += "&id=" + id;
		document.body.style.cursor = "wait";
		mfg_SendAjaxCallback( requestUrl, function(theText) { document.body.style.cursor = "default";
															mfg_GetGalleryList(); 
															alert("The gallery has been deleted!");
														  } );
	}
}

function mfg_PhotoManagement(id)
{
	window.location = '/wp-admin/admin.php?page=MFGalleryPhotoManager&gallery=' + id;
}

function mfg_GetThumbnails(id,start, showdesc, targetelem)
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryGetThumbnails";
	requestUrl += "&id=" + id;
	requestUrl += "&start=" + start;
	requestUrl += "&showthumbdesc=" + showdesc;
	requestUrl += "&targetelem=" + targetelem;
	
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 	document.body.style.cursor = "default";
															//alert(theText);
											   				document.getElementById(targetelem).innerHTML = theText;
													  } );
}

//////////////////////////
// Image rollover code
//////////////////////////

function mfg_ImageRollover( elem, normalstate, overstate, downstate, currentstate )
{
	switch( currentstate )
	{
		case 0:
			document.getElementById(elem).src = normalstate;
			break;
		case 1:
			document.getElementById(elem).src = overstate;
			break;
		case 2:
			document.getElementById(elem).src = downstate;
			break;
	}	
}

//////////////////////////
// This block of code contains functions for the Display Options page
//////////////////////////

function mfg_SaveDisplayOptions()
{
	// To do: Add field validation
	
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGallerySaveGalleryDisplayOptions";
	requestUrl += "&thumbgridsize=" + document.getElementById("thumbgridsize").value;
	requestUrl += "&thumbnailsize=" + document.getElementById("thumbnailsize").value;
	requestUrl += "&thumbcolor=" + escape(document.getElementById("thumbcolor").value);
	requestUrl += "&thumbjpeg=" + document.getElementById("thumbjpeg").value;
	requestUrl += "&thumbborder=" + (document.getElementById("thumbborder").checked ? "1" : "0");
	requestUrl += "&thumbborderwidth=" + document.getElementById("thumbborderwidth").value;
	requestUrl += "&thumbbordercolor=" + escape(document.getElementById("thumbbordercolor").value);
	requestUrl += "&thumbsperpage=" + document.getElementById("thumbsperpage").value;
	requestUrl += "&gwidth=" + document.getElementById("gwidth").value;
	requestUrl += "&gheight=" + document.getElementById("gheight").value;
	requestUrl += "&maximagewidth=" + document.getElementById("maximagewidth").value;
	requestUrl += "&maximageheight=" + document.getElementById("maximageheight").value;

	requestUrl += "&showphotographer=" + (document.getElementById("showphotographer").checked ? "1" : "0");
	requestUrl += "&showcopyright=" + (document.getElementById("showcopyright").checked ? "1" : "0");
	requestUrl += "&showdescription=" + (document.getElementById("showdescription").checked ? "1" : "0");

	//alert(requestUrl);
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 	document.body.style.cursor = "default";
											   				alert("Options Are Saved!\n");
															//document.getElementById("debuginfo").innerHTML = theText;
													  	} );
}

function mfg_UpdateThumbnailPreview()
{
	var w = document.getElementById("thumbnailsize").value * 0.6666;
	try
	{
		document.getElementById("mfgallery_thumbnail_box").style.width = document.getElementById("thumbgridsize").value + "px";
		document.getElementById("mfgallery_thumbnail_box").style.height = document.getElementById("thumbgridsize").value + "px";
		
		var toppadding = (document.getElementById("thumbgridsize").value - document.getElementById("thumbnailsize").value) / 2;
		document.getElementById("mfgallery_thumbnail_img").style.paddingTop = toppadding + "px";
		
		document.getElementById("mfgallery_thumbnail_box").style.backgroundColor = document.getElementById("thumbcolor").value;
	
		if( document.getElementById("thumbborder").checked )
		{
			var bw = document.getElementById("thumbborderwidth").value
			document.getElementById("mfgallery_thumbnail_box").style.border = bw + "px solid " + document.getElementById("thumbbordercolor").value;
		}
		else
		{
			document.getElementById("mfgallery_thumbnail_box").style.border = "none";
		}
		
		document.getElementById("mfgallery_thumbnail_img").style.width = w + "px";
		document.getElementById("mfgallery_thumbnail_img").style.height = document.getElementById("thumbnailsize").value + "px";
	}
	catch(e)
	{
	}
}

function mfg_GetDisplayOptions()
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryGetDisplayOptions";	

	document.body.style.cursor = "wait";

	mfg_SendAjaxCallback( requestUrl, 
						 function(theText) { 	document.body.style.cursor = "default";
						 						//alert(theText);
												theGalleryOptions = eval("(" + theText + ")");															
												document.getElementById("thumbgridsize").value = theGalleryOptions.thumbgridsize;
												document.getElementById("thumbnailsize").value = theGalleryOptions.thumbnailsize;
												document.getElementById("thumbcolor").value = theGalleryOptions.thumbcolor;
												document.getElementById("thumbjpeg").value = theGalleryOptions.thumbjpeg;
												document.getElementById("thumbborder").checked = theGalleryOptions.thumbborder ? true : false;
												document.getElementById("thumbborderwidth").value = theGalleryOptions.thumbborderwidth;
												document.getElementById("thumbbordercolor").value = theGalleryOptions.thumbbordercolor;
												document.getElementById("thumbsperpage").value = theGalleryOptions.thumbsperpage;
												document.getElementById("gwidth").value = theGalleryOptions.gwidth;
												document.getElementById("gheight").value = theGalleryOptions.gheight;
												document.getElementById("maximagewidth").value = theGalleryOptions.maximagewidth;
												document.getElementById("maximageheight").value = theGalleryOptions.maximageheight;	

												document.getElementById("showphotographer").checked = theGalleryOptions.showphotographer ? true : false;
												document.getElementById("showcopyright").checked = theGalleryOptions.showcopyright ? true : false;
												document.getElementById("showdescription").checked = theGalleryOptions.showdescription ? true : false;

												mfg_UpdateThumbnailPreview();											
											} );
}

function mfg_ShowHelp(elem)
{
	var src = "&nbsp;";
	
	if( elem != -1 )
		src = document.getElementById(elem).innerHTML;
	
	document.getElementById("mfgallery_settings_help").innerHTML = src;
}

function mfg_InsertCopyright()
{
	var d = new Date();
	document.getElementById("copyright").value = "Copyright &" + "copy; " + d.getFullYear() + ", All Rights Reserved";
}

function mfg_MoveTop(id)
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryMoveTop";
	requestUrl += "&id=" + id;
	requestUrl += "&galleryid=" + MFGgalleryId;
	
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 	document.getElementById("mfgallerydisplay").innerHTML = theText;
															document.body.style.cursor = "default";
													  } );
}

function mfg_MoveUp(id)
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryMoveUp";
	requestUrl += "&id=" + id;
	requestUrl += "&galleryid=" + MFGgalleryId;
	
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 	document.getElementById("mfgallerydisplay").innerHTML = theText;
															document.body.style.cursor = "default";
													  } );
}

function mfg_MoveDown(id)
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryMoveDown";
	requestUrl += "&id=" + id;
	requestUrl += "&galleryid=" + MFGgalleryId;
	
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 	document.getElementById("mfgallerydisplay").innerHTML = theText;
															document.body.style.cursor = "default";
													  } );
}

function mfg_MoveBottom(id)
{
	requestUrl = MFGajaxPath;
	requestUrl += "?action=MFGalleryMoveBottom";
	requestUrl += "&id=" + id;
	requestUrl += "&galleryid=" + MFGgalleryId;
	
	document.body.style.cursor = "wait";
	mfg_SendAjaxCallback( requestUrl, function(theText) { 	document.getElementById("mfgallerydisplay").innerHTML = theText;
															document.body.style.cursor = "default";
													  } );
}

//////////////////////////
// This block of code contains functions called from Flash Uploader.
//////////////////////////

function mfg_FlashAlert(msg)
{
	alert(msg);
}

function mfg_ImageClicked()
{
	mfg_HideImage( mfg_displayelem, mfg_galleryelem );
}

function mfg_FlashUploadFinished(msg)
{
	//alert(MFGgalleryId);
	mfg_ShowGallery(MFGgalleryId);
	//mfg_ShowLogfiles();
}

function mfg_FlashUploadStarted(msg)
{
	document.getElementById("flashuploadstatus").innerHTML = msg;
}

function mfg_GetGalleryId()
{
	return MFGgalleryId;
}


