var adHTML = new Array();

adHTML[0] = new Array();
/* If Jpeg or gif file then this will complete the link and image tag */
adHTML[0][0] = "<a href='";
adHTML[0][1] = "' target=_blank><img border=0 src='";
adHTML[0][2] = "' width='";
adHTML[0][3] = "' height='";
adHTML[0][4] = "'></a>";

/* If its flash type ad then this will complete the code. */
adHTML[1] = new Array();
adHTML[1][0] = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="';
adHTML[1][1] = '" height="';
adHTML[1][2] = '"><param name="movie" value="';
adHTML[1][3] = '"><param name="quality" value="high"><embed src="';
adHTML[1][4] = '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="';
adHTML[1][5] = '" height="';
adHTML[1][6] = '"></embed></object>';


/* global vars */
var AdHtml = "";
var AdWidth = 0;
var AdHeight = 0;
function createPopupAd(AdType, AdSrc, Width, Height, AdLink){
	var popupHTML = "";
	if(AdType == "Flash"){
		popupHTML += makeFlashHtml(AdSrc, Width, Height);
	}
	else if(AdType == "Image"){
		popupHTML += makeImageHtml(AdSrc, Width, Height, AdLink);
	}
	
	AdHtml = popupHTML;
	AdWidth = Width;
	AdHeight = Height;
	window.setTimeout("startTimer()", 5000);
	//window.setTimeout("showPopup()", 1000, popupHTML, Width, Height);
}

function startTimer(){
	showPopup(AdHtml, AdWidth, AdHeight);
}

function makeImageHtml(Src, Width, Height, Link){
	adHTML[0][0] += Link;
	adHTML[0][1] += Src;
	adHTML[0][2] += Width;
	adHTML[0][3] += Height;
	
	return adHTML[0][0] + adHTML[0][1] + adHTML[0][2] + adHTML[0][3] + adHTML[0][4];
}

function makeFlashHtml(Src, Width, Height){
	adHTML[1][0] += Width;
	adHTML[1][1] += Height;
	adHTML[1][2] += Src;
	adHTML[1][3] += Src;
	adHTML[1][4] += Width;
	adHTML[1][5] += Height;
	
	return adHTML[1][0] + adHTML[1][1] + adHTML[1][2] + adHTML[1][3] + adHTML[1][4] + adHTML[1][5] + adHTML[1][6];
}

function showPopup(PopupBody, Width, Height){
	/*var oPopup = window.createPopup();
	var oPopupBody = oPopup.document.body;*/
	var Top, Right, Bottom, Left;
	Top = 175;
	Left = 300;
	Right = Left + Width;
	Bottom = Top + Height;
	//oPopupBody.style.backgroundColor = "magenta";
	//oPopupBody.style.border = "solid black 1px";
	/*oPopupBody.className = "Shadow";
	oPopupBody.innerHTML = PopupBody;
	oPopup.show(Left, Top, Width, Height, document.body);*/
	makeLayer('DAdLayer', Left, Top, Width, Height, 'Shadow', 1, 1);
	if(window.document.getElementById('DAdLayer')){
		window.document.getElementById('DAdLayer').innerHTML = PopupBody;
	}
	window.setTimeout("deleteAd()", 10000);
}

function deleteAd(){
	if(window.document.getElementById('DAdLayer')){
		deleteLayer('DAdLayer');
	}
}

function makeLayer(id,L,T,W,H,bgColor,visible,zIndex) {
 if (document.layers) {
  if (document.layers[id]) {
   alert ('Layer with this ID already exists!')
   return
  }
  var LR=document.layers[id]=new Layer(W)
  LR.name= id
  LR.left= L
  LR.top = T
  LR.clip.height=H
  LR.visibility=(null==visible || 1==visible ? 'show' : 'hide')
  if(null!=zIndex)  LR.zIndex=zIndex
  if(null!=bgColor) LR.className=bgColor
 }
 else if (document.all) {
  if (document.all[id]) {
   alert ('Layer with this ID already exists!')
   return
  }
  var LR= '\n<DIV id='+id+' class=' + bgColor + ' style="position:absolute'
  +'; left:'+L
  +'; top:'+T
  +'; width:'+W
  +'; height:'+H
  +'; clip:rect(0,'+W+','+H+',0)'
  +'; visibility:'+(null==visible || 1==visible ? 'visible':'hidden')
  +(null==zIndex  ? '' : '; z-index:'+zIndex)
  +(null==bgColor ? '' : '; background-color:'+bgColor)
  +'"></DIV>'
  document.body.insertAdjacentHTML("BeforeEnd",LR)
 }
}
function deleteLayer(id) {
 if (document.layers && document.layers[id]) {
  document.layers[id].visibility='hide'
  delete document.layers[id]
 }
 if (document.all && document.all[id]) {
  document.all[id].innerHTML=''
  document.all[id].outerHTML=''
 }
}