var emdpopup_width = 510; 
var emdpopup_height = 500;
var emParams='?subject=From virginiacommunityassociationlaw.com';
var regBoxDir = "/images";
var popUpWinXsrc='/images/popup_close_normal.gif';
var popUpWinXHoverSrc='/images/popup_close_hover.gif';

    function getScreenCenterY()
    {
        var y = 0;
        y = getScrollOffset()+(getInnerHeight()/2);
        return(y);
    }

    function getScreenCenterX()
    {
        return(document.body.clientWidth/2);
    }

    function getInnerHeight()
    {
        var y;
        if (self.innerHeight) // all except Explorer
            y = self.innerHeight;
        else if (document.documentElement && document.documentElement.clientHeight)     // Explorer 6 Strict Mode
            y = document.documentElement.clientHeight;
        else if (document.body) // other Explorers
            y = document.body.clientHeight;
        return(y);
    }

    function getScrollOffset()
    {
        var y;
        if (self.pageYOffset) // all except Explorer
            y = self.pageYOffset;
        else if (document.documentElement && document.documentElement.scrollTop)    // Explorer 6 Strict
            y = document.documentElement.scrollTop;
        else if (document.body) // all other Explorers
            y = document.body.scrollTop;
        return(y);
    }
    var shadowOffsetLeft=-6;
    var shadowOffsetTop=6;
    function buildTable(html,width,height)
    {
        var bgColor = "#dcdcba";
        var windowHTMLTableWrapperOpen="<table cellpadding=\"0\" cellspacing=\"0\" style=\"width:"+width+"px;height:"+height+"px;\"><tr><td><img src=\""+regBoxDir+"/popup_tl.gif\"></td><td style=\"background-color:"+bgColor+";\"></td><td><img src=\""+regBoxDir+"/popup_tr.gif\"></td></tr><tr><td style=\"background-color:"+bgColor+";\"></td><td class=\"content\" style=\"background-color:"+bgColor+";width:"+(width-8)+"px;height:"+(height-8)+"px;padding:0px;\">";
        var windowHTMLTableWrapperClose="</td><td style=\"background-color:"+bgColor+";\"></td></tr><tr><td><img src=\""+regBoxDir+"/popup_bl.gif\"></td><td style=\"background-color:"+bgColor+";\"></td><td><img src=\""+regBoxDir+"/popup_br.gif\"></td></tr></table>";

        return windowHTMLTableWrapperOpen+html+windowHTMLTableWrapperClose;
    }
    function popUpWindow(width,height,div,extraClass)
    {
        var html = div.innerHTML;
        var divOffsetTop=0;
        var divOffsetLeft=0;
        
        var wOffset=getScreenCenterX()-(width/2)+divOffsetLeft;
        var hOffset=((getInnerHeight()-height)/2)+divOffsetTop;
        
        var maskDivHTML="<div id=\"fixme\" class=\"siteMask\" style=\"width:"+(getScreenCenterX()*2)+"px;height:"+(getInnerHeight()+getScrollOffset())+"px;\"></div>";
        var windowLaunchInnerHTML = "<div id=\"fixme\" class=\"popUpDiv"+extraClass+"\" style=\"top:"+hOffset+"px;left:"+wOffset+"px;width:"+width+"px;height:"+height+"px;\">"+buildTable(html,width,height)+"</div>";
        var windowLaunchInnerHTMLShadow = "<div id=\"fixme\" class=\"popUpDivShadow\" style=\"top:"+(hOffset+shadowOffsetTop)+"px;left:"+(wOffset+shadowOffsetLeft)+"px;width:"+width+"px;height:"+height+"px;\"></div>";
        var clearDiv="<div class=\"clear\"></div>";
        
        document.getElementById("divWinLauncher").innerHTML=windowLaunchInnerHTML+maskDivHTML;
    }
        
    var infoHolder='';
    function closePopupWin()
    {
        document.getElementById("divWinLauncher").innerHTML="";
        infoHolder='';
    }
    function disclaimerEmail(handle,host)
    {
        if (handle!='')
            handle+='@';
        infoHolder=handle+host;
        popUpWindow(emdpopup_width,emdpopup_height,document.getElementById("emailDisclaimerPopupContent"), '');
    }
    function openPopupMessage(buttonsClass)
    {
        var okButtonOnlyClass = ' okaybuttononly';
        if (buttonsClass == undefined ||
            buttonsClass == null
            )
            buttonsClass = okButtonOnlyClass;
        else
        {
            buttonsClass += '';
            if (buttonsClass.indexOf('[object') == 0)
                buttonsClass = okButtonOnlyClass;
        }
        popUpWindow(emdpopup_width,emdpopup_height,document.getElementById("emailDisclaimerPopupContent"), buttonsClass);
    }
    function openJavascriptActivator(code, closeWinOnClick)
    {
        var div = document.getElementById("emailDisclaimerPopup_accept");
        var onclickNode = null;
        // find onclick value
        for(var i=0;i<div.attributes.length;i++)
        {
            if (div.attributes[i].nodeName == 'onclick')
            {
                onclickNode = div.attributes[i];
                break;
            }
        }
        // replace onclick value
        if (onclickNode!=null)
        {
            if (closeWinOnClick == true)
            {
                onclickNode.nodeValue="performPending('"+code+"');";
            }
            else
            {
                onclickNode.nodeValue = code;
            }
        }
        openPopupMessage('');
    }
    function performPending(code)
    {
        setTimeout(code,0);
        closePopupWin();
    }
    function testfunc()
    {
        alert('Got Here!');
    }
    function openEmailClient()
    {
        if (infoHolder!='')
        {
            window.location="mailto:"+infoHolder+emParams;
            closePopupWin();
        }
    }
    function offOn(img, on)
    {
        if (on)
            img.src=popUpWinXHoverSrc;
        else
            img.src=popUpWinXsrc;
    }
    function changeClass(div,className)
    {
        div.className=className;
    }
    
    function addPopups()
    {
	    var rpopups = document.myGetElementsByClassName('popupmessage');
	    for (i=0;i<rpopups.length;i++)
	    {
	        if (rpopups[i].tagName=="A")
	        {
	            rpopups[i].href = "javascript:void(0);";
	            rpopups[i].onclick = openPopupMessage;
	        }
		}
	}

    if (!document.myGetElementsByClassName) {
	    document.myGetElementsByClassName = function(className) {
		    var children = document.getElementsByTagName('*') || document.all;
		    var elements = new Array();
    	  
		    for (var i = 0; i < children.length; i++) {
			    var child = children[i];
			    var classNames = child.className.split(' ');
			    for (var j = 0; j < classNames.length; j++) {
				    if (classNames[j] == className) {
					    elements.push(child);
					    break;
				    }
			    }
		    }
		    return elements;
	    }
    }
