var xmlDoc;

function breakout(){
    if (window!= top)
      top.location.href=location.href
}

function reverse(s){
    return s.split("").reverse().join("");
}


function doemailaddy(){
            var name = reverse("retsaMbeW");
            var mydom = reverse("ku.oc.odn.cissalcdnalhgih");
            var myat = String.fromCharCode('?'.charCodeAt(0) + 1);
           
            document.write('<a class="link" href="mailto:' + name + myat + mydom + '?subject=Contact from Website">')
            document.write('Click here to email us')
            document.write('</a>')
}

function doemailaddysubscribe(){
            var name = reverse("retsaMbeW");
            var mydom = reverse("ku.oc.odn.cissalcdnalhgih");
            var myat = String.fromCharCode('?'.charCodeAt(0) + 1);
          
            document.write("<a class='link' href='mailto:" + name + myat + mydom + "?subject=Subscribe to Classic Scene&body=subscribe'>")
            document.write('here')
            document.write('</a>')
}

function doemailaddydid(){
            var name = reverse("retsaMbeW");
            var mydom = reverse("ku.oc.odn.cissalcdnalhgih");
            var myat = String.fromCharCode('?'.charCodeAt(0) + 1);
          
            document.write("<a class='link' href='mailto:" + name + myat + mydom + "?subject=Entry for DID 2011&body=Name:<p>Address:<p>Vehicle Make:<br>Vehicle Model:<br>Vehicle Year:'>")
            document.write('here')
            document.write('</a>')
}

function header(){
            document.write('<script type="text/javascript"> breakout(); </script>');
            document.write('<a name="top"></a>');
            document.write('<table background="page/header_title2.jpg" align="center" width="1000" cellpadding="0" cellspacing="0">');
            document.write('  <tr>');
            document.write('    <td width="100" align="center" valign="bottom"></td>');
            document.write('    <td height="133" align="center" valign="bottom"><font type="Arial">');
            document.write('      <script type="text/javascript"> doemailaddy(); </script>');
            document.write('    </td>');
            document.write('    <td width="100" align="center" valign="bottom"></td>');
            document.write('  </tr>');
            document.write('</table>');
}
 
function footer(){
            document.write('<table align="center" width="1000" cellpadding="0" cellspacing="0">');
            document.write('<tr><td bgcolor="white" align="center"><hr color="red" /><font size="1">© Highland Classic Motor Club, 2011</font></td></tr>');
            document.write('</table>');
}
 
function meta(){
            document.write('<title>Highland Classic Motor Club</title>');
            document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
            document.write('<meta name="description" content="Website of the Highland Classic Motor Club">');
            document.write('<meta name="keywords" content="Highland Classic Motor Club, HCMC, Classic Cars, Highland, Classic, Cars, Car, Highlands, Scotland, Inverness, Drive It Day, drive it day">');
            document.write('<meta name="author" content="HCMC 2009">');
            document.write('<meta name="generator" content="notepad">');
}
 
function featurecar(){
            var today = new Date();
            var day = today.getDate();
            var index = (day % 14)+1;
                                    var anchor;
            var pic;
                                    anchor='docs/mamc' + index + '.pdf';
                                    pic = 'images/mamc/mamc' + index + '.jpg';
                                   
            document.write('<td class="border" valign="top">');
            document.write('  <table width="350" align="center" cellpadding="5" cellspacing="0">');
            document.write('    <tr>');
            document.write('      <td align="center" >');
            document.write('        <p class="medium">');
            document.write('          <b>Club Cars</b> ');
            document.write('        </p>');
            document.write('      </td> ');
            document.write('      <td align="center" > ');
            document.write('        <a target="_blank" href="' + anchor + '">');
            document.write('          <img height="150" alt="" src="' + pic + '" />');
            document.write('        </a> ');
            document.write('      </td> ');
            document.write('    </tr>');
            document.write('  </table>');
            document.write('</td> ');
 
} 

function driveitday(){
            var today = new Date();
            var day = today.getDate();
            var index = (day % 14)+1;
            var anchor;
            var pic;
			anchor='did.htm';
			pic = 'images/did/fbhvc.jpg';
		   
            document.write('<td class="border" valign="top">');
            document.write('  <table width="350" align="center" cellpadding="5" cellspacing="0">');
            document.write('    <tr>');
            document.write('      <td align="center" >');
            document.write('        <p class="medium">');
            document.write('          <b>Drive It Day 2011</b> ');
            document.write('        </p>');
            document.write('        <p class="medium">');
            document.write('          <b>April 17th </b> ');
            document.write('        </p>');
            document.write('        <p class="medium">');
            document.write('          (Click the logo) ');
            document.write('        </p>');
            document.write('      </td> ');
            document.write('      <td align="center" > ');
            document.write('        <a href="' + anchor + '">');
            document.write('          <img height="150" alt="" src="' + pic + '" />');
            document.write('        </a> ');
            document.write('      </td> ');
            document.write('    </tr>');
            document.write('  </table>');
            document.write('</td> ');
 
} 

function redirect(){
	var x = GetBannerText();
	if (x != "")
		document.write('<meta http-equiv="refresh" content="0;url=urgent.htm">');
	else
		document.write('<meta http-equiv="refresh" content="0;url=page1.htm">');
}

function redirectnews(){
	var x = GetNewsletterURL();
	if (x != "")
		document.write('<meta http-equiv="refresh" content="0;url=' + x + '">');
	else
		document.write('<meta http-equiv="refresh" content="0;url=page1.htm">');
}


function GetBannerText(){
	//load XML steering file
	LoadXML();

	var NodeList = xmlDoc.getElementsByTagName("banner");
    if (NodeList.length > 0)
		return (NodeList[0].childNodes[0].nodeValue);
	else
		return ("");
}

function ShowBanner(){
	var x = GetBannerText();
	if (x != "")
		document.write(x);
}


function GetNewsletterText(){
	//load XML steering file
	LoadXML();

	//XMLdOC = loadXMLDoc("config.xml");
	//alert("loaded");
	var NodeList = xmlDoc.getElementsByTagName("newsletter");
    if (NodeList.length > 0)
    {
		var x = NodeList[0].getElementsByTagName("text")[0];
		var y=x.childNodes[0];
		//alert(y.nodeValue);
		return(y.nodeValue);
	}
	return("");
}

function ShowNewsletterText(){
	
	var x = GetNewsletterText();
	if (x != "")
		document.write(x);
}

function GetNewsletterURL(){
	//load XML steering file
	LoadXML();
	var NodeList = xmlDoc.getElementsByTagName("newsletter");
    if (NodeList.length > 0)
    {
		var x = NodeList[0].getElementsByTagName("url")[0];
		var y = getXML(x);
		return(y);
	}
}

function ShowNewsletterURL(){
	//load XML steering file
	LoadXML();

	var NodeList = xmlDoc.getElementsByTagName("newsletter");
    if (NodeList.length > 0)
    {
		var x = NodeList[0].getElementsByTagName("piclink")[0];
		var y = getXML(x);
		document.write(y);
	}
}

function getXML(x){
	var ret="";
	var sAttrName;
	var sAttrValue;
	var i;
	var j;
	
	if (x.hasChildNodes())
	{
		for (i=0; i < x.childNodes.length; i++)
		{
			//alert("found child " + i);
			//alert("node type:" + x.childNodes[i].nodeType);
			if (x.childNodes[i].nodeType != 1) //! ELEMENT_NODE
			{
				//alert("found !element: " + x.childNodes[i].nodeValue);
				ret = x.childNodes[i].nodeValue;
			}
			else
			{
				//alert("found element: " + x.childNodes[i].tagName);
				ret = "<" + x.childNodes[i].tagName;
			    for (j=0; j < x.childNodes[i].attributes.length; j++)
				{
					sAttrName = x.childNodes[i].attributes[j].nodeName;
					sAttrValue = x.childNodes[i].attributes[j].nodeValue;
					ret = ret + " " + sAttrName + '="' + sAttrValue + '"';
					//alert("ret now:" + ret);
				}
				ret = ret + ">";
				ret = ret + getXML(x.childNodes[i]);
				ret = ret + "</" + x.childNodes[i].tagName + ">";
			}
		}
	}
	return(ret);
}

function loadXMLDoc(dname) //unused now
{
	if (window.XMLHttpRequest)
	{
		xhttp=new XMLHttpRequest();
	}
	else
	{
		xhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xhttp.open("GET",dname,false);
	xhttp.send();
	return xhttp.responseXML;
} 

function LoadXML(){
	if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		while (xmlDoc.readyState != 4) {} // readyState will be set to 4 when the document is loaded
		xmlDoc.load("config.xml");
		return;
	}

	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("","",null);
		xmlDoc.async=false;
		var isLoaded = xmlDoc.load("config.xml");
		while (isLoaded ==  false)
		{
		}
		return;
	}
}

function GetMeetingText(){
	var sThisDate;
	var sNow = new Date();
	var sToday = sNow.getFullYear() + pad2((sNow.getMonth()+1)) + pad2(sNow.getDate());

	//load XML steering file
	LoadXML();

	var NodeList = xmlDoc.getElementsByTagName("meeting");
    if (NodeList.length > 0)
    {
		//loop through the steering file looking for a date in the future
	    for (i=0; i < NodeList.length; i++){
			sThisDate = NodeList[i].getAttribute("date")
			if (sThisDate >= sToday)
			{
				var x = NodeList[i].getElementsByTagName("text")[0];
				var y=x.childNodes[0];
				//alert(y.nodeValue);
				document.write(y.nodeValue);
				break;
			}
			
		}
	}
}


function GetMeetingURL(){
	var sThisDate;
	var sNow = new Date();
	var sToday = sNow.getFullYear() + pad2((sNow.getMonth()+1)) + pad2(sNow.getDate());

	//load XML steering file
	LoadXML();

	var NodeList = xmlDoc.getElementsByTagName("meeting");
    if (NodeList.length > 0)
    {
		//loop through the steering file looking for a date in the future
	    for (i=0; i < NodeList.length; i++){
			sThisDate = NodeList[i].getAttribute("date")
			if (sThisDate >= sToday)
			{
				var x = NodeList[i].getElementsByTagName("url")[0];
				var y = getXML(x);
				//alert("got URL as: " + y);
				document.write(y);
				break;
			}
		}
	}
}

function pad2(number) {
     return (number < 10 ? '0' : '') + number
}

