

var BPopUpOnWindowCloseType=1;
var BPopUpOnTimeType=2;

var BPopUpApearAsFrame=1;
var BPopUpApearAsPageElement=2;


var BPopUpDisplayContent = ["http://www.4cruises.com","http://www.yahoo.com"];

var BPopUpIndex=0;


// frame properties
var BPopUpFrameWidth = 800;
var BPopUpFrameHeight = 800;
var BPopUpFrameLocationX =300;
var BPopUpFrameLocationY = 200;

// popup element properties

var BPopUpElementWidth =300;
var BPopUpElementHeight =340;

// timer properties

var BPopUpTimeInterval = 10; // value is in seconds
var BPopUpTimeType =1 ; // 1 if timer goes off one time    2 if multiple times

var BPopUpTimer;

var BPopUpFired = false;

function BPopUp(BType,BPopUpAppereance){
this.typePopUp = BType;
this.appearPopUp = BPopUpAppereance;

  if(BType == 1) window.onunload = BDisplayPopUp;
  else if(BType == 2) {
                       if(BPopUpTimeType ==1)setTimeout("BDisplayPopUp()",BPopUpTimeInterval*1000);
                       else if(BPopUpTimeType ==2) {
                                       BPopUpTimer=setInterval("BDisplayPopUp()",BPopUpTimeInterval*1000); 
                                       window.onunload = BPopUpClear;
                                                   }
                      }

}


//var raPopUp = new BPopUp(BPopUpOnWindowCloseType,BPopUpApearAsPageElement);

function BDisplayPopUp(){
   if(raPopUp.appearPopUp == BPopUpApearAsFrame) {
       var u=BPopUpDisplayContent[BPopUpIndex];
      var w =  window.open(BPopUpDisplayContent[BPopUpIndex],"adname","height="+BPopUpFrameHeight+",width="+BPopUpFrameWidth+",top="+BPopUpFrameLocationY+",left="+BPopUpFrameLocationX+",resizable=yes,status=yes,location=yes,toolbar=yes,menubar=yes,scrollbars=yes");

          BPopUpIndex++;
          if(BPopUpIndex == BPopUpDisplayContent.length) BPopUpIndex=0;

          if (w) {
                  w.blur();
                  w.location = u;
                   //window.focus();
          if ( (w==null)
||(typeof(w)=="undefined")
||(typeof(w.location.hash)!="string")
) {
           window.open(BPopUpDisplayContent[BPopUpIndex],"adname","height="+BPopUpFrameHeight+",width="+BPopUpFrameWidth+",top="+BPopUpFrameLocationY+",left="+BPopUpFrameLocationX+",resizable=yes,status=yes,location=yes,toolbar=yes,menubar=yes,scrollbars=yes");
}
else { w.blur(); }
//window.focus();
}
return false;
 
   }

   else if(raPopUp.appearPopUp == BPopUpApearAsPageElement) {
             if(!document.getElementById("popupID")) {
                    var divE=document.createElement("div");
                    var ifrE=document.createElement("iframe");
                        divE.style.zIndex =10;
                        divE.style.position="absolute";
                    var ce = BPopUpgetCenter();
                        divE.style.top = ce.down+"px";
                        divE.style.left = ce.ri+"px";
                        ifrE.id="popupID";
                        ifrE.style.width=BPopUpElementWidth;
                        ifrE.style.height=BPopUpElementHeight;
                        divE.appendChild(ifrE);
                        document.body.appendChild(divE);
                   }
            document.getElementById("popupID").src=BPopUpDisplayContent[BPopUpIndex];
      BPopUpIndex++;
          if(BPopUpIndex == BPopUpDisplayContent.length) BPopUpIndex=0;
                
  }

}

function BPopUpClear(){
 
  clearInterval(BPopUpTimer); 
}

function BPopUpgetCenter(){
var sX=0,sY=0;
   if(document.body && typeof document.body.scrollTop !="undefined"){
           sX +=document.body.scrollLeft;
           sY +=document.body.scrollTop;
          if(document.body.parentNode && typeof document.body.parentNode.scrollTop !="undefined"){
               sX += document.body.parentNode.scrollLeft;
               sY += document.body.parentNode.scrollTop;
           }
   }
   else if(typeof window.pageXOffset != "undefined"){
      sX += window.pageXOffset;
      sY == window.pageYOffset;
     }

var x = Math.round((getWindowW()-BPopUpElementWidth)/2)+sX;
var y = Math.round((getWindowH()-BPopUpElementHeight)/2)+sY;
    
return {ri:x,down:y};
  

}

function getWindowH(){
var  isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? 
            true : false;

  if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;

}

function getWindowW(){
var  isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? 
            true : false;
 if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth;
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;

}

function exitPage(evt) {
if(BPopUpFired) return;
  BPopUpFired =true;
  if(document.cookie.indexOf("BPopUpFired")>=0) return ;
  else document.cookie="BPopUpFired=true"; 
//var evt = window.event ? window.event : eve ? eve : null;
var u = BPopUpDisplayContent[BPopUpIndex];
BPopUpIndex++;
          if(BPopUpIndex == BPopUpDisplayContent.length) BPopUpIndex=0;
var w = window.open('', '','width=790,height=450,left=1,right=1,top=0,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,status=yes,location=yes');
if (w) {
//w.blur();
w.location = u;
window.focus();
if ( (w==null)
||(typeof(w)=="undefined")
||(typeof(w.location.hash)!="string")
) {
var t=window.open('', '','width=790,height=450,left=1,right=1,top=0,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,status=yes,location=yes');
t.location=u;
}
else { //w.blur();
      }
window.focus();
}

//if(window.event) {
       //           event.cancelBubble = true;
          //       event.returnValue = false;
               //  }
//else if(evt){
        ///     evt.preventDefault( );
     //   evt.stopPropagation( );
//}
}

function buildHandler(){

if (document.getElementsByTagName) {
var arrAnchor = document.getElementsByTagName('A');
for (i=0; i < arrAnchor.length; i++){
if (arrAnchor[i].getAttribute) {
if (!arrAnchor[i].onclick)
{
arrAnchor[i].onclick = exitPage(this);
}
}
}
}
}

