function validateUpload(fileControlName, assetTypeDropDownControlName, allowedExtensions, isPending)
{
	var typeControl = document.getElementById(assetTypeDropDownControlName);
	var fileControl = document.getElementById(fileControlName);
	
	var errormessage = "";
	
	if (typeControl)
	{
		if (typeControl.options[typeControl.options.selectedIndex].value == "0")
			errormessage += "\n* No asset type specified";
		
		if (allowedExtensions)
			allowedExtensions += "zip;";
	}
		
	if (!fileControl.value)
	{
		errormessage += "\n* No file specified";
	}
	else
	{
		if (allowedExtensions)
		{
			var path = fileControl.value.toLowerCase();
			var ext = path.match(/(.{3}$)/);
			if (ext)
			{
				ext = ext[1];
				
				if (ext)
				{
					var pattern = ext + ";";
					if (!allowedExtensions.match(pattern))
						errormessage += "\n* The extension '" + ext + "' is invalid for the selected asset type";
				}
				else
				{
					errormessage += "\n* File has unknown extension";
				}
			}
			else
			{
				errormessage += "\n* File has missing extension";
			}
		}
	}
		
	if (errormessage)
	{
		alert("Unable to upload assets.  Please correct the following errors and try again:\n" + errormessage);
		return false;
	}
	
	if (isPending)
	{
		var c = confirm('Replacing the asset will require it to be checked by administrators\nbefore publication.  Are you sure you wish to proceed?');
		if (!c)
			return false;
	}
	
	// Delay attaching the onbeforeunload handler for two seconds
	// so that the postback can go through okay without warning the user
	window.setTimeout("attachOnBeforeUnloadHandler()", 2000);
	
	return true;
}

function attachOnBeforeUnloadHandler()
{
	window.onbeforeunload = confirmExitDuringFileUpload;
}

function confirmExitDuringFileUpload()
{
	return "There appears to be a file upload in progress.  Leaving this page will cancel the upload.";				
}

function getAbsolutePath() {
    var loc = window.location;
    var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
    return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
}

function showAssetInfo(assetId, returnWin, path) {
    var url = ((null == path || 0 == path.length) ? getAbsolutePath() : path) + "Popups/AssetInfo.aspx?assetId=" + assetId;    
	var width = 730;
	var height = 600;

	var leftPosition = (screen.width)?(screen.width-width)/2:100;
	var topPosition = (screen.height)?(screen.height-height)/2:100;
	var settings = 'width='+width+',height='+height+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';	
	var win = window.open(url, 'win_'+assetId, settings);
	
	if (returnWin)
		return win;
}

function showToolTip(c, t)
{
	overlib(t, CAPTION, c)
}

function hideToolTip()
{
	return nd();
}

function toggleCheckboxes(container, state)
{
	var e = document.getElementById(container);
	var chks = e.getElementsByTagName("input");
	
	for (var chkindex in chks)
	{
		var chk = chks[chkindex];
		if (chk.type == 'checkbox')
		{
			chk.checked = state;
		}
	}
}

function toggleCheckboxesEnabled(container, enabled)
{
	// Get all of the input elements
	var e = document.getElementById(container);
	var inputs = e.getElementsByTagName("input");
	
	// Internet Explorer puts a 'disabled' attribute on the container
	// table so remove it from there (otherwise, the javascript below
	// won't result in any change in the UI, even though the properties will change)
	// if (e.getElementsByTagName("table"))
	//	e.getElementsByTagName("table")[0].disabled = !enabled;
	
	// Iterate through all of the elements toggling their disabled
	// or checked properties according to the 'enabled' parameter.
	for (var i=0; i < inputs.length; i++)
	{
		var ie = inputs[i];
		
		if (ie.type == 'checkbox')
		{
			if (enabled)
			{
				ie.disabled = false;
			}
			else
			{
				ie.disabled = true;
				ie.checked = false;
			}
		}
	}
}

function toggleFileSize(dd, tbid)
{
	var tb = document.getElementById(tbid);
	tb.disabled = (dd.options.selectedIndex == 0);
}
