function MoveGallery(id, dir)
{
    var frm = window.frmGalleries;
	var galleryId, galleryName, galleryRows, galleryCols, isActive;
	
	if(dir == "up")
	{
		galleryId = frm["galleryId" + id].value;
		frm["galleryId" + id].value = frm["galleryId" + (id - 1)].value;
		frm["galleryId" + (id - 1)].value = galleryId;
		
		galleryName = frm["galleryName" + id].value;
		frm["galleryName" + id].value = frm["galleryName" + (id - 1)].value;
		frm["galleryName" + (id - 1)].value = galleryName;
		
		galleryRows = frm["galleryRows" + id].value;
		frm["galleryRows" + id].value = frm["galleryRows" + (id - 1)].value;
		frm["galleryRows" + (id - 1)].value = galleryRows;
		
		galleryCols = frm["galleryCols" + id].value;
		frm["galleryCols" + id].value = frm["galleryCols" + (id - 1)].value;
		frm["galleryCols" + (id - 1)].value = galleryCols;
		
		isActive = frm["isActive" + id].checked;
		frm["isActive" + id].checked = frm["isActive" + (id - 1)].checked;
		frm["isActive" + (id - 1)].checked = isActive;
	}
	else
	{
		galleryId = frm["galleryId" + id].value;
		frm["galleryId" + id].value = frm["galleryId" + (id + 1)].value;
		frm["galleryId" + (id + 1)].value = galleryId;
		
		galleryName = frm["galleryName" + id].value;
		frm["galleryName" + id].value = frm["galleryName" + (id + 1)].value;
		frm["galleryName" + (id + 1)].value = galleryName;
		
		galleryRows = frm["galleryRows" + id].value;
		frm["galleryRows" + id].value = frm["galleryRows" + (id + 1)].value;
		frm["galleryRows" + (id + 1)].value = galleryRows;
		
		galleryCols = frm["galleryCols" + id].value;
		frm["galleryCols" + id].value = frm["galleryCols" + (id + 1)].value;
		frm["galleryCols" + (id + 1)].value = galleryCols;
		
		isActive = frm["isActive" + id].checked;
		frm["isActive" + id].checked = frm["isActive" + (id + 1)].checked;
		frm["isActive" + (id + 1)].checked = isActive;
	}
}

function GetGalleryImages(frm)
{
	GetPage("admin_gallery.aspx?galleryid=" + frm.gallery.value, "content");
}

function doPreview()
{
	top.frames["rightbar"].location.href = "preview.aspx?cat_id=" + window.frmGallery.cat.value;
}

function MoveImage(id, dir)
{
    var frm = window.frmGallery;
	var img_id, img_name, img_filename, img_desc, img_thumb, img_checked;
	
	if(dir == "up")
	{
		img_id = frm["img_id" + id].value;
		frm["img_id" + id].value = frm["img_id" + (id - 1)].value;
		frm["img_id" + (id - 1)].value = img_id;
		
		img_name = frm["img_name" + id].value;
		frm["img_name" + id].value = frm["img_name" + (id - 1)].value;
		frm["img_name" + (id - 1)].value = img_name;
			
		img_filename = frm["img_filename" + id].value;
		frm["img_filename" + id].value = frm["img_filename" + (id - 1)].value;
		frm["img_filename" + (id - 1)].value = img_filename;
		
		img_oldfilename = frm["img_oldfilename" + id].value;
		frm["img_oldfilename" + id].value = frm["img_oldfilename" + (id - 1)].value;
		frm["img_oldfilename" + (id - 1)].value = img_oldfilename;
		
		img_desc = frm["img_desc" + id].value;
		frm["img_desc" + id].value = frm["img_desc" + (id - 1)].value;
		frm["img_desc" + (id - 1)].value = img_desc;
		
		img_thumb = document.getElementById("img_thumb" + id).src;
		document.getElementById("img_thumb" + id).src = document.getElementById("img_thumb" + (id - 1)).src;
		document.getElementById("img_thumb" + (id - 1)).src = img_thumb;
		
		img_checked = frm["img_default" + id].checked;
		frm["img_default" + (id - 1)].checked = frm["img_default" + id].checked;
		frm["img_default" + id].checked = img_checked;
	}
	else
	{
		img_id = frm["img_id" + id].value;
		frm["img_id" + id].value = frm["img_id" + (id + 1)].value;
		frm["img_id" + (id + 1)].value = img_id;
		
		img_name = frm["img_name" + id].value;
		frm["img_name" + id].value = frm["img_name" + (id + 1)].value;
		frm["img_name" + (id + 1)].value = img_name;

		img_filename = frm["img_filename" + id].value;
		frm["img_filename" + id].value = frm["img_filename" + (id + 1)].value;
		frm["img_filename" + (id + 1)].value = img_filename;
		
		img_oldfilename = frm["img_oldfilename" + id].value;
		frm["img_oldfilename" + id].value = frm["img_oldfilename" + (id + 1)].value;
		frm["img_oldfilename" + (id + 1)].value = img_oldfilename;
		
		img_desc = frm["img_desc" + id].value;
		frm["img_desc" + id].value = frm["img_desc" + (id + 1)].value;
		frm["img_desc" + (id + 1)].value = img_desc;

		img_thumb = document.getElementById("img_thumb" + id).src;
		document.getElementById("img_thumb" + id).src = document.getElementById("img_thumb" + (id + 1)).src;
		document.getElementById("img_thumb" + (id + 1)).src = img_thumb;
		
		img_checked = frm["img_default" + (id + 1)].checked;
		frm["img_default" + (id + 1)].checked = frm["img_default" + id].checked;
		frm["img_default" + id].checked = img_checked;
	}
}

function ImageGalleryMove(frm, id, index)
{
    frm["galleryId"].value = frm["img_movecat" + index].value;
	frm.action = "admin_gallery.aspx?move=1&img_id=" + id;
	frm["submit"].click();
}

function ImageErase(frm, id, cat_id)
{
	if(window.confirm("Are you sure you want to Erase this image?") == true)
	{
		frm.action = "admin_gallery.aspx?erase_img=" + frm["img_id" + id].value;
		frm["submit"].click();
	}
}

function UpdateDefaultImage(frm, id)
{
    var i;
    for(i = 0; i < frm.length; i++)
    {
        if(frm[i].name.indexOf("img_default") > -1)
        {
            if(frm[i].name == "img_default" + id)
            {
                frm[i].checked = true;
            }
            else
            {
                frm[i].checked = false;
            }
        }
    }
}

