		
// ----- Action Methods -----

function setCurrField()
{
	var FieldRef = document.getElementById("Email");
	FieldRef.focus();
}

function validate(pbMember)
{	
	if (pbMember==0)
	{
		// Name
		var Name = document.getElementById("Name").value;
		if (Name.length<5)
		{
			alert("Please enter your full name.");
			return false;
		}
		
			// Country
		var Country = document.getElementById("Country").value;
		if (Country.length<2)
		{
			alert("Please enter your country name.");
			return false;
		}
	}
	
	// Email Address
	var Email = document.getElementById("Email").value;
	var EmailOK = checkEmailAddress(Email);
	//if (EmailOK==false)
	if (checkEmailAddress(Email)==false)
	{
		alert("Please enter a valid email address.");
		return false;
	}
	
	// File Selected?
	var FilesCSV = retSelectedFilesCSV();
	if (FilesCSV.length==0)
	{
		alert("Please select the files you wish to download.");
		return false;
	}
	
	return true;
	
}

function retSelectedFilesCSV()
{	

	// Loop through the downloads form and build a string of all the selected files.
	var ParentRef = document.forms.DownloadFilesForm;
	var ElementNum = document.forms.DownloadFilesForm.length;	
	var FilesCSV = ""
	var ElementType = ""
	var ElementChecked = 0
	//alert("ElementNum = "+ElementNum);	
	
	for (count=0;count<ElementNum;count++)
	{	
		if (ParentRef.elements[count].type=="checkbox")
		{
			if (ParentRef.elements[count].checked)
			{	
				FilesCSV = FilesCSV+","+ParentRef.elements[count].id ;
			}					
		}
	}
	return FilesCSV;
}	
	

function submitRequest(pbMember)
{	
	var ValidateOK = validate(pbMember);
	if (ValidateOK==true)
	{	
		if (pbMember==0)
		{
			var Name = document.getElementById("Name").value;
			var Country = document.getElementById("Country").value;
		}
		var Email = document.getElementById("Email").value;
		var FilesCSV = retSelectedFilesCSV();
		var rTypeID = document.getElementById("TypeID")
		if (rTypeID)
		{
			alert("TypeID = true");
			var TypeID = document.getElementById("TypeID").value;
		}
	
		// Calculate the URL which will submit the request to the Omnis web app server.
		var CGI = OmnisCGI();
		var Port = OmnisPort();
		var Lib = OmnisLib();
		var Class = "rtRequestDownloadInfo"
		var MethodName = "emailDownloadInfo"
		var URL = CGI+"?OmnisServer="+Port+"&OmnisLibrary="+Lib+"&OmnisClass="+Class+"&MethodName="+MethodName+"&Name="+Name+"&Email="+Email+"&Country="+Country+"&FilesCSV="+FilesCSV+"&TypeID="+TypeID; 	
		
		// Open the window and set the contents. (last parameter is replaceFlag)
		SubWinRef = window.open('','',"width=600,height=500,fullscreen,resizable",1);
		var HTML = "<html><head><title>Request Download Info</title></head><body><p>An email to "+Email+" with the download information is being prepared and sent by an Omnis Studio web app.</p><p>You can continue browsing while your request is being processed.</p></body></html>";
		SubWinRef.document.write(HTML);
		SubWinRef.document.close();
		
		// After the window is open point it to the URL so that Omnis is called and starts generating the email.
		SubWinRef.location.href = URL;
		// Omnis will replace the window once the email has been generated.
	}
}
