function checkError (error) {
	switch (error) {
		case 'File Not Found':
			alert ('We\'re sorry. The file you requested is no longer available for download.');
			break;
		}
	}
	
function showDownloadForm (loc_pixel) {
	var x = getX (loc_pixel);
	var r_marg = getX ('right_margin');
	if ((r_marg - x) < 300) x -= 75;
		else x += 20;
	var y = getY (loc_pixel) - 15;
	moveItSimple ('download_div', x, y);
	MM_showHideLayers('download_div','','show');
	}

function closeDownload () {
	MM_showHideLayers('download_div','','hide');
	}

function track_cb (new_id) {
	if (new_id == 0) {
		alert ('id mismatch - customer information update needed');
		// force cookie expiration to remove
		document.cookie = "ns_id=0; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/";
		var doc_id = document.getElementById('download_id').value;
		checkCookie (doc_id);
		}
	else {
		if (new_id != '_no_capture') setCookie (new_id);
		var tmp = document.getElementById('download_id').value;
//		alert ('calling getDownload');
		closeDownload ();
		document.location="/globals/get_download.php?id=" + tmp;
		}
	}

function track (id) {
	var d_id = document.getElementById('download_id').value;
	if (id == 0) {
		var first = document.getElementById ('first_name').value;
		var last = document.getElementById ('last_name').value;
		var email = document.getElementById ('email').value;
		if ((first == "") || (last == "")) alert ("You must specify a First and Last name for this download.");
			else if (email == "") alert ("You must specify a valid email address for this download.");
				else if (validate_email(email)) {
					x_track ('', first, last, email, d_id, track_cb);
					}
		}
	else {
//		alert (id);
		x_track (id, '', '', '', d_id, track_cb);
		}
	}

function trackDownload (doc_id, capture) {
//	alert ('trackDownload');
	document.getElementById('download_id').value = doc_id;
	if (capture) checkCookie (doc_id);
		else x_track ('', '_no_capture', '', '', doc_id, track_cb);
	}
	
function getCookieInfo (ns_cookie, find_entry) {
	var tmp = ns_cookie.split(';');
	var ret_val = '';
	for (var a=0; a<tmp.length; a++) {
		if (tmp[a].indexOf(find_entry) != -1) {
			var b = tmp[a].indexOf('=');
			ret_val = tmp[a].substr(b + 1)
			}
		}
	return (ret_val);
	}

function setCookie (id) {
	// set expiration for a year
	var year = new Date();
	year.setFullYear(year.getFullYear() + 1);
	document.cookie = "ns_id=" + id + "; expires=" + year.toGMTString() + "; path=/";
//	alert ('Cookie Set: ' + id);
	}
	
function checkCookie (doc_id) {
//	alert ('checkCookie');
	var ns_cookie = document.cookie;
// download_id is a hidden value in calling doc - it idebtifies the download
	document.getElementById('download_id').value = doc_id;
	if (ns_cookie) {
		var id = getCookieInfo (ns_cookie, 'ns_id');
		if (id) track (id);
			else showDownloadForm ("dl_" + doc_id);
		}
	else {
		showDownloadForm ("dl_" + doc_id);
		}
	}
