var adPositions = new Array;

// Write out the placeholder <div> and add an entry to the adPositions array to indicate that this ad position is present on the current page
function writeAdDiv(name, ad_width, ad_height) {
    // Write the placeholder <div>
    document.write('<div class="banner" id="'+name+'" style="width:'+ad_width+'px; height:'+ad_height+'px; line-height:' + ad_height + 'px;">&nbsp;</div>');
    // Add an item to the adPositions array
    adPositions[name] = name;
}

// DIV moving code
function OpenX_findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
    }
	return curleft;
}

function OpenX_findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
    }
	return curtop;
}

function OpenX_moveAbove(sourceObj,targetObj) {
    var height = 0;
    if (sourceObj.offsetHeight) {
        height = sourceObj.offsetHeight;
    } else if (sourceObj.clip && sourceObj.clip.height) {
        height = sourceObj.clip.height;
    } else if (sourceObj.style && sourceObj.style.pixelHeight) {
        height = sourceObj.style.pixelHeight;
    }
    
    if (window.XMLHttpRequest) {
		if(document.all) { //IE7
		} else { // Mozilla, etc
			targetObj.style.paddingTop=0;targetObj.style.paddingBottom=0;
		}
	} else{ // IE6, older browsers
	}
    if (height > 0) {targetObj.style.height = height; }
    sourceObj.style.left = OpenX_findPosX(targetObj);
    sourceObj.style.top = OpenX_findPosY(targetObj);
}

function OpenX_positionDivs() {
    for (var zoneName in adPositions) {
        var offScreenZoneName = zoneName + '-Hidden';
        if (document.getElementById) {
            targetZoneDivID = document.getElementById(zoneName);
            sourceZoneDivID = document.getElementById(offScreenZoneName);
        } else if (document.all) {
            targetZoneDivID = document.all[zoneName];
            sourceZoneDivID = document.all[offScreenZoneName];
        } else if (document.layers) {
            targetZoneDivID = document.layers[zoneName];
            sourceZoneDivID = document.layers[offScreenZoneName];
        }
        if ((targetZoneDivID != null) && (sourceZoneDivID != null)) {
    		OpenX_moveAbove(sourceZoneDivID, targetZoneDivID);
        }
    }
}



