

// JScript File

//
// project specific variables - must be customized for each project
//
var debugMode = false;
var honorInterceptCookie = false;
var percentToIntercept = 1.0;
var interceptWidth = 260;
var interceptHeight = 280;
var interceptCookieName = "com.magid.intercept.UniqueInterceptProjectName";
var interceptDestinationURL = "";
var interceptImageURL = "http://pmtool.sharepointsite.net/Shared%20Documents/sece.png";
//var interceptBlankURL = "http://www.magid.com/intercept/blank.html";
var interceptBlankURL = "http://Plumb.growthbox.com/FirstPopup.htm";
// upper left x, upper left y, lower right x, lower right y (x1,y1,x2,y2)
var acceptInterceptButtonCoordinates = "65,199,204,218";
var declineInterceptButtonCoordinates = "100,242,165,259";


//
// adjust Y coordinate position, speed of flyin/flyout, and pause before flyin
//
var topOffset = 400;
var flyInStep = 30;
var flyOutStep = 100;
var flyInterval = 1;
var pauseBeforeFlyIn = 3000;
var stopX = -1; // set to -1 to fly in to calculated middle of window


//
// calculated values and working variables
// do not modify
//
var initialLeft = -2 * interceptWidth;
var currentLeft = initialLeft;
var isNetscape = false;
var isInternetExplorer = false;
var isUnknownUserAgent = false;
var interceptWasShown = false;
var interceptTimer;

var suppressOneDismissal = false;

var browserName = navigator.appName;

if ( browserName == "Netscape" ) {
  isNetscape = true;
} else {
  if ( browserName == "Microsoft Internet Explorer" ) {
    isInternetExplorer = true;
  } else {
    isUnknownUserAgent = true;
  }
}

function calculateStopPoint() {

  // default in case unknown browser
  var windowWidth = 1024;

  if ( isNetscape ) {
    windowWidth = window.innerWidth;
  }

  if ( isInternetExplorer ) {

    windowWidth = document.body.offsetWidth;
  }

  // if stopX isn't set to an explicit value, calculate middle
  // of page to stop it at.
  if ( stopX == -1 ) {
    stopX = parseInt( ( windowWidth - interceptWidth ) / 2, 10 );
  }
}


function hideIntercept() {
  document.getElementById( "floatingIntercept" ).style.display = "none";
  document.getElementById( "floatingInterceptIframe" ).style.display = "none";
}


function moveIntercept( maxLeft, step, hideWhenDone ) {

  window.clearTimeout( interceptTimer );

  if ( currentLeft < maxLeft ) {

    currentLeft = currentLeft + step;

    if ( currentLeft > maxLeft ) {
      currentLeft = maxLeft;
    }

    document.getElementById( "floatingIntercept" ).style.left =
      currentLeft + "px";

    document.getElementById( "floatingInterceptIframe" ).style.left =
      currentLeft + "px";

    if ( currentLeft < maxLeft ) {

      interceptTimer =
        window.setTimeout(
          "moveIntercept( " +
          maxLeft +
          ", " +
          step +
          ", " +
          hideWhenDone +
          " )",
          flyInterval
        );

    } else {

      if ( hideWhenDone ) {
        hideIntercept();
      }

    }
  }
}

function flyOutIntercept() {
  if ( ! suppressOneDismissal ) {
    moveIntercept( 2000, flyOutStep, true );
  } else {
    suppressOneDismissal = false;
  }
}

function writeInterceptCookie( value, expires, remove ) {

  var now = new Date();
  var expiration_date;

  if ( remove ) {

    expiration_date =
      new Date((new Date()).getTime() - ((1*24)*3600000));

  } else {

    expiration_date =
      new Date((new Date()).getTime() + ((expires*24)*3600000));

  }

  expiration_date = expiration_date.toGMTString();

  document.cookie =
    interceptCookieName +
    "=" +
    value +
    "; path=/; expires=" +
    expiration_date;
}

function getInterceptCookie( cookieName ) {

  var cookieValue = "";

  var allCookies = document.cookie;

  var cookiePosition = allCookies.indexOf( cookieName + '=' );

  if ( cookiePosition != -1 ){

    var valueStart = cookiePosition + cookieName.length + 1;

    var valueEnd = allCookies.indexOf( ';', valueStart );

    if ( valueEnd == -1 ) {

      valueEnd = allCookies.length;

    }

    cookieValue = allCookies.substring( valueStart, valueEnd );

    cookieValue = unescape( cookieValue );

  }

  return cookieValue;
}

function displayIntercept() {

  var interceptCookie = getInterceptCookie( interceptCookieName );

  if ( honorInterceptCookie && interceptCookie == "true" ) {
    interceptWasShown = true;
  }

  writeInterceptCookie( true, 30, false );

  if ( ! interceptWasShown ) {

    // only show if within random percentage of people we wish to intercept
    if ( Math.random() <= percentToIntercept ) {

      var bodyHtml = document.body.innerHTML;
      var zMatches = bodyHtml.match( /z[\-]index[\:][\ ]*\d+[\ ]*[\;]/ig );
      var zMax = 15;
      
      if ( zMatches != null ) {
        for ( var i = 0; i < zMatches.length; i++ ) {
          var zMatch = zMatches[ i ];
          var z = zMatch.match( /\d+/ )[ 0 ];
          if ( z > zMax ) zMax = z + 1;
        }
      }

      var interceptDiv = 
        "<iframe " +
        "  id=\"floatingInterceptIframe\"  allowtransparency='true' " +
        "  style=\"" +
        "   position: absolute; " +
        "   z-index: " + zMax++ + ";" +
        "   width: " + interceptWidth + ";" +
        "   height: " + interceptHeight + ";" +
        "   left: " + initialLeft + "px;" +
        "   top: " + topOffset + "px;\"" +
        "  src=\"" + interceptBlankURL + "\" " +
        "  marginheight=\"0\" " +
        "  marginwidth=\"0\" "  +
        "  noresize " +
        "  frameborder=\"0\""  +
        "  scrolling=\"no\">" +
        "</iframe>";

      interceptDiv += 
        "<div id=\"floatingIntercept\" " +
        "style=\"position: absolute; z-index: " + zMax + "; left: " +
        initialLeft +
        "px; top: " +
        topOffset +
        "px; border: 0; background-color: transparent;\" >";

//      interceptDiv += 
//        "<img src=\"" +
//        interceptImageURL +
//        "\" width=\"" +
//        interceptWidth +
//        "\" height=\"" +
//        interceptHeight +
//        "\" border=\"0\" alt=\"\" usemap=\"#interceptMap\" >";

      interceptDiv += "<map name=\"interceptMap\">";
      
      
            // For text...
      
      //interceptDiv += "<div style=\"position: absolute; z-index: 10; top:80%;left:30%;\">Hi! You want to chat?</div>";
//      interceptDiv += "$$$$3";

      // For Yes...
      
   //   interceptDiv += "<div style=\"position: absolute; z-index: 10; top:90%;left:30%;\"><a href=\"" +interceptDestinationURL +"\" onclick=\"hideIntercept()\">Yes</a></div>";

      // For No...
       
          //interceptDiv += "<div style=\"position: absolute; z-index: 10; top:5%;left:87%;\"><a href=\"javascript:Popupcancel();\"><img src='http://plumb.growthbox.com/images/close1.gif' border='0px' alt='Cancel'/></a></div>";

 var sPath = window.location;
 var sReffer='Null';
if (document.referrer != '')
{sReffer=document.referrer;}
var browseType='Null';
if (document.all)
var version=/MSIE \d+.\d+/;
if (!document.all){browseType=navigator.userAgent}
else{browseType=navigator.appVersion.match(version)}
var PageTitle=document.title;

      //interceptDiv += "<iframe allowtransparency=\"true\" marginheight=\"0\" marginwidth=\"0\" noresize frameborder=\"0\" scrolling=\"no\" style=\"position: absolute; z-index: 10; top:90%;left:30%;\" src=\"http://localhost:1408/Plumb/CampaignTrack.aspx?OwnerCreatedId=2&AdsId=25&PageName="+sPath+"&PageReffer="+sReffer+"&browseType="+browseType+"&PageTitle="+PageTitle+"&TrackEmail=&Url=a.html\"></iframe>";

//alert(GetCookie("0906201013595101ab"));
      interceptDiv += "<iframe height='270px' allowtransparency=\"true\"  marginheight='0' marginwidth='0' noresize frameborder='0' scrolling='no' style='position: absolute; z-index: 10; top:28%;left:10%;' src='http://plumb.growthbox.com/CampaignTrackAlhada.aspx?OwnerCreatedId=2&AdsId=38&PageName="+sPath+"&PageReffer="+sReffer+"&browseType="+browseType+"&PageTitle="+PageTitle+"&TrackEmail=&Url='></iframe>";

      // For Redirecting...

    //  interceptDiv += "<div style=\"position: absolute; z-index: 10; top:90%;left:50%;\"><a href=\"javascript:flyOutIntercept();\">No</a></div>";
     // interceptDiv += "$$$$5";



      // default, do nothing, areas listed above take precedence
      interceptDiv += 
        "<area shape=\"rect\" alt=\"\" coords=\"0,0," +
        interceptWidth +
        "," +
        interceptHeight +
        "\" nohref onclick=\"suppressOneDismissal = true;\" />";

      interceptDiv += "</map>";

      interceptDiv += "</div>";

      var dummyDiv = document.createElement( "div" );
      
      dummyDiv.innerHTML = interceptDiv;
      
      document.body.appendChild( dummyDiv );

      calculateStopPoint();

      interceptTimer =
        window.setTimeout(
          "moveIntercept( " +
          stopX +
          ", " +
          flyInStep +
          ", " +
          false +
          " )",
          pauseBeforeFlyIn
        );

      interceptWasShown = true;
      
      if ( document.addEventListener )
        document.addEventListener( "click", flyOutIntercept, false );
      
      if ( document.attachEvent )
        document.attachEvent( "onclick", flyOutIntercept );
      
    } else {
      if ( debugMode ) {
        alert( 
          "You weren't picked to be part of the random intercept sample.\n" +
          "Current intercept rate set at " + 
          ( percentToIntercept * 100 ) +
          "%\n\n" +
          "Now that you have visited this site once, you will not be " +
          "considered a candidate to be intercepted unless you remove the " +
          "cookie named: " +
          interceptCookieName +
          " which has now been placed into your browser.\n\n" +
          "NOTE:  This message will not show in production mode"
        );
      }
    }
  } else {
    if ( debugMode ) {
      alert( 
        "You have already visited this site so the intercept will not " +
        "be displayed unless you remove the cookie named: " +
        interceptCookieName +
        " from your browser.\n\n" +
        "You may not have been presented an intercept on your " +
        "initial visit to this site depending on whether you were " +
        "selected as part of the random sample, which is currently set to " +
        ( percentToIntercept * 100 ) +
        "%.\n\n" +
        "NOTE:  This message will not show in production mode"
      );
    }
  }
}
function Popupcancel() {

    var expdate = new Date();
    var num;
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
    if (!(num = GetCookie("0906201013595101ab")))
        num = 0;
    num++;


    SetCookie("0906201013595101ab", num, expdate);
    
  if ( ! suppressOneDismissal ) {
    moveIntercept( 2000, flyOutStep, true );
  } else {
    suppressOneDismissal = false;
  }
}


var getpopup;

var chkcou;
var cook;
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) {
    //alert("dd");
    var vars = [], hash;


    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 interceptStart() 
{

    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for (var i = 0; i < hashes.length; i++) 
    
    {
        var getvalu = hashes[i].indexOf('=');
        var finelkey = hashes[i].substring(0, getvalu);
        var PageKey = hashes[i].substring(getvalu + 1, hashes[i].length);

    }

    var expdate = new Date();
    var num;
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
    if (!(num = GetCookie("0906201013595101ab")))
        num = 0;
    num++;



    if (num > 1) {
    }
    else {


        try {
            var temp = "";
            if (document.body != null) {
                temp = document.body.innerHTML;
            }
            if (temp != "" && document.readyState) {
                if (document.readyState != "complete") {
                    temp = "";
                }
            }
            if (temp != "") {
                displayIntercept();
            } else {
                window.setTimeout(interceptStart, 100);
            }
        } catch (e) {
            window.setTimeout(interceptStart, 100);
        }

    }
}


interceptStart();
