/* Comment content:
Update: Premium Finance Web Marketing
Date: 12/01/2009
Update:
Date: 04/05/2010
loadXMLdoc - Function 
*/

function loadXMLdoc(xmlfile){
	//xmldoc;
	var xmlhttp;
    if(window.XMLHttpRequest){
        xmlhttp = new window.XMLHttpRequest();
    } else if(window.ActiveXObject){   	    
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
       
    xmlhttp.open("GET",xmlfile, false);
    xmlhttp.send("");
    return xmlhttp.responseXML;
}


function loadRecentNewsSideBar(year_id, post_id, xmldoc){
	var news_date, news_title, news_content, active, i, j, y, linkColor;
	//var xmldoc = loadXMLdoc('http://' + site_domain + '/' + xmlfile);
	var x = xmldoc.getElementsByTagName("year");
	
	if(year_id == "" && post_id == "" && x.length > 0){
		year_id = x[0].attributes.getNamedItem("id").value;
	}

	if(post_id != ""){
		var newsNode = xmldoc.getElementsByTagName("news");
		for(var k=0; k<newsNode.length; k++){
			if(newsNode[k].attributes.getNamedItem("id").value == post_id){
				year_id = newsNode[k].parentNode.attributes.getNamedItem("id").value;
			}
		}
	}

	var p = "";
	for(i=0; i<x.length; i++){
		news_year = x[i].attributes.getNamedItem("id").value;

		p = p + '<a href="RecentNews.asp?y=' + news_year + '"><font color="black" size="2"><b>' + news_year + '</b></font></a><br/><br/>';			
		if(news_year == year_id){
			y = x[i].childNodes;
			for(j=0; j<y.length; j++){
				if(y[j].nodeType == '1'){
					active = y[j].attributes.getNamedItem("active").value;
					news_id = y[j].attributes.getNamedItem("id").value;			
					news_date = y[j].attributes.getNamedItem("date").value;
					news_title = y[j].attributes.getNamedItem("title").value;
					news_link = y[j].attributes.getNamedItem("link").value;
					news_link_target = y[j].attributes.getNamedItem("link_target").value;					
	
					if(active == 1){
						if(news_id == post_id){ linkColor = "green"; } else { linkColor = "black"; }
						p = p + '<font color="' + linkColor + '" size="1">' + news_date + '</font><br>';
						if(news_link != ""){
							p = p + '<a href="' + news_link + '" target="' + news_link_target + '"><font color="' + linkColor +'" size="1">' + news_title + '</font></a><br /><br />';
						}else{											
							p = p + '<a href="RecentNews.asp?postid=' + news_id + '"><font color="' + linkColor +'" size="1">' + news_title + '</font></a><br><br>';			
						}
					}			
				}
			}
		}
	}	
	document.getElementById("recentNewsFocus1").innerHTML = p;
}

function loadDefaultRecentNewsSideBar(xmldoc){
	var news_date, news_title, news_content, active, i;
	//var xmldoc = loadXMLdoc('http://' + site_domain + '/' + xmlfile);
	var yearNodes = xmldoc.getElementsByTagName("year");
	var p = "";
	var yr_limit = yearNodes.length;
	if (yearNodes.length > 2){ yr_limit = 2; }

	for(i=0; i<yr_limit; i++){
		y = yearNodes[i].childNodes;
		for(j=0; j<y.length; j++){
			if(y[j].nodeType == '1'){
				active = y[j].attributes.getNamedItem("active").value;
				news_id = y[j].attributes.getNamedItem("id").value;			
				news_date = y[j].attributes.getNamedItem("date").value;
				news_title = y[j].attributes.getNamedItem("title").value;
				news_link = y[j].attributes.getNamedItem("link").value;
				news_link_target = y[j].attributes.getNamedItem("link_target").value;
				
				if(active == 1){
					linkColor = "black";
					p = p + '<font color="' + linkColor + '" size="1">' + news_date + '</font><br/>';
					if(news_link != ""){
						p = p + '<a href="' + news_link + '" target="' + news_link_target + '"><font color="' + linkColor +'" size="1">' + news_title + '</font></a><br /><br />';									
					}else{
						p = p + '<a href="RecentNews.asp?postid=' + news_id + '"><font color="' + linkColor +'" size="1">' + news_title + '</font></a><br /><br />';				
					}
				}			
			}
		}
	}
	document.getElementById("vmarquee").innerHTML = p;
}


function loadRecentNewsArticle(year_id, post_id, xmldoc){
	var news_date, news_title, news_content, active, i;
	
	//var xmldoc = loadXMLdoc('http://' + site_domain + '/' + xmlfile);
	var yearNodes = xmldoc.getElementsByTagName("year");
	
	if(year_id == "" && post_id == "" && yearNodes.length > 0){
		year_id = yearNodes[0].attributes.getNamedItem("id").value;
	}

	//Show all news articles
	if(year_id != ""){
		var p = '<table cellspacing="1" cellpadding="5" border="0" style="background-color: #FFFFFF">';
		for(i=0; i<yearNodes.length; i++){
			news_year = yearNodes[i].attributes.getNamedItem("id").value;
			
			p = p + '<tr valign="top" style="background-color: #42744E;"><td colspan="2"><a href="RecentNews.asp?y=' + news_year + '"><font color="#FFFFFF" size="3"><b>' + news_year + '</b></font></a></td></tr>';
			if(news_year == year_id){
				p = p + '<tr valign="top" style="background-color: #FFFFFF;"><td><font color="black" size="2"><b>Date</b></font></td><td><font color="black" size="2"><b>Title</b></font></td></tr>';			
				y = yearNodes[i].childNodes;
				for(j=0; j<y.length; j++){
					if(y[j].nodeType == '1'){
						active = y[j].attributes.getNamedItem("active").value;
						news_id = y[j].attributes.getNamedItem("id").value;			
						news_date = y[j].attributes.getNamedItem("date").value;
						news_title = y[j].attributes.getNamedItem("title").value;
						news_link = y[j].attributes.getNamedItem("link").value;
						news_link_target = y[j].attributes.getNamedItem("link_target").value;
		
						if(active == 1){
							linkColor = "black";
							p = p + '<tr valign="top" style="background-color: #FFFFFF;">';
							p = p + '<td><font color="' + linkColor + '" size="2">' + news_date + '</font>&nbsp;&nbsp;&nbsp;&nbsp;</td>';
							if(news_link != ""){
								p = p + '<td><a href="' + news_link + '" target="' + news_link_target + '"><font color="' + linkColor +'" size="2">' + news_title + '</font></a></td>';																
							}else{							
								p = p + '<td><a href="RecentNews.asp?postid=' + news_id + '"><font color="' + linkColor +'" size="2">' + news_title + '</font></a></td>';				
							}								
							p = p + '</tr>';
						}			
					}
				}
			}
		}
		p = p + '</table>';		
	}else if(post_id != ""){ //Show individual news article
		var newsNodes = xmldoc.getElementsByTagName("news");	
		for(i=0; i<newsNodes.length; i++){
			if (newsNodes[i].attributes.getNamedItem("id").value == post_id){
				active = newsNodes[i].attributes.getNamedItem("active").value;
				news_date = newsNodes[i].attributes.getNamedItem("ldate").value;
				news_title = newsNodes[i].attributes.getNamedItem("title").value;
				news_content = newsNodes[i].childNodes[0].data;
			}
		}
		if(active == 1){
			var p = '<table class="recentNewsContent">';
			p = p + '<tr><td align="center"><b>' + news_title + '</b></td></tr>';
			p = p + '<tr><td><b>' + news_date + '</b><br/><br/></td></tr>';
			p = p + '<tr><td><p>' + news_content + '</p></td></tr>';
		    p = p + '<tr><td>For more information, visit our website at <a target="_blank" href="http://www.hcc.com">www.hcc.com</a></td></tr>';
	    	p = p + '</table>';
		}else{
			p = "";
		}	
	}
	document.getElementById("newsContent").innerHTML = p;
}


