﻿// JScript File
//used in div_content template for hide/show function
function unhide(divID) {
    var item = document.getElementById(divID);
    if (item) {
        item.className = (item.className == 'hiddendiv') ? 'unhiddendiv' : 'hiddendiv';
    }
    var item2 = document.getElementById(divID+'Question');
    if (item2) {
        item2.className = (item2.className == 'hiddendiv') ? 'unhiddendiv' : 'hiddendiv';
    }
}
//Used for Christmas Countdown

function zeroPad(num, places) {
    var zero = places - num.toString().length + 1;
    return Array(+(zero > 0 && zero)).join("0") + num;
}

function GettheDate() {
    var today = new Date();
    var daynow = today.getDate();
    var monthnow = (today.getMonth() + 1);
    //document.write(zeroPad(daynow, 2)); // "05"
    //document.write("<br />")
    return (zeroPad(daynow, 2) + "-" + monthnow + "-2011");
}

function Start(id) {

    var divid = "div" + id;
    var x, a0, b0, y0, c0, d0, f0, g0, k0, l0,a2,b2 = "";
    var txtDate = "";
    var txtToday = "";
    var imgPromo = "";

    txtToday = GettheDate();
    document.getElementById('btn').style.display = "none";
    document.getElementById(divid).style.display = "block";
    var xmlDoc = loadXMLDoc('/Images/files/AGAChristmas.xml');

    x = xmlDoc.getElementsByTagName('promotion');
    for (i = 0; i < x.length; i++) {
        //	txtDate = x[i].getAttributeNode('date').nodeValue;
        var txtDate = x[i].getAttribute('date');


        if (txtDate == txtToday) {
            //document.write(txtToday);
            //document.write("<br />")

            a0 = xmlDoc.getElementsByTagName('title')[i]
            b0 = a0.childNodes[0];
            //image
            a2 = xmlDoc.getElementsByTagName('image')[i]
            if (a2 != null) {

                b2 = a2.childNodes[0];
                imgPromo = "<img src=\"" + b2.nodeValue + "\" width=\"250\" height=\"250\" border=\"0\" alt=\"" + b0.nodeValue + "\" \>";
                }
            //	document.write(b.nodeValue);
            c0 = xmlDoc.getElementsByTagName('url')[i]
            d0 = c0.childNodes[0];
            f0 = xmlDoc.getElementsByTagName('rrp')[i]
            g0 = f0.childNodes[0];
            k0 = xmlDoc.getElementsByTagName('sale')[i]
            l0 = k0.childNodes[0];
            //document.write('<a href="'+d0.nodeValue+'">'+b0.nodeValue+'</a>');

            var txtLink = document.getElementById('myLink');
            txtLink.href = d0.nodeValue;
            txtLink.innerHTML = b0.nodeValue;
         
            var txtDesc = txtLink.innerHTML + " 20% OFF - Was: £" + g0.nodeValue + ", Now: £" + l0.nodeValue;
            txtLink.innerHTML = imgPromo + "<br />" + txtDesc;
            txtLink.title = txtDesc;

        }
        //document.write("<br />");
    }

    //document.write(divid + " finished");
    document.close();
}


function loadXMLDoc(dname) {
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    }
    else {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET", dname, false);
    xhttp.send();

    return xhttp.responseXML;
} 

