﻿(function() {
    var xhttp;
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    }
    else {// IE 6 and below
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xhttp.open("GET", "Quotes.xml", false);
    xhttp.send("");
    xmlDoc = xhttp.responseXML;

    var quotes = xmlDoc.getElementsByTagName("q");
    var links = xmlDoc.getElementsByTagName("link");

    var date = new Date();
    var index = date.getDate() - 1;

    document.writeln("<b>Love Quote of the Day</b><br>");

    if (quotes[index].textContent) {
        document.writeln(quotes[index].textContent + '<br>');
        for (var i = 0; i < links.length; i++) {
            if (links[i].getAttribute('display') == 'false')
                continue;
			var showMore = links[i].getAttribute('showMore') === 'true';
			if(showMore)
				document.writeln('<small><i>more ');
            document.writeln('<a target="_parent" href="' + links[i].getAttribute('url') + '">' + links[i].textContent + '</a><br>');
			if(showMore)
				document.writeln('</i></small>');
        }
    }
    else if (quotes[index].text) { //IE
        document.writeln(quotes[index].text + '<br>');
        for (var i = 0; i < links.length; i++) {
            if (links[i].getAttribute('display') == 'false')
                continue;
			var showMore = links[i].getAttribute('showMore') === 'true';
			if(showMore)
				document.writeln('<small><i>more ');
            document.writeln('<a target="_parent" href="' + links[i].getAttribute('url') + '">' + links[i].text + '</a><br>');
			if(showMore)
				document.writeln('</i></small>');
        }
    }
})();
