﻿// daincb --> DynaAds Include Banner
plazoo_daincb = function() {

	this.bLayers = Array();
	this.baseURL = "http://www.plazoo.com/external/pages/getbcxml.asp";
	this.Keyword = "";
	this.Language = "";

	this.init = function() {
		var i = 0;
		var documentLayers;
		
		this.Keyword = window.plazoo_daincb_kw;
		this.Language = (window.plazoo_daincb_lang?window.plazoo_daincb_lang:"EN");
		
		documentLayers = document.getElementsByTagName("div");
		for (i=0; i < documentLayers.length;i++) {
			if (documentLayers[i] && documentLayers[i].getAttribute("btype")) {
				if (documentLayers[i].getAttribute("pbchangenodes")) {
					this.bLayers[this.bLayers.length] = {i: documentLayers[i].id, type: documentLayers[i].getAttribute("btype"), changenodes: documentLayers[i].getAttribute("pbchangenodes") };
				}
				else {
					this.bLayers[this.bLayers.length] = {i: documentLayers[i].id, type: documentLayers[i].getAttribute("btype"), changenodes: "" };
				}
			}
		}
		
		for (i = 0; i<this.bLayers.length; i++) {
			if (this.Keyword != "") { this.GetImage(this.bLayers[i]); }
			else { this.printImage(null, this.bLayers[i].i); }
		}
	}
	
	this.GetImage = function(objLayer) {
		var objRequest = null;
		var strUrl = this.baseURL;
		
		strUrl += "?l=" + this.Language;
		strUrl += "&kw=" + this.Keyword;
		strUrl += "&t=" + objLayer.type;
		strUrl += "&ts=" + Date.UTC(new Date());
		
		eval("objRequest = document.plazoo_" + objLayer.i + ";");
		var objAJAX = new plazoo_daincb_AJAX(objLayer.i, strUrl);
		objAJAX.getUrl(this);
	}
	
	this.HTML_Code = function(objXML) {
		
		var strRetVal = "";
		var objCampaign;
		
		if (objXML) {
			objCampaign = objXML.getElementsByTagName("campaign");
			
			if (objCampaign && objCampaign.length > 0) {
				
				if (objCampaign[0].getAttribute("t") == 'div') {
					strRetVal = '<div style="position:relative;  border: 1px solid #215A9C; overflow: hidden; width:' + (parseInt(objCampaign[0].getAttribute("w")) + 1) + 'px; height:' + (parseInt(objCampaign[0].getAttribute("h")) + 1) + 'px">';
					strRetVal += '<a href="http://www.dyna-ads.com/dacc.asp?bcid=' + objCampaign[0].getAttribute("i") + '&bid=' + objCampaign[0].getAttribute("tbbid") + '" target="_blank" rel="nofollow">';
					strRetVal += '<img src="http://www.dyna-ads.com/dacv.asp?bcid=' + objCampaign[0].getAttribute("i") + '&what=clientid:' + objCampaign[0].getAttribute("tbclid") + '&campaignid:' + objCampaign[0].getAttribute("tbcaid") + '&source=frontpage" border="0" alt="">';
					strRetVal += '</a>';
					strRetVal += '</div>';
				}
				else {
					strRetVal = '<iframe scrolling="no" frameborder="0"  src="http://' + objCampaign[0].getElementsByTagName("url")[0].childNodes[0].nodeValue + '" style="position:absolute;  border: 1px solid #215A9C; width:' + (parseInt(objCampaign[0].getAttribute("w")) + 1) + 'px; height:' + (parseInt(objCampaign[0].getAttribute("h")) + 1) + 'px" height="' + (parseInt(objCampaign[0].getAttribute("h")) + 1) + '" width="' + (parseInt(objCampaign[0].getAttribute("w")) + 1) + '">';
					strRetVal += '</iframe>';
				}
			}
		}
		return  strRetVal;
	}
	
	this.printImage = function(objXML, sLayerId) {
		var objLayer = this.GetObjectById(sLayerId);
		var arrChangeNodes, tmpNode, i;
		
		var strHtml = this.HTML_Code(objXML);
		var parentNode, objNode;
		if (strHtml != "") {
			if (document.getElementById(objLayer.i)) {
				var oCampaign = objXML.getElementsByTagName("campaign");
				
				document.getElementById(objLayer.i).innerHTML = strHtml;
				document.getElementById(objLayer.i).style.width = oCampaign[0].getAttribute("w") + "px";
				document.getElementById(objLayer.i).style.height = oCampaign[0].getAttribute("h") + "px";
			}
		}
		else {
			if (document.getElementById(objLayer.i)) {
				objNode = document.getElementById(objLayer.i);
				parentNode = objNode.parentNode;
				if (parentNode) {
					parentNode.removeChild(objNode);
				}
				if (objLayer.changenodes != "") {
					arrChangeNodes = objLayer.changenodes.split(",");
					for (i=0;i<arrChangeNodes.length;i++) {
						this.ChangeNode(arrChangeNodes[i]);
					}
				}
			}
		}
	}
	
	this.GetObjectById = function(objectId) {
		var obj = document.getElementById(objectId);
		var retVal = null;
		
		if (obj && obj.getAttribute("btype")) {
			if (obj.getAttribute("pbchangenodes")) {
				retVal = {i: obj.id, type: obj.getAttribute("btype"), changenodes: obj.getAttribute("pbchangenodes") };
			}
			else {
				retVal = {i: obj.id, type: obj.getAttribute("btype"), changenodes: "" };
			}
		}
		return retVal;
	}
	
	this.ChangeNode = function(sNodeId) {
		var oNode = document.getElementById(sNodeId);
		
		if (oNode) {
			oNode.style.width = "600px";
		}
		
	}
}


plazoo_daincb_AJAX = function(LayerId, sourceUrl) {
	this.url = sourceUrl;
	this.sLayerId = LayerId;
		
	this.getRequest = function(){
		if (window.XMLHttpRequest) {
        	return new window.XMLHttpRequest();
    	} else if (window.ActiveXObject) {
        	return new window.ActiveXObject("Microsoft.XMLHTTP");
    	}
    	else { return null; }
	}
	
	this.objRequest = this.getRequest();
	
	this.setUrl = function(url) {
		this.url = url;	
	}
	
	this.getUrl = function(objDaIncB) {
		var objRetVal = null;
		var objRss = null;
		
		if ((this.objRequest) && (this.url != "")) {
			try {
				eval("document.plazoo_" + this.sLayerId + " = this.objRequest;");
				eval("document.plazoo_" + this.sLayerId + ".open(\"GET\", this.url, true);");
				eval("document.plazoo_" + this.sLayerId + ".onreadystatechange=function() {if (document.plazoo_" + this.sLayerId + ".readyState == 4) { objDaincb.printImage(document.plazoo_" + this.sLayerId + ".responseXML, \"" + this.sLayerId + "\"); } }");
				eval("document.plazoo_" + this.sLayerId + ".send(null);");
			}
			catch (ex){
				objDaincb.printImage(null, this.sLayerId);
			}
		}
	}
	
}

function plazoo_daincb_GF() {

	this.checkBrowser = function() {
		this.appName=navigator.appName;
		this.ver=navigator.appVersion;
		this.dom=(document.getElementById);
		this.ie5=(document.all && this.dom);
		this.ie4=(document.all && !this.dom);
		this.ns5=((parseInt(this.ver) >= 5) && this.dom && !document.all);
		this.ns4=(document.layers && !this.dom);
		return this;
	 }
}

var objDaincb = new plazoo_daincb();
