var ajax = getXMLHttpRequest(); // get object to send ajax calls
var instance=1;

function getXMLHttpRequest()
{
     var request = false;

    try
    {
        request = new XMLHttpRequest();
    }
    catch (err1)
    {
        try
        {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (err2)
        {
            try
            {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (err3)
            {
                request = false;
            }
        }
    }
    return request;
}


// output dropdown list with archives listed
function fetchList()
{
    var url = 'archives/etailing_archives.php'; // script to output the list
    
    ajax.open('GET', url, true); // don't need to send any variables through url
    ajax.onreadystatechange = showList; // callback function to output list
    ajax.send(null);
    
}

// callback function
function showList()
{

    if(ajax.readyState == 4)
    {
        var response = ajax.responseText;
        document.getElementById("archive_list").innerHTML = response;
        
        fetchEtailing(); // get most current article
       
    }
    
}



function fetchEtailing()
{
	var issue;
	
	if(document.getElementById('IssID').value != '')
		issue = document.getElementById('IssID').value;
	else
		issue = 0;
	var url = 'archives/crn_arc_show.php?IssID=' + issue;
    
    ajax.open('GET', url, true);
    ajax.onreadystatechange = showEtailing;
    ajax.send(null);
	return false;
}

function showEtailing()
{
	 if(ajax.readyState == 4)
    {
        var response = ajax.responseText;
        //alert(response);
		
        document.getElementById("etailing_archives").innerHTML = response;
    }
}
