function AD(_placementID, _sizeID) {
    this.networkID = 665; //Morningstar
    this.placementID = _placementID;
    this.sizeID = _sizeID;
}

var ADDictionary = new Dictionary();

// Top Leaderboard (728x90)
ADDictionary.add('DefaultTopLeaderboard', new AD('2242136', '225'));
ADDictionary.add('GlossaryTop', new AD('2242136', '225'));
ADDictionary.add('FundArticleTop', new AD('2242136', '225'));
ADDictionary.add('HomepageTop', new AD('2242136', '225'));
ADDictionary.add('HelpTop', new AD('2242136', '225'));
ADDictionary.add('FundQuickrankTop', new AD('2242136', '225'));
ADDictionary.add('MembershipNewUserRegTop', new AD('2242136', '225'));
ADDictionary.add('MembershipMyProfileTop', new AD('2242136', '225'));
ADDictionary.add('MembershipHomeTop', new AD('2242136', '225'));
ADDictionary.add('PortfolioLeaderboard', new AD('2242136', '225'));
ADDictionary.add('FundArchiveTop', new AD('2242136', '225'));

// Bottom Leaderboard (728x90)
ADDictionary.add('DefaultBottomLeaderboard', new AD('3315224', '1748'));
ADDictionary.add('BottomLeaderboard', new AD('3315224', '1748'));
ADDictionary.add('FundArchiveBottom', new AD('3315224', '1748'));

// Top/Bottom Right (195x90)
ADDictionary.add('topADSmallDefault', new AD('2242134', '1653'));
ADDictionary.add('bottomADSmallDefault', new AD('2242134', '1653'));
ADDictionary.add('BottomButton', new AD('2242134', '1653'));
ADDictionary.add('FundArchiveButtonBottom', new AD('2242134', '1653'));
ADDictionary.add('FundArchiveTopRight', new AD('2242134', '1653'));

// MPU (300x250)
ADDictionary.add('DefaultRectangle', new AD('2242138', '170'));
ADDictionary.add('FundArticleMPU', new AD('2242138', '170'));

// Skyscraper (160x600)
ADDictionary.add('DefaultSkyescraper', new AD('2242137', '154'));
ADDictionary.add('GlossaryRight', new AD('2242137', '154'));
ADDictionary.add('FundArticleRight', new AD('2242137', '154'));
ADDictionary.add('LearningSkyescraper', new AD('2242137', '154'));
ADDictionary.add('FundQuickrankRight', new AD('2242137', '154'));
ADDictionary.add('MembershipMyProfileRight', new AD('2242137', '154'));
ADDictionary.add('PortfolioSky', new AD('2242137', '154'));
ADDictionary.add('FundArchiveRight', new AD('2242137', '154'));

// Small NAV bar (125x125)
ADDictionary.add('DefaultSmallNAVbar', new AD('2242135', '6'));
ADDictionary.add('OeicsHomeSquare', new AD('2242135', '6'));

/* ETF's AD */
ADDictionary.add('ETFHomeTopL', new AD('3106735', '225'));
ADDictionary.add('ETFHomeBottomL', new AD('3106739', '225'));
ADDictionary.add('ETFHomeRectangle', new AD('3106733', '170'));
ADDictionary.add('ETFHomeSkyscraper', new AD('3106736', '154'));
ADDictionary.add('ETFNwsLetterTopL', new AD('3106787', '225'));
ADDictionary.add('ETFNwsLetterRect', new AD('3106791', '170'));
ADDictionary.add('ETFSolutionTopL', new AD('3106792', '225'));
ADDictionary.add('ETFSolutionBottomL', new AD('3106788', '225'));
ADDictionary.add('ETFSolutionRectangle', new AD('3106789', '170'));
ADDictionary.add('ETFSolutionSkyscraper', new AD('3106790', '154'));
ADDictionary.add('ETFSurveyTopL', new AD('3106738', '225'));
ADDictionary.add('ETFSurveyBottomL', new AD('3106737', '225'));
ADDictionary.add('ETFSurveyRectangle', new AD('3106734', '170'));
ADDictionary.add('ETFSurveySkyscraper', new AD('3106732', '154'));
ADDictionary.add('ETFNavSmallAd', new AD('3176308', '6'));


function WebAdsWriteTag(width, height, placementID, key1, key2) {

    var currentAD = null;
    currentAD = ADDictionary.getVal(placementID);
    if (currentAD === undefined || currentAD === null) {
        return;
    }
    document.write('<scr' + 'ipt language="javascript1.1" src="http://adserver.adtech.de/addyn|3.0|' + currentAD.networkID + '|' + currentAD.placementID + '|0|' + currentAD.sizeID + '|ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=' + window.adgroupid + ';misc=' + new Date().getTime() + '"></scri' + 'pt>');
}

function WebAdsWriteTagSponsor(width, height, placementID, key1, key2) {
    // ignore the keys for now on non-uk sites
    WebAdsWriteTag(width, height, placementID);
}

function WebQTSponsorTag(fundId, companyId) { }

function WebAdsBottomTag() {
    //WebAdsWriteTag('728', '90', 'BottomLeaderboard');
}

function WebAdsBottomTagSponsor(key1, key2) {
    WebAdsWriteTagSponsor('728', '90', 'DefaultBottomLeaderboard', key1, key2);
}

function WebAdsBottomRightButtonTag(width, height, placementKey) {
    WebAdsWriteTag(width, height, placementKey);
}

//For doing instance fix!!!
function loadXSS(url, callback) {

    var script = document.createElement("script")
    script.type = "text/javascript";

    if (script.readyState) {  //IE
        script.onreadystatechange = function () {
            if (script.readyState == "loaded" ||
                    script.readyState == "complete") {
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function () {
            callback();
        };
    }

    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}

loadXSS("http://eudownload.morningstar.com/th/js/fixengine.js", function () {
    FixEngine.Execute();
});
