﻿// JScript File
function renderAd(size, tile, dcsrc) {
	// parse parameters
	//...
	// width and height of each iframe is found by splitting size: { 728x90, 208x90, 1000x90 } in turn
	var width = 0
	var height = 0
	
	var sizes;
	var heights;
	var widths;
	
	var newsize = size.replace('COMMA',',').replace('FHB', '');
	
	sizes = newsize.split(',');
	

    for (var i=0; i<sizes.length; i++){
        var s = sizes[i].split('x');
		
        var w = s[0];
        var h = s[1];

        if (w > width){
	        width = w;	
        }
		
        if (h > height){
	        height = h;	
        }
    }
	
	var src = '/includes/advertising.html?dcsrc=' + escape(dcsrc); 
	var divID = "outterDCkAd" + size + tile ;
	document.write('<div id="' + divID + '"></div>');                          // Note: the src is from the same domain
	var newIframe = '<iframe allowtransparency="true" id="innerAd' + size + tile + '" src="' + src + '" border="0" frameborder="0" width="' + width + '" height="' + height + '" scrolling="no" style="vertical-align:middle;"></iframe>';
	document.getElementById(divID).innerHTML = newIframe;
}

function adRefresh(size, tile) {
	var ord = Math.floor(Math.random()*1E16);  //random number generated for doubleclick ad calls

    //replace the ord to ensure the original ad isn't cached
	var fif = document.getElementById('innerAd' + size + tile);
    srce = fif.src
	ordindx = srce.indexOf("ord");
	qindx = srce.indexOf("?",ordindx);
	
	oldord = srce.substring(ordindx,qindx);
	neword = 'ord=' + ord;
	
	srce.replace(oldord,neword);
	
	fif.src = srce;
}
