﻿// Constructor -- pass a REST request URL to the constructor
//
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "windows-1255");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    //bthis.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}



if (DG_bannerTypes != null && DG_bannerTypes.length >0 &&  firstView == null )
{
var rndNum=Math.floor(Math.random()*999999);
    var firstView=1;
    if (dcHeadline == null)
    dcHeadline ='';
    if (dcChannel == null)
    dcChannel ='';
    function GetDG_Ban(jsonData) {
       var i,j;
       for (j =0 ; j<DG_bannerTypes.length;j++) 
       { 
          for (i = 1 ; i<=eval('jsonData.bannType'+DG_bannerTypes[j]+'.length');i++) 
          { 
            var obj = document.getElementById("dgBan_t"+(DG_bannerTypes[j])+"x"+i);
            if (obj != null)
             obj.innerHTML= eval('jsonData.bannType'+DG_bannerTypes[j])[i-1].html.replace(/#link#/g,'http://banrest.d-group.co.il/click.aspx?p=' + i +escape('&id='+eval("jsonData.bannType"+DG_bannerTypes[j])[i-1].ID + '&dcheadline='+ dcHeadline + '&dcChannel='+dcChannel));
          }
        }
    }
    var DG_obj=new JSONscriptRequest("http://banrest.d-group.co.il/t.aspx?bannerTypes="+DG_bannerTypes+"&amounts=" + DG_bannerAmounts+"&dcheadline="+dcHeadline + "&dcchannel="+ dcChannel);
    DG_obj.buildScriptTag(); 
    DG_obj.addScriptTag(); 
}
