function MM_swapImage() {
    var i,j=0,x,a=MM_swapImage.arguments; 
    document.MM_sr=new Array; 
    for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null) {
			document.MM_sr[j++]=x; 
			if(!x.oSrc) 
				x.oSrc=x.src; x.src=a[i+2];
		}
} 

function MM_swapImgRestore() {
    var i,x,a=document.MM_sr; 
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
		x.src=x.oSrc;
}
 
function MM_findObj(n, d) {
    var p,i,x;  
    if(!d) 
      d=document; 
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
		if(!(x=d[n])&&d.all) 
			x=d.all[n]; 
		for (i=0;!x&&i<d.forms.length;i++) 
			x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
			x=MM_findObj(n,d.layers[i].document);
    if(!x && document.getElementById)  
		x=document.getElementById(n); 
    return x;
}

function SubmitJobResults() {
	w = 425;
	h = 500;
	LeftPosition = (screen.width)?(screen.width-w)/2:100;
	TopPosition = (screen.height)?(screen.height-h)/2:100;

	settings = 'width='+w+',height='+h+',resizable=yes,scrollbars=yes,status=yes,left='+LeftPosition+',top='+TopPosition+',location=no,directories=no,menubar=no,toolbar=yes';

	var NewWind = window.open('','remote',settings);
	if (NewWind.opener == null) {
		NewWind.opener=window;
	}

	//document.jobresults.submit();

}

function SubmitWorkspaceForm(type,action) 
{
    var Count = 0;
    var ElementArray = new Array;
    var ACLArray = new Array;

	for (var i = 0; i < document.forms[0].length; i++) 
	{
		if (document.forms[0].elements[i].type == "checkbox")
		{
			if (document.forms[0].elements[i].checked == true) 
			{
				ACLArray[Count] = document.forms[0].elements[i].id;
				ElementArray[Count] = document.forms[0].elements[i];
				Count = Count + 1;
			}
		}
	}
	
	if (Count > 0)
	{
		if (action == "DownloadHires")
		{
			if (document.forms[0].enabledownloadhires.value == "true")
			{
				SubmitForm(action, 425, 500);
			}
		}	
		if (action == "DownloadLores")
		{
			if (document.forms[0].enabledownloadlores.value == "true")
			{
				SubmitForm(action, 425, 500);
			}
		}	
		if (action == "ConvertHires")
		{
			if (document.forms[0].enableconverthires.value == "true")
			{
				SubmitForm(action, 700, 500);
			}
		}	
		if (action == "EditImage")
		{
			if (document.forms[0].enableeditimage.value == "true")
			{
				SubmitForm(action, 700, 500);
			}
		}	
		if (action == "Order")
		{
			if (document.forms[0].enableorderhires.value == "true")
			{
				SubmitForm(action, 600, 725);
			}
		}		
		if (action == "Add2LBox")
		{
			if (document.forms[0].enablecreatlightbox.value == "true")
			{
				SubmitForm(action, 425, 500);
			}
		}	
		if (action == "Add2Rpt")
		{
			if (document.forms[0].enablereport.value == "true")
			{
				SubmitForm(action, 450, 660);
			}
		}	
		if (action == "Trash")
		{
			if (document.forms[0].enabletrash.value == "true")
			{
				document.forms[0].workaction.value = action;
				document.forms[0].target = "_self";
				document.forms[0].submit();
				//SubmitForm(action, 425, 500);
			}
		}	
		if (action == "Add2Workspace")
		{
			if (document.forms[0].enableclipboard.value == "true")
			{		
				if (done == "jobquery")
				{
					document.forms[0].target = "_parent";
				}
				else
				{
					document.forms[0].target = "_self";
				}
				
				
				document.forms[0].workaction.value = action;
				document.forms[0].submit();
			}
		}	
	}
	
    if (action == "refresh") 
    {
        document.forms[0].workaction.value = action;
		document.forms[0].target = '';
        document.forms[0].submit();
    } 
}

function SubmitForm(action, w, h)
{
	document.forms[0].workaction.value = action;
		
	var LeftPosition = (screen.width)?(screen.width-w)/2:100;
	var TopPosition = (screen.height)?(screen.height-h)/2:100;

	var settings = 'width='+w+',height='+h+',resizable=yes,scrollbars=yes,status=yes,left='+LeftPosition+',top='+TopPosition+',location=no,directories=no,menubar=no,toolbar=no';
			
	var NewWind = window.open('','remote',settings);
	if (NewWind.opener == null) {
		NewWind.opener=window;
	}
	document.forms[0].submit();
}

function SubmitWorkspaceFormOld(type,action) {

    if (type == "searchresults") 
    {
        var count;
        var checked = 0;
        var length = document.results.elements.length;

        for (count = 4; count < length; count++) {
			if (document.results.elements[count].checked == true) {
                checked = checked + 1;
            }
        }

		if (checked != 1 && action == "EditImage")
		{
			alert('Please select one element to edit image.');
		}
        else if (checked > 0) {
            document.results.workaction.value = action;

			if (action == "ConvertHires" || action == "EditImage") {
				w = 700;
				h = 500;
			}
			else {
				w = 425;
				h = 500;
			}
			
			LeftPosition = (screen.width)?(screen.width-w)/2:100;
			TopPosition = (screen.height)?(screen.height-h)/2:100;

			settings = 'width='+w+',height='+h+',resizable=yes,scrollbars=yes,status=yes,left='+LeftPosition+',top='+TopPosition+',location=no,directories=no,menubar=no,toolbar=no';
			var NewWind = window.open('','remote',settings);
			if (NewWind.opener == null) {
				NewWind.opener=window;
			}
			document.results.submit();
		}
		else {
            if (action == "Add2Workspace") {
                alert('You must select at least one element to add to your workspace.');
            }
            else if (action == "DownloadHires" || action == "DownloadLores") {
                alert('You must select at least one element to download.');
            }
            else if (action == "ConvertHires") {
                alert('You must select at least one element to convert hires.');
            }
            else if (action == "Order") {
                alert('You must select at least one element to order.');
            }
            else if (action == "Add2LBox") {
                alert('You must select at least one element to add to a lightbox.');
            }
            else if (action == "Add2Rpt") {
                alert('You must select at least one element to add to a report.');
            }
        }
    } 
    else if (type == "lightbox") {
        var count;
        var checked = 0;
        var length = document.lightbox.elements.length;

        if (action == "refresh") {
            document.lightbox.workaction.value = action;
			document.workspace.target = '';
            document.lightbox.submit();
        } 
        else {
			for (count = 2; count < length; count++) {
				if (document.lightbox.elements[count].checked == true) {
					checked = checked + 1;
				}
			}

			if (checked != 1 && action == "EditImage")
			{
				alert('Please select one element to edit image.');
			}
			else if (checked > 0) 
			{
				document.lightbox.workaction.value = action;

				if (action == "ConvertHires" || action == "EditImage") {
					w = 700;
					h = 500;
				}
				else {
					w = 425;
					h = 500;
				}
				
				LeftPosition = (screen.width)?(screen.width-w)/2:100;
				TopPosition = (screen.height)?(screen.height-h)/2:100;

				settings = 'width='+w+',height='+h+',resizable=yes,scrollbars=yes,status=yes,left='+LeftPosition+',top='+TopPosition+',location=no,directories=no,menubar=no,toolbar=no';
				var NewWind = window.open('','remote',settings);
				if (NewWind.opener == null) {
					NewWind.opener=window;
				}
				document.lightbox.submit();
			}
			else 
			{
				if (action == "DownloadHires" || action == "DownloadLores") {
					alert('You must select at least one element to download.');
				}
				else if (action == "ConvertHires") {
					alert('You must select at least one element to convert hires.');
				}
				else if (action == "Order") {
					alert('You must select at least one element to order.');
				}
			}
        }
    }
    else {
        var count;
        var checked = 0;
        var length = document.workspace.elements.length;

        //sort workspace, so don't check for action
        if (action == "refresh") {
            document.workspace.workaction.value = action;
			document.workspace.target = '';
            document.workspace.submit();
        } 
        else {
			for (count = 0; count < document.forms[0].length; count++) 
			{
				if (document.forms[0].elements[count].type == "checkbox")
				{
					if (document.forms[0].elements[count].checked == true) 
					{
						checked = checked + 1;
					}
				}
			}

			if ((checked > 0) && (action == "Trash")) {
				document.workspace.workaction.value = action;
				document.workspace.target = '';
				document.workspace.submit();
			}
			else if (checked != 1 && action == "EditImage")
			{
				alert('Please select element to edit image.');
			}
			else if ((checked > 0) && (action != "Trash")) 
			{		
				document.workspace.workaction.value = action;

				if (action == "ConvertHires" || action == "EditImage") {
					w = 700;
					h = 500;
				}
				else {
					w = 425;
					h = 500;
				}
				
				LeftPosition = (screen.width)?(screen.width-w)/2:100;
				TopPosition = (screen.height)?(screen.height-h)/2:100;

				settings = 'width='+w+',height='+h+',resizable=yes,scrollbars=yes,status=yes,left='+LeftPosition+',top='+TopPosition+',location=no,directories=no,menubar=no,toolbar=no';
					
				var NewWind = window.open('','remote',settings);
				if (NewWind.opener == null) {
					NewWind.opener=window;
				}
				document.workspace.submit();
			}
			else {
				if (action == "Trash") {
					alert('You must select at least one element to remove from your workspace.');
				}
				else if (action == "DownloadHires" || action == "DownloadLores") {
					alert('You must select at least one element to download.');
				}
				else if (action == "ConvertHires") {
					alert('You must select at least one element to convert hires.');
				}
				else if (action == "Order") {
					alert('You must select at least one element to order.');
				}
				else if (action == "Add2LBox") {
					alert('You must select at least one element to add to a lightbox.');
				}
				else if (action == "Add2Rpt") {
					alert('You must select at least one element to add to a report.');
				}
			}
        }
    }
}


function SubmitDownloadForm() {
    document.download.submit();
}

function SubmitLightboxForm() {
    document.lightbox.submit();
}

function SubmitOrderForm() {
    document.order.submit();
}

function SubmitSearchForm() {
    document.searchform.submit();
}

function SubmitJobSearchForm() {
    document.jjsearchform.submit();
}

function SubmitPrefsForm(Mode)
{	
	if (document.forms[0].cachejobtrecheckbox.checked == true)
	{
		document.forms[0].cachejobtre.value = "1";
	}
	else
	{
		document.forms[0].cachejobtre.value = "0";	
	}
	
	if (document.forms[0].cachedbfieldscheckbox.checked == true)
	{
		document.forms[0].cachedbfields.value = "1";
	}
	else
	{
		document.forms[0].cachedbfields.value = "0";	
	}
	
	if (document.forms[0].cachedbclasscheckbox.checked == true)
	{
		document.forms[0].cachedbclass.value = "1";
	}
	else
	{
		document.forms[0].cachedbclass.value = "0";	
	}
	
	if (document.forms[0].cachedbmetacheckbox.checked == true)
	{
		document.forms[0].cachedbmeta.value = "1";
	}
	else
	{
		document.forms[0].cachedbmeta.value = "0";	
	}
	
	document.forms[0].submit();
}

function SubmitAdminForm() {
    document.admin.submit();
}

function SubmitLBControlForm() {
    document.lbcontrol.submit();
}

function SubmitSearchResultsForm() {
    document.results.submit();
}

function GetPageInfo(form,pageno) {
    document.results.target = '';
    document.results.req_page.value = pageno;
    document.results.submit();
}

function SetMenuDisplayBasedOnACLs()
{
	var count = 0;
	var ElementACLStringArray = new Array;

	for (i = 0; i < document.forms[0].elements.length; i++)
	{
		if (document.forms[0].elements[i].type == "checkbox")
		{
			if (document.forms[0].elements[i].checked == true)
			{
				ElementACLStringArray[count] = document.forms[0].elements[i].id;
				count++;
			}
		}
	}

	if (ElementACLStringArray.length >= 1)
	{
		SetIcon(GetResolveElementACL(ElementACLStringArray, 8), "enabledownloadlores", "icondownloadlo");
		SetIcon(GetResolveElementACL(ElementACLStringArray, 9), "enabledownloadhires", "icondownloadhi");
		SetIcon(GetResolveElementACL(ElementACLStringArray, 10), "enableorderhires", "iconorderhi");
		SetIcon(GetResolveElementACL(ElementACLStringArray, 13), "enableconverthires", "iconconverthi");
		SetIcon(GetResolveElementACL(ElementACLStringArray, 13), "enableeditimage", "iconedithi");
		SetIcon(GetResolveElementACL(ElementACLStringArray, 16), "enablecreatlightbox", "iconcreatelbox");
		SetIcon("true", "enablereport", "iconreport");
		SetIcon("true", "enabletrash", "icontrash");
		SetIcon("true", "enableclipboard", "iconclipboard");		
	}
	else
	{
		SetIcon("false", "enabledownloadlores", "icondownloadlo");
		SetIcon("false", "enabledownloadhires", "icondownloadhi");
		SetIcon("false", "enableorderhires", "iconorderhi");
		SetIcon("false", "enableconverthires", "iconconverthi");
		SetIcon("false", "enableeditimage", "iconedithi");
		SetIcon("false", "enablecreatlightbox", "iconcreatelbox");
		SetIcon("false", "enablereport", "iconreport");
		SetIcon("false", "enabletrash", "icontrash");
		SetIcon("false", "enableclipboard", "iconclipboard");		
	}
}

function SetIcon(ElementACLFlag, ACLFlagID, IconID)
{
	var Icon = document.getElementById(IconID);
	var ACLFlag = document.getElementById(ACLFlagID);
	
	if (null != Icon && null != ACLFlag)
	{
		if (ElementACLFlag == "true")
		{
			ACLFlag.value = ElementACLFlag;
			EnableIcon(IconID);
		}
		else
		{
			ACLFlag.value = "false";
			DisableIcon(IconID);
		}
	}
}



function GetResolveElementACL(ElementACLStringArray, anIndex)
{
	var aResolvedACL = "true";

	for (i = 0; i < ElementACLStringArray.length; i++)
	{
		var ElementACL = ElementACLStringArray[i].split("::::");
		for (j = 0; j < ElementACL.length; j++)
		{
			if (ElementACL[anIndex] == "F")
			{
				aResolvedACL = "false";
			}
		}
	}

	return aResolvedACL;
}

