window.onload = function () {
    var req = 'http://construct.md/ajaxcontrol/remotebaner/' + getclientid();
    bObj = new JSONscriptRequest(req);
    bObj.buildScriptTag();
    bObj.addScriptTag();
}

function getGeo(jsonData) {
    addbaner("http://construct.md/Image.ashx?type=91&imageid=" + jsonData.ResultSet.Result[0].BannerId, jsonData.ResultSet.Result[0].AltText, jsonData.ResultSet.Result[0].Refrence);
    bObj.removeScriptTag();
}

function getclientid() {
    var el = getElementsByName_iefix("div", "construct_md");
    var v;
    if (el != "") {
        v = el[0].getAttribute('id');
    } else {
        el = document.getElementById("construct_md");
        v = el.getAttribute("title");
    }
    return v;
}

function addbaner(imgpath, imgalt, reference) {
    if (document.createTextNode) {

        //create the anchor node
        myA = document.createElement("a");
        myA.setAttribute("href", reference);

        //create the image node
        myImg = document.createElement("img");
        myImg.setAttribute("src", imgpath);
        myImg.setAttribute("width", "88");
        myImg.setAttribute("height", "31");
        myImg.setAttribute("border", "0");
        myImg.setAttribute("alt", imgalt);

        // Appends the image node to the anchor
        myA.appendChild(myImg);
        var el = getElementsByName_iefix("div", "construct_md")
        if (el != "") {
            el[0].appendChild(myA);
        } else {
            el = document.getElementById("construct_md");
            el.appendChild(myA);
        }
    }
}

function getElementsByName_iefix(tag, name) {
    var elem = document.getElementsByTagName(tag);
    var arr = new Array();
    for (i = 0, iarr = 0; i < elem.length; i++) {
        att = elem[i].getAttribute("name");
        if (att == name) {
            arr[iarr] = elem[i];
            iarr++;
        }
    }
    return arr;
}

// Constructor -- pass a REST request URL to the constructor
function JSONscriptRequest(fullUrl) {
    this.fullUrl = fullUrl;
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
JSONscriptRequest.prototype.buildScriptTag = function () {
    this.scriptObj = document.createElement("script");
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl); // + this.noCacheIE
    this.scriptObj.setAttribute("id", this.scriptId);
}

JSONscriptRequest.prototype.removeScriptTag = function () {
    this.headLoc.removeChild(this.scriptObj);
}

JSONscriptRequest.prototype.addScriptTag = function () {
    this.headLoc.appendChild(this.scriptObj);
}