﻿function AddOASQueryKeyValues(key, value) 
{
    if (OAS_query == "?") 
    {
        OAS_query += key + "=" + value;
    }
    else 
    {
        OAS_query += "&" + key + "=" + value;
    } 
}

function OAS_Load() 
{
    if (OAD_enabled = true) 
    {
        // Build Array of all Advert positions
        var advertContainers = $(".cw_oas_ad");

        //Iterate thru all adverts
        advertContainers.each(function(container)
        {
            //Get the advert position name.
            var OAS_position = $(this).attr("id").replace("oas_", "");

            //Check if it already exists on the page
            if (OAS_positionlist.indexOf(OAS_position + ",") < 0)
            {
                OAS_positionlist = OAS_positionlist + OAS_position + ",";
            }
            else
            {
                //Cannot have the duplicate advert positions on the page. Remove it.
                $("#oas_" + OAS_position + "_container").remove();
            }
        });

        //remove trailing ,
        if (OAS_positionlist.length > 0)
        {
            OAS_positionlist = OAS_positionlist.slice(0, OAS_positionlist.length - 1);
        }

        //inject iframe
        advertContainers.each(function(container) {
            var OAS_position = $(this).attr("id").replace("oas_", "");
            $(this).append("<IFRAME src='" + OAS_url + "adstream_sx.ads/" + OAS_pagehost + "/" + OAS_pagepath + "/1" + OAS_rns + "@" + OAS_positionlist + "!" + OAS_position + OAS_query + "' marginHeight='0' allowtransparency='true' marginWidth='0' scrolling='no' style='height:100%; width:100%; z-index=3001;' frameborder='0'></IFRAME>");
        });
    }
}
