function Download(download_link) {
	document.getElementById('download_link').value=download_link;
	
	
	var first_name = document.getElementById('first_name').value;
	var last_name = document.getElementById('last_name').value;
	var email_address = document.getElementById('email_address').value;
	var the_form = document.getElementById('form2');
	if (first_name!='' && last_name!='' && email_address !='') {
		GetFile();
		return;
	}	
	
	
	
	var theDiv = document.getElementById('DownloadPane');
	theDiv.style.display='block';
	document.getElementById('first_name').focus();
	

	


}

function CancelDownload () {
	var theDiv = document.getElementById('DownloadPane');
	document.getElementById('download_link').value='';
	theDiv.style.display='none';
}

function GetFile() {
	download_link = document.getElementById('download_link').value;
	var email_address = document.getElementById('email_address').value;
	var first_name =  document.getElementById('first_name').value;
	var last_name =  document.getElementById('last_name').value;	
	
	if (first_name=='' || last_name=='' || email_address == '') {
		alert('Enter your first name, last name and email address. Thank you!');
		document.getElementById('first_name').focus();
		return
	}
	
	else
	{	
	
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', 'get_download.php', true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
     	var theDiv = document.getElementById('DownloadPane');
			theDiv.style.display='none'; 
		
  	//window.location = 'download.php?file=' + self.xmlHttpReq.responseText;
            window.location = self.xmlHttpReq.responseText;
            
            //alert(self.xmlHttpReq.responseText);
            //updatepage(self.xmlHttpReq.responseText);
        }
    }


    self.xmlHttpReq.send(getquerystring());
    
	}
}


function getquerystring() {
    
    qstr = 'first_name=' + document.getElementById('first_name').value + 
    '&last_name=' + document.getElementById('last_name').value + '&email_address='+
    document.getElementById('email_address').value + '&ip_address=' + document.getElementById('ip_address').value + '&download_link=' + document.getElementById('download_link').value
    ;
	
	return qstr;
}

