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, 640, 725);
			}
		}	
		if (action == "DownloadLores")
		{
			if (document.forms[0].enabledownloadlores.value == "true")
			{
				SubmitForm(action, 640, 500);
			}
		}	
		if (action == "ConvertHires")
		{
			if (document.forms[0].enableconverthires.value == "true")
			{
				SubmitForm(action, 680, 500);
			}
		}	
		if (action == "SlideShow")
		{
			if (document.forms[0].enableslideshow.value == "true")
			{
				SubmitForm(action, 800, 700);
			}
		}	
		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, 640, 725);
			}
		}		
		if (action == "Add2LBox")
		{
			if (document.forms[0].enablecreatlightbox.value == "true")
			{
				SubmitForm(action, 640, 500);
			}
		}	
		if (action == "Add2Rpt")
		{
			if (document.forms[0].enablereport.value == "true")
			{
				SubmitForm(action, 640, 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" && collections != "true")
				{
					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 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");
		SetIcon("true", "enableslideshow", "iconslideshow");		
	}
	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");	
		SetIcon("false", "enableslideshow", "iconslideshow");	
	}
}

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;
}
