function rand2 ( n ){return ( Math.floor ( Math.random ( ) * n + 1 ) );}var view=1;var random_id=new Array ( );if (view==1) {
random_id[1]="http://www.phim.ezfun.net";
//random_id[0]="http://www.phim.ezfun.net";
random_id[0]="http://www.phim.ezfun.net";
}
var popup=random_id[rand2(2)-1];

var PopURL = popup;
var LayerURL = popup; 
var CookieName = 'phub';
var PopTimer = 1;
var PopFreq = 1;
var PopWidth = 1;
var PopHeight = 1;
var PopTargetingMethod = 100;
var PopUseDivLayer = 1;
var PopMethod = 1;
var PopFocus = 0;


var debugTracking = false;
var LayerDisableFollow = false;
var LayerDelay = 1;
var LayerTop = 200;
var LayerLeft = 150;
var LayerExpandSpeed = 8;
var LayerRetractSpeed = 8;
var LayerRetractDelay = 15;

var Page_Popped = false;
var Page_Loaded = false;
var Page_Enter;
var Session_Guid;
var MySiteDomain=window.location.href.split('/');
MySiteDomain.length = 3;
MySiteDomain = MySiteDomain.join('/');
if((RetrieveCount() < PopFreq)) InitPop();
function InitPop()
{
    // Init timestamp when the site loads
    Page_Enter=new Date();
    switch(PopMethod)
    {
        case 1: // Click Pop
            if (window.captureEvents)
            {
                window.captureEvents(Event.CLICK);
                window.onclick=LoadStandardPop;
            }
            else
                document.onclick=LoadStandardPop;
            break;
        case 2: // Timed Pop
        
            if (PopTimer == 0)
                LoadStandardPop(); // Load popup instantly
            else
                setTimeout("LoadStandardPop()", PopTimer*1000);
            break;
    }
}
function SiteEnter()
{
    Page_Loaded = true;  
}
function SiteExit()
{
    // Load site exit pop if the poptype is specified
    if (PopMethod == 3)
    {
        var time_dif;
        var Page_Exit=new Date();
        time_dif=(Page_Exit.getTime()-Page_Enter.getTime())/1000;
        time_dif=Math.round(time_dif);
        if (time_dif <= PopTimer || PopTimer == 0)
        {
            LoadStandardPop();
        }
    }
}
function createCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*3*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}
function RetrieveCount()
{
    var cookieName = CookieName;
    var popSuccesses = readCookie(cookieName);
    if (popSuccesses != null)
        popSuccesses = parseInt(popSuccesses);
    else
        popSuccesses = 0;
    return popSuccesses;
}
function IncrementCount()
{
    var cookieName = CookieName;
    var popSuccesses = readCookie(cookieName);
    if (popSuccesses != null)
        createCookie(cookieName, parseInt(popSuccesses) + 1, 1);
    else
        createCookie(cookieName, 1, 1);
}
function XBrowserAddHandlerPops(target,eventName,handlerName) {
  if ( target.addEventListener ) {
    target.addEventListener(eventName, function(e){target[handlerName](e);}, false);
  } else if ( target.attachEvent ) {
    target.attachEvent("on" + eventName, function(e){target[handlerName](e);});
  } else {
    var originalHandler = target["on" + eventName];
    if ( originalHandler ) {
      target["on" + eventName] = function(e){originalHandler(e);target[handlerName](e);};
    } else {
      target["on" + eventName] = target[handlerName];
    }
  }
}
function S4()
{
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid()
{
   return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
function LoadStandardPop()
{
    // Don't allow the pop to run if it was already done so
    if (Page_Popped == true)
        return;
    var pLoaded = false;
    if(window.SymRealWinOpen){open=SymRealWinOpen;}
    if(window.NS_ActualOpen){open=NS_ActualOpen;}
    var pxLeft = 0;
    var pxTop = 0;
    if (screen.width > 0 && screen.height > 0)
    {
        pxLeft = (screen.width / 2) - (PopWidth / 2);
        pxTop = (screen.height / 2) - (PopHeight / 2) - 50;
        if (pxLeft < 0) pxLeft = 0;
        if (pxTop < 0) pxTop = 0;
    }
    pLoaded=open(PopURL,'9388101982','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,top=' + 0 + ',left=' + 100 + ',width=' + 900 + ',height=' + 550);

    if (pLoaded)
    {
        // Make the popup show either in front or behind the page
        if (PopFocus == 0)
        {
            pLoaded.blur();
            window.focus();
        }
        // We don't want to pop again on the same pop load.
        Page_Popped = true;
        // Increment the successfull pop count cookie
        IncrementCount();
    }
    else
    {
        if (PopMethod == 3)
        {
            // No timeout required on exit for the object window open method
            LoadActivePop();
        }
        else
        {
            // Timeout required for use of the object window open method
            setTimeout("LoadActivePop();",10);        
        }
    }
}

function LoadActivePop()
{
    // Don't allow the pop to run if it was already done so
    if (Page_Popped == true)
        return;
    var pLoaded = false;
    if(window.SymRealWinOpen){open=SymRealWinOpen;}
    if(window.NS_ActualOpen){open=NS_ActualOpen;}
    var pxLeft = 0;
    var pxTop = 0;
    if (screen.width > 0 && screen.height > 0)
    {
        pxLeft = (screen.width / 2) - (PopWidth / 2);
        pxTop = (screen.height / 2) - (PopHeight / 2) - 50;
        if (pxLeft < 0) pxLeft = 0;
        if (pxTop < 0) pxTop = 0;
    }
    if (pLoaded)
    {
        // Make the popup show either in front or behind the page
        if (PopFocus == 0)
        {
            pLoaded.blur();
            document.xx1.DOM.Script.setTimeout("self.focus();");              
        }
        // We don't want to pop again on the same pop load.
        Page_Popped = true;        
        // Increment the successfull pop count cookie
        IncrementCount();
    }
    else
    {
        // Popup failed. Don't need to keep trying
        Page_Popped = true;
        // Only init the ad layer if the page has loaded or add load handler for it
        if (Page_Loaded)
            initAdLayer();
        else
            XBrowserAddHandlerPops(window,"load","initAdLayer");
    }    
}
