/* ENEWSLETTER ARCHIVE scripts */

//show the said element
function showIt(showMe) {
	showMe.style.display = 'block';
	showMe.style.visibility = 'visible';
}

//hides the said element
function hideIt(hideMe) {
	hideMe.style.display = 'none';
	hideMe.style.visibility = 'hidden';
}

function showArchive() {
	
	var showlink = document.getElementById('link_showArchive');
	var hidelink = document.getElementById('link_hideArchive');
	var divarchive = document.getElementById('divArchive');
	
	showlink.setAttribute("class", "off"); //For Most Browsers
	showlink.setAttribute("className", "off"); //For IE; harmless to other browsers.
	
	hidelink.setAttribute("class", "on"); 
	hidelink.setAttribute("className", "on"); 
	
	showIt(divarchive);
	
	showIt(hidelink);
	
	hideIt(showlink); 
}

function hideArchive() {
	
	var showlink = document.getElementById('link_showArchive');
	var hidelink = document.getElementById('link_hideArchive');
	var divarchive = document.getElementById('divArchive');
	
	showlink.setAttribute("class", "on"); //For Most Browsers
	showlink.setAttribute("className", "on"); //For IE; harmless to other browsers.
	
	hidelink.setAttribute("class", "off"); 
	hidelink.setAttribute("className", "off");
	
	hideIt(divarchive);
	
	hideIt(hidelink);
	//showLink.className += "on";
	showIt(showlink); 
	
}

//load page -- newsletter -- into div

function loadIssue(id, url, issue, issueNum){
	var xmlHttp;
	try {// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {// Internet Explorer

		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {

			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {

				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange = function(){

		if (xmlHttp.readyState == 4) {
			//Get the response from the server and extract the section that comes in the body section of the second html page avoid inserting the header part of the second page in your first page's element
			var respText = xmlHttp.responseText.split('<body link="#308ebf" alink="#415eb8" vlink="#b89c46">');
			//try this
			var news_css = "<style type='text/css'>table td {padding: 0;}</style>";
			elem.innerHTML = news_css+respText[1].split('</body>')[0];
			//turn this issue's link "on"
			newslinklist = document.getElementById("newsLinkList");
			for (i=0; i<newslinklist.childNodes.length; i++) {
				node = newslinklist.childNodes[i];
				if (node.nodeName=="LI") {
					//alert("we are now on: "+issueNum);
					var matchThis = "eNews_"+issueNum;
					if (node.id==matchThis){
						node.setAttribute("class", "on"); 
						node.setAttribute("className", "on");
					} else {
						node.setAttribute("class", "off"); 
						node.setAttribute("className", "off");
					}		
				}
			}
			
			//and update box heading
			info.innerHTML = "<h3>Clinton Foundation News: "+issue+"</h3>";
		}
	}

	var elem = document.getElementById(id);
	if (!elem) {
		alert('The element with the passed ID doesn\'t exists in your page');
		return;
	}

	var info = document.getElementById("info");
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


