var d = new Date();
var today = d.getDate();
var imgPath = "http://www.hedgeco.net/public/images/logos/special/";
var logoImg = "hedgeco.png";
var logoAlt = "HedgeCo.net";

function setLogo(){
	(window.XMLHttpRequest) ? xmlhttp=new XMLHttpRequest() : xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

	xmlhttp.open("GET","http://www.hedgeco.net/public/images/logos/logo_schedule.xml",false);
	xmlhttp.send();
	xmlDoc=xmlhttp.responseXML;
	x=xmlDoc.getElementsByTagName("holidays");
	for(i=0; i<x[0].childNodes.length; i++){
		if (x[0].childNodes[i].nodeType==1){
			if(x[0].childNodes[i].getAttribute("m") == d.getMonth()){
				if(x[0].childNodes[i].getAttribute("float") == "true"){
					var tgtDay = x[0].childNodes[i].getAttribute("tD");
					var tgtNum = x[0].childNodes[i].getAttribute("tN");
					if(isFloatingHoliday(d.getFullYear(),d.getMonth(),Number(tgtDay),Number(tgtNum))){
						logoImg = x[0].childNodes[i].getAttribute("path");
						logoAlt = x[0].childNodes[i].getAttribute("alt");
					}
				}else{
					if(x[0].childNodes[i].getAttribute("d") == d.getDate()){
						logoImg = x[0].childNodes[i].getAttribute("path");
						logoAlt = x[0].childNodes[i].getAttribute("alt");
					}
				}
			}
		}
	}
	document.getElementById('hlogo').src = imgPath + logoImg;
	document.getElementById('hlogo').alt = logoAlt;
}
function isFloatingHoliday(nYear,nMonth,nTargetday,nTh){
/*	http://michaelthompson.org/technikos/holidays.php	*/
	nEarliestDate = 1 + 7 * (nTh - 1);
	d = new Date(nYear,nMonth,nEarliestDate);
	nWeekday = d.getDay();	
	( nTargetday==nWeekday ) ? nOffset = 0 : ( nTargetday<nWeekday ) ? nOffset = nTargetday + (7 - nWeekday) : nOffset = (nTargetday + (7 - nWeekday)) - 7;
	
	return((nEarliestDate + nOffset) == today);
}
setLogo();
