Part 2 of 3
function display(obj)
{
var divContent = null;
var _body = null;
var type = parseInt(obj,10);
//type when 1 means it's going to display the ad in the parent
if(type == 1)
{
divContent = parent.document.getElementById("divContent");
_body = parent.document.body;
docWidth = parent.document.documentElement.clientWidth == 0 ? _body.clientHeight : parent.document.documentElement.clientWidth;
docHeight = parent.document.documentElement.clientHeight == 0?_body.clientHeight:parent.document.documentElement.clientHeight;
}
else
{
divContent = $("divContent");
_body = document.body;
docWidth = document.documentElement.clientWidth==0?_body.clientWidth : document.documentElement.clientWidth;
docHeight = document.documentElement.clientHeight==0?_body.clientHeight:document.documentElement.clientHeight;
}
//divide the body into 9 parts
// 1 4 7
// 2 5 8
// 3 6 9
var perWid = Math.round(docWidth / 3);
var perHei = Math.round(docHeight / 3);
switch(iPosition)
{
case 1 :
posLeft = 0;
posTop = 0;
break;
case 2 :
posLeft = 0;
posTop = perHei;
break;
case 3 :
posLeft = 0;
posTop = perHei * 2;
break;
case 4 :
posLeft = perWid;
posTop = 0;
break;
case 5 :
posLeft = perWid;
posTop = perHei;
break;
case 6 :
posLeft = perWid;
posTop = perHei * 2;
break;
case 7 :
posLeft = perWid * 2;
posTop = 0;
break;
case 8 :
posLeft = perWid * 2;
posTop = perHei;
break;
case 9 :
posLeft = perWid * 2;
posTop = perHei * 2;
break;
default:
posLeft = perWid;
posTop = perHei;
break;
}
var leftAddwidth = parseInt(posLeft,10) + parseInt(iWidth,10);
var docWidMinusiWid = parseInt(docWidth,10) - parseInt(iWidth,10);
posLeft = leftAddwidth > parseInt(docWidth,10) ? (docWidMinusiWid > 0 ? docWidMinusiWid : 0) : (parseInt(posLeft,10));
var topAddheight = parseInt(posTop,10) + parseInt(iHeight,10);
var docHeiMinusiHei = parseInt(docHeight,10) - parseInt(iHeight,10);
posTop = topAddheight > parseInt(docHeight,10) ? (docHeiMinusiHei > 0 ? docHeiMinusiHei : 0) : (parseInt(posTop,10));
switch(iPosition)
{
case 7:
case 8:
case 9:
posLeft = parseInt(posLeft,10) - 18;
break;
}
// no need to move the ad when display,just show it
if(iShowType == 1)
{
divContent.style.left = posLeft + "px";
divContent.style.top = posTop + "px";
divContent.style.visibility = "visible";
}
else
{
//set the original position just before move the ad
switch(iPosition)
{
case 3:
case 6:
case 9:
divContent.style.left = posLeft + "px";
divContent.style.top = docHeight + "px";
break;
case 1:
case 4:
case 7:
divContent.style.left = posLeft + "px";
divContent.style.top = (-1) * perHei + "px";
break;
case 2:
divContent.style.left = (-1) * perWid + "px";
divContent.style.top = posTop + "px";
break;
case 8:
divContent.style.left = 3 * perWid + "px";
divContent.style.top = posTop + "px";
break;
default:
break;
}
divContent.style.visibility = "visible";
moveWin(type);
}
}
///<summary>
///move the ad step by step,adjust the div's position
///</summary>
///<param name=type>type=1,the parent window,or itself</param>
function moveWin(type)
{
var curTop = 0,curLeft = 0,step = 15;
var div = null;
if(type == 1) isParent = true;
else isParent = false;
if(isParent) div = parent.document.getElementById("divContent");
else div = $("divContent");
curTop = parseInt(div.style.top,10);
curLeft = parseInt(div.style.left,10);
switch(iPosition)
{
case 3:
case 6:
case 9:
if(parseInt(curTop,10) > parseInt(posTop,10))
{
var minus = parseInt(curTop,10) - parseInt(posTop,10);
var curMinus = (parseInt(minus,10) - parseInt(step,10)) >= 0 ? parseInt(step,10) : ((parseInt(step,10) - parseInt(minus,10)) >= 0 ? (parseInt(step,10) - parseInt(minus,10)) : 0);
var newTop = parseInt(curTop,10) - parseInt(curMinus,10);
div.style.top = newTop + "px";
div.style.zIndex++;
if(typeof(objTimer)=='undefined')objTimer = setInterval(function(){moveWin(type);},1);
}
else
{
if(objTimer)
clearInterval(objTimer);
}
break;
case 1:
case 4:
case 7:
if(parseInt(curTop,10) < parseInt(posTop,10))
{
var minus = parseInt(posTop,10) - parseInt(curTop,10);
var curMinus = (parseInt(minus,10) - parseInt(step,10)) >= 0 ? parseInt(step,10) : ((parseInt(step,10) - parseInt(minus,10)) >= 0 ? (parseInt(step,10) - parseInt(minus,10)) : 0);
var newTop = parseInt(curTop,10) + curMinus;
div.style.top = newTop + "px";
div.style.zIndex++;
if(typeof(objTimer)=='undefined')objTimer = setInterval(function(){moveWin(type);},1);
}
else
{
if(objTimer)
clearInterval(objTimer); }
break;
case 2:
if(parseInt(curLeft,10) < parseInt(posLeft,10))
{
var minus = parseInt(posLeft,10) - parseInt(curLeft,10);
var curMinus = (parseInt(minus,10) - parseInt(step,10)) >= 0 ? parseInt(step,10) : ((parseInt(step,10) - parseInt(minus,10)) >= 0 ? (parseInt(step,10) - parseInt(minus,10)) : 0);
var newLeft = parseInt(curLeft,10) + curMinus;
div.style.left = newLeft + "px";
div.style.zIndex++;
if(typeof(objTimer)=='undefined')objTimer = setInterval(function(){moveWin(type);},1);
}
else
{
if(objTimer)
clearInterval(objTimer);
}
break;
case 5:
div.style.top = posTop + "px";
div.style.left = posLeft + "px";
break;
case 8:
if(parseInt(curLeft,10) > parseInt(posLeft,10))
{
var minus = parseInt(curLeft,10) - parseInt(posLeft,10);
var curMinus = (parseInt(minus,10) - parseInt(step,10)) >= 0 ? parseInt(step,10) : ((parseInt(step,10) - parseInt(minus,10)) >= 0 ? (parseInt(step,10) - parseInt(minus,10)) : 0);
var newLeft = parseInt(curLeft,10) - curMinus;
div.style.left = newLeft + "px";
div.style.zIndex++;
if(typeof(objTimer)=='undefined')objTimer = setInterval(function(){moveWin(type);},1);
}
else
{
if(objTimer)
clearInterval(objTimer);
}
break;
default:
break;
}
}
///<summary>
///handle the <a> element in parent window
///</summary>
function PCheckAd()
{
try
{
var win = window.frames[0].parent;
if (win.document.readyState != 'complete')
{
return;
}
window.clearInterval(_hPInterval);
_hPInterval = null;
var doc = win.document;
for (var i in doc.links)
{
if (doc.links.target == "")
{
doc.links.target = "_top";
}
}
for (var i in doc.forms)
{
if (doc.forms.target == "")
{
doc.forms.target = "_top";
}
}
}
catch(e)
{}
}
///<summary>
///handle the <a> element in current window
///</summary>
function CheckAd()
{
try
{
var win = window.frames[0];
if (win.document.readyState != 'complete')
{
return;
}
window.clearInterval(_hInterval);
_hInterval = null;
var doc = win.document;
for (var i in doc.links)
{
if (doc.links.target == "")
{
doc.links.target = "_top";
}
}
for (var i in doc.forms)
{
if (doc.forms.target == "")
{
doc.forms.target = "_top";
}
}
}catch(e){}
}
///<summary>
///call this function to display the ad in the current window
///</summary>
function displayAd()
{
createBorder(iBorder);
display("0");
}
///<summary>
///call this function to display the ad in the parent window,when top.location != self.location happens,
///need to display the ad in the parent window too.In this function,need to register the close event to the some element.
///</summary>
function dispalyAdInP()
{
if(isLoaded == false)
{
if(isCreated)
{
parent.document.getElementById("divContent").style.visibility = "visible";
isLoaded = true;
clearInterval(_hShowWindow);
isStartAdjust = true;
return;
}
if(null != parent) {
createBorder(iBorder);
var divContent = $("divContent");
var pDiv = parent.document.createElement("div");
pDiv.setAttribute("id","divContent");
parent.document.body.appendChild(pDiv);
parent.document.getElementById("divContent").innerHTML = divContent.innerHTML;
parent.document.getElementById("divContent").style.zIndex = 10000;
parent.document.getElementById("divContent").style.position = "absolute";
parent.document.getElementById("divContent").style.top = "0";
var parCloseObj = null;
switch(iBorder)
{
case 1:
parCloseObj = parent.document.getElementById("divTitle");
break;
case 2:
var table = parent.document.getElementById("tframe");
parCloseObj = table.rows[0].cells[3];
break;
case 3:
var table = parent.document.getElementById("tframe");
parCloseObj = table.rows[0].cells[4];
break;
default:
break;
}
if (navigator.userAgent.indexOf("Firefox")!=-1)
{
isFirefox = true;
}
if(isFirefox)
{
parCloseObj.addEventListener("click",closePWin,false);
}
else
{
parCloseObj.attachEvent("onclick",closePWin);
}
display("1");
}
}
else
{
clearInterval(_hShowWindow);
isStartAdjust = true;
}
} |