function retrieveArchiveFiles(manual, section, date, url)
{	
	if(!(validateRetrieveArchiveFiles(manual.value, section.value, date.value)))
	{
		return;
	}
	var dt = (date.value).split("/");
	
	if (dt[2] < 2008)
	{
		window.open('../presentation/archiveMessage.jsp','Manuals','width=300,height=130,left=500,top=400,screenX=300,screenY=400');
		return false;
	}
		
	var parms =   manual.name 
				+ "=" 
				+ manual.value 
				+ "&" 
				+ section.name 
				+ "="
				+ section.value
				+ "&" 
				+ date.name 
				+ "="
				+ date.value;
	
	var req = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: parms, 
			onComplete: processArchiveFilesResponse,
			onFailure: function(parm) 
					   {
       				   	alert('AJAX call to obtain Archive Files Error: ' + parm.status + ' -- ' + parm.statusText);
       				   }
		});
}

function processArchiveFilesResponse(req)
{	
	var nodeLength = req.responseXML.documentElement.
						getElementsByTagName('ArchiveFileNode').length;
	var url;
	var name;
	var buffer = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	var content = buffer + "<span class=txt1><u>Results:</u></span></br></br>";

	for(var i=0; i < nodeLength; i++)
	{	
		url = req.responseXML.documentElement.
					getElementsByTagName('ArchiveFileNode')[i].
					getElementsByTagName('Url')[0].childNodes[0].nodeValue;

		name = req.responseXML.documentElement.
					getElementsByTagName('ArchiveFileNode')[i].
					getElementsByTagName('Name')[0].childNodes[0].nodeValue;

		content = content + buffer + "<a href=" + url + " target=_blank id=idSectionHref><span class=txt1>" + name + "</span></a></br>";
	}

	if(nodeLength == 0)
	{
		document.getElementById("idSections").innerHTML = content + buffer + "<span class=txt1>No Manual Sections available at this time.</span>";
	}
	else
	{
		//document.getElementById("idSections").innerHTML = content;
		document.getElementById("idSections").innerHTML = "";
		window.open(url);
	}
}

function openLinkWindow(url) 
{
	window.open(url,'win','width=750,height=500,resizable=1,scrollbars=1');
}

function validateArchiveSearch(inForm, isArchiveSearch)
{
	if(isArchiveSearch == 'true')
	{
		var month = inForm.archiveFileSearchMonth.value;
		var year = inForm.archiveFileSearchYear.value;
		
		
		if((month == 'NA' && year != 'NA') || (month != 'NA' && year == 'NA'))
		{
			alert("If the archive search should include a date, please specify both the month and the year.");
			return false;
		}else if ((year != 'NA' && year < 2008) || ( month < 7 && year == 2008) )
		{
			window.open('/manuals/presentation/archiveMessage.jsp','Manuals','width=300,height=130,left=500,top=200,screenX=300,screenY=400');
			return false;
		}
		
	}
	
	return true;
}

function validateRetrieveArchiveFiles(manual, section, date)
{	
	if(manual == 'NA')
	{
		alert("Please select a manual category.");
		return false;
	}
	else if(section == '' || section.length != 2 || !isInteger(section))
	{
		alert("Please input a 2-digit section number.");
		return false;
	}
	else if(date == '')
	{
		alert("Please select a date.");
		return false;
	}

	var today = new Date();
	var viewByDate = new Date(date);
	
	if(viewByDate > today)
	{
		alert("Dates in the future are invalid. Please enter a valid date.");
		return false;
	}
		
	return true;
}

function executeSearchDataPersistence(originalQuery, collection, isArchiveFileSearch, archiveMonth, archiveYear)
{
	document.forms[0].q.value = originalQuery;
	document.forms[0].site.selectedIndex = 2;
	for(i=0; i < document.forms[0].site.length; i++){
		if(document.forms[0].site[i].value == collection){
			document.forms[0].site[i].selected = true;		
		}
	}
	
	if(isArchiveFileSearch == 'true')
	{
		//archive month
		document.forms[0].archiveFileSearchMonth.selectedIndex = 0;
		for(j=0; j < document.forms[0].archiveFileSearchMonth.length; j++){
			if(document.forms[0].archiveFileSearchMonth[j].value == archiveMonth){
				document.forms[0].archiveFileSearchMonth[j].selected = true;		
			}
		}

		//archive year
		document.forms[0].archiveFileSearchYear.selectedIndex = 0;
		for(k=0; k < document.forms[0].archiveFileSearchYear.length; k++){
			if(document.forms[0].archiveFileSearchYear[k].value == archiveYear){
				document.forms[0].archiveFileSearchYear[k].selected = true;		
			}
		}
	}
}

function viewbydateConfirm() {
	var result = confirm("You are entering into View By Date search");		
	if(result) {
		return true;
	} else { 
		window.location = "/manuals/presentation/index.jsp";
		return false;
	}
}

function archiveConfirm() {
	var result = confirm("This will take you to archive documents that are no longer in production.\nThey do not contain current information.\nContinue to archive documents by clicking ok \nor click cancel to stay on same page.");	
	if(result)
		return true;
	else
		return false;
}

function isInteger(number) {
         
	var modulus = number % 1;

    if (modulus == 0)
    	return true;
    else
        return false;   
}