﻿/*
	popstuff 
	function to automatically add popup window calls to each link
	with a target, and add close window links to the popups.
*/
function showLeavingDiv() {
document.getElementById("leavingSite").style.display = "block";
}
function hideLeavingDiv() {
document.getElementById("leavingSite").style.display = "none";
}

function initpop()
{
	var closeElementId='closewindow';
	var closeLinkText='Close window';
	var w,h,extraFeatures,windowAttributes;
		var as,i,popfun
		as=document.getElementsByTagName('a');
		for (i=0;i<as.length;i++)
		{
			if(as[i].target)
			{
//			    if (as[i].target.toLowerCase() == '_blank')
//			    {
//                    w='500';
//                    h='300';
//                    windowAttributes = createWindowAttributes(w,h,'scrollbars=no,location=no');
//	                
//                    //popfun=function(){window.open('/build/LeavingSite.aspx?href=' + encodeURI(this.href),'LeavingSite',windowAttributes);return false;};
//                    popfun=function(){window.open('#?href=' + encodeURI(this.href),'_self',windowAttributes);return false;};
//                    as[i].onclick=popfun;
//                    as[i].onkeypress=popfun;
//                }
            }
            else
            {
                var attachPop = false;
                extraFeatures = 'scrollbars=no,location=no';
                switch(as[i].className)
                {
                    case "timeMachineVideo":
                        w='432';
                        h='258';
                        attachPop = true;
                        break;
                    default:
                        break;
                }
                
                if (attachPop)
                {
                    windowAttributes = createWindowAttributes(w,h,extraFeatures);
	            	            
                    popfun=function(){window.open(this.href,'',windowAttributes);return false;};
                    as[i].onclick=popfun;
                    as[i].onkeypress=popfun;
                }
			}
		}
}

function createWindowAttributes(width, height, additionalFeatures)
{
    var LeftPosition,TopPosition, features;
    LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	features = 'width='+width+',height='+height+',left='+LeftPosition+',top='+TopPosition;
	if(additionalFeatures != '')
	{
	    features = features + ',' + additionalFeatures;
	}
	return features;
    
}

function addEvent(obj, evType, fn)
{ 
	if (obj.addEventListener)
	{ 
		obj.addEventListener(evType, fn, true); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}
addEvent(window,'load',initpop);


// Self-working popup to use for flash videos before the 'Leaving Site' window is promoted
// Chris Morrow, June 9th, 2008
var WindowObjectReference = null; // global variable

 function openPopup(strUrl, strWindowName)
 {
    width='432';
    height='258';
    LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
    features = 'width='+width+',height='+height+',left='+LeftPosition+',top='+TopPosition;
        if(WindowObjectReference == null || WindowObjectReference.closed)
        {
        WindowObjectReference = window.open(strUrl, strWindowName, features, "resizable=no,scrollbars=no,status=no");
        }
        else
        {
        WindowObjectReference.focus();
        };
 }
 
 var WindowObjectReference = null; // global variable

 function openCalc(strUrl)
 {
    strWindowName = 'DensGuard_Calculator';
    width='760';
    height='500';
    LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
    features = 'width='+width+',height='+height+',left='+LeftPosition+',top='+TopPosition;
        if(WindowObjectReference == null || WindowObjectReference.closed)
        {
        WindowObjectReference = window.open(strUrl, strWindowName, features, "resizable=no,scrollbars=no,status=no");
        }
        else
        {
        WindowObjectReference.focus();
        };
 }
