function displayDownload()
{
	var oBodyText = document.getElementById('oBodyText');
	var oBodyForm = document.getElementById('oBodyForm');
	
	if (oBodyForm.style.display == 'none')
	{
		oBodyText.style.display = 'none';
		oBodyForm.style.display = 'block';
		document.getElementById('oFormDownload').reset();
		document.getElementById('oName').focus();
		document.getElementById('oDownload').style.visibility = 'visible';
		document.getElementById('bCancel').value = 'Cancel';
	}
	else
	{
		oBodyForm.style.display = 'none';
		oBodyText.style.display = 'block';
		document.getElementById('oDownload').style.visibility = 'visible';
		document.getElementById('bCancel').value = 'Cancel';
	}
}

function displayDownloadList(ReportID, ImageName, ImageText)
{
  var oBodyText = document.getElementById('oBodyText');
  var oBodyList = document.getElementById('oBodyList');
	var oBodyForm = document.getElementById('oBodyForm');
	
	document.getElementById('oSelectedFileImage').src = '../_images/' + ImageName;
	document.getElementById('oSelectedFileText').innerHTML = ImageText;
	
	if (oBodyForm.style.display == 'none')
	{
		oBodyText.style.display = 'none';
		oBodyList.style.display = 'none';
		oBodyForm.style.display = 'block';
		document.getElementById('oFormDownload').reset();
		document.getElementById('oName').focus();
	}
	else
	{
		oBodyForm.style.display = 'none';
		oBodyText.style.display = 'block';
		oBodyList.style.display = 'block';
	}
	document.getElementById('oFile').value = ReportID;
}

function validateRequiredDownload()
{
	var oName = document.getElementById('oName');
	var oCompany = document.getElementById('oCompany');
	var oSector = document.getElementById('oSector');
	var oCountry = document.getElementById('oCountry');
	var oTerms = document.getElementById('oTerms');
	var oFocus = null;
	
	var sErrorMessage = 'You have not completed the form correctly:';
	
	var isValid = true;
	
	if (oName.value.trim() == '')
	{
		sErrorMessage += '\n - You have not provided your name';
		isValid = false;
		oFocus = oName;
	}
	if (oCompany.value.trim() == '')
	{
		sErrorMessage += '\n - You have not provided company name';
		isValid = false;
		if (oFocus == null) { oFocus = oCompany; }
	}
	if (oSector.value.trim() == '')
	{
		sErrorMessage += '\n - You have not selected a sector';
		isValid = false;
		if (oFocus == null) { oFocus = oSector; }
	}
	if (oCountry.value.trim() == '')
	{
		sErrorMessage += '\n - You have not selected a country';
		isValid = false;
		if (oFocus == null) { oFocus = oCompany; }
	}

	if (oTerms.checked == false)
	{
		sErrorMessage += '\n - You have not agreed to the Terms and Conditions';
		isValid = false;
		if (oFocus == null) { oFocus = oSubscribe; }
	}
	
	if (isValid == false)
	{
		sErrorMessage += '\n\n Please correct the incorrect fields and try again';
		alert(sErrorMessage);
		oFocus.focus();
		return false;
	}
	else
	{
		document.getElementById('oDownload').style.visibility = 'hidden';
		document.getElementById('bCancel').value = 'Close';
		return true;
	}
}

function validateRequiredSubscribe()
{
	var oName = document.getElementById('oName');
	var oEmail = document.getElementById('oEmail');
	var oCompany = document.getElementById('oCompany');
	var oSector = document.getElementById('oSector');
	var oCountry = document.getElementById('oCountry');
	var oFocus = null;
	
	var sErrorMessage = 'You have not completed the form correctly:';
	
	var isValid = true;
	
	if (oName.value.trim() == '')
	{
		sErrorMessage += '\n - You have not provided your name';
		isValid = false;
		oFocus = oName;
	}
	if (validateEmail(oEmail) == false)
	{
	  sErrorMessage += '\n - You have not provided a valid email address for subscriptions';
		isValid = false;
		if (oFocus == null) { oFocus = oEmail; }
  }
	if (oCompany.value.trim() == '')
	{
		sErrorMessage += '\n - You have not provided company name';
		isValid = false;
		if (oFocus == null) { oFocus = oCompany; }
	}
	if (oSector.value.trim() == '')
	{
		sErrorMessage += '\n - You have not selected a sector';
		isValid = false;
		if (oFocus == null) { oFocus = oSector; }
	}
	if (oCountry.value.trim() == '')
	{
		sErrorMessage += '\n - You have not selected a country';
		isValid = false;
		if (oFocus == null) { oFocus = oCompany; }
	}

	if (isValid == false)
	{
		sErrorMessage += '\n\n Please correct the incorrect fields and try again';
		alert(sErrorMessage);
		oFocus.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function validateRequiredUnsubscribe()
{
	var oEmail = document.getElementById('oEmail');
	var oFocus = null;
	
	var sErrorMessage = 'You have not entered a valid email address\n\nPlease enter a valid email address and try again.';
	var isValid = true;
	
	if (validateEmail(oEmail) == false)
	{
		isValid = false;
		if (oFocus == null) { oFocus = oEmail; }
  }

	if (isValid == false)
	{
		alert(sErrorMessage);
		oFocus.focus();
		return false;
	}
	else
	{
		return true;
	}
}


function validateEmail(field)
{
	with (field)
  {
  	apos=value.indexOf("@");
  	dotpos=value.lastIndexOf(".");
  	if (apos<1||dotpos-apos<2)
    	return false;
  	else 
  		return true;
  }
}
