var etwPopup = null
var continueVisit = false

var shownsurvey = GetCookie('jrsurvey');

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}

function SetCookie (name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}


function ContinueVisit()
{
  continueVisit = true;
}
function openETWWindow(flagSrc,URL,vRef)
{
        try
        {
		   //alert(continueVisit + "--" + doETWPopup +"--" + window.location.href);
	       if (!continueVisit && !doETWPopup && shownsurvey == null)
			{
				if ((etwPopup == null) || etwPopup.closed || !etwPopup.open)
				{
					if(flagSrc){
						etwPopup = window.open(URL + "popup/exitsurvey.asp?from=click", "etwPopup", "scrollbars=1,resizable=0,width=625,height=540,toolbar=0,menubar=0,status=0")
					}else{
						etwPopup = window.open(URL + "popup/exitsurvey.asp?from=" + vRef, "etwPopup", "scrollbars=1,resizable=0,width=625,height=540,toolbar=0,menubar=0,status=0");
						pathname = location.pathname;
    						//myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
						//myDomain = 'juliannarae.com';
    						// set expiry date to 1 year from now.
    						var largeExpDate = new Date ();
    						largeExpDate.setTime(largeExpDate.getTime() + (10 * 24 * 3600 * 1000));
						//largeExpDate.setTime(largeExpDate.getTime());
    						SetCookie('jrsurvey','SET',largeExpDate);
					}
					if((etwPopup != null)&&(!etwPopup.closed))
					{
						etwPopup.blur()
					}
					this.focus()
				}
			}
		}
		catch(ex)
		{
        }
}

if (document.layers)
document.captureEvents(Event.CLICK);
document.onclick = 
function (evt) 
{
var target = document.all ? event.srcElement : evt.target;
if(target.href && target.href.indexOf(window.top.location.hostname) != -1)
	ContinueVisit();
};

