﻿var myReq = new XMLHttpRequest();

function getProductList(listName,divID) {
        var script = document.createElement("script");
        script.setAttribute("src", "http://anywhereproducts.yourecommerce.com/Default.aspx?ln="+listName+"&dv="+divID+"&mid=SLinke1055");
        script.setAttribute("type", "text/javascript");
        document.body.appendChild(script);

}

function writeProductList() {
    if (myReq.readyState == 4) // Completed operation
    {
        var stringResult = myReq.responseXML.getElementsByTagName("string");
        var index = 0;
        while(index+1 < stringResult.length) {
            document.getElementById(myReq.responseXML.getElementsByTagName("string")[index+1].firstChild.nodeValue).innerHTML = myReq.responseXML.getElementsByTagName("string")[index].firstChild.nodeValue;
            index = index + 2;
        }
        
    }
}

function anywhereProducts(result) {

    var obj = result;
    for (var key in obj) {
        var attrName = key;
        var attrValue = obj[key];
        var t = document.createElement('div');
        t.innerHTML = attrValue;
        if (document.getElementById(attrName) != null) {
            if (document.getElementById(attrName).firstChild)
                document.getElementById(attrName).removeChild(document.getElementById(attrName).firstChild);
            document.getElementById(attrName).appendChild(t);
        }
    }
}

