var Debug


//start home_popup section
function DisplayPopUp( ) {
  var PERCENT = 100;    // Set this to the Percentage of users to see PopUp
  var Height  = 475;   // Height and Width of popup window
  var Width   = 372;
//  var URL     = "http://public.wsj.com/nonsub-popup.htm"; // URL of new Window
//    var URL     = "/marketing/nonsub_popup.html"; // URL of new Window
  var URL     = "/marketing/nonsub_popup.html"; // URL of new Window
  var Debug   = 0;     // Set this to 1 to turn on Testing Mode (0 otherwise)

  var oneDay = 24 * 60 * 60 * 1000;  // (milliseconds)
  var oneMonth= oneDay * 30;
  var Left = 0;
  var Top = 0;

  var expDate = new Date( );
    expDate.setTime( expDate.getTime( ) + oneDay * 2 ); // Expires in Ten Days

  // ----- DO NOT MODIFY BELOW THIS LINE ------

  var agent = navigator.userAgent;
  if ( agent.indexOf( 'Mozilla' ) != -1 ) { // almost all browsers send this

    // only select users who haven't seen the popup recently.
    if ( (( ! HasLoginCookie() ) && HasUserTypeCookie() != 'subscribed') || Debug ) {
	    if ( ( ! HasSurveyCookie() ) || Debug ) {
	
	      // only select a percentage of those potential users.
	      var theDate = new Date( );
	      if ( ( theDate.getTime( ) % 100 ) < PERCENT ) {
	
	        // try to set the cookie.
	        document.cookie = 'survey=true; expires=' +
	                          expDate.toGMTString( ) + '; path=/';
	
	        // if they accepted the cookie; give them the popup!
	        if ( HasSurveyCookie( ) ) {
	          window.open( URL, 'SurveyPopUp',
	                       'toolbar=no,location=no,directories=no,' +
	                       'status=no,scrollbars=no,menubar=no,' +
	                       'width=' + Width + ',height=' + Height + ',top=' + Top + ',left=' + Left);
	        }
	      }
	    }
	}    
  }
}

//start health_popup section
function DisplayPopUpForHealth( ) {
  var PERCENT = 100;    // Set this to the Percentage of users to see PopUp
  var Height  = 460;   // Height and Width of popup window
  var Width   = 372;
  var URL     = "/public/health_popup.htm"; // URL of new Window
  var Debug   = 0;     // Set this to 1 to turn on Testing Mode (0 otherwise)

  var oneDay = 24 * 60 * 60 * 1000;  // (milliseconds)
  var oneMonth= oneDay * 30;
  var Left = 0;
  var Top = 0;

  var expDate = new Date( );
  expDate.setTime( expDate.getTime( ) + oneDay * 10 ); // Expires in Ten Days

  // ----- DO NOT MODIFY BELOW THIS LINE ------

  var agent = navigator.userAgent;
  if ( agent.indexOf( 'Mozilla' ) != -1 ) { // almost all browsers send this

    // only select users who haven't seen the popup recently.
    if ( (( ! HasLoginCookie() ) && HasUserTypeCookie() != 'subscribed') || Debug ) {
	    if ( ( ! HasSurveyCookieForHealth() ) || Debug ) {
	
	      // only select a percentage of those potential users.
	      var theDate = new Date( );
	      if ( ( theDate.getTime( ) % 100 ) < PERCENT ) {
	
	        // try to set the cookie.
	        document.cookie = 'ForHealth=true; expires=' +
	                          expDate.toGMTString( ) + '; path=/';
	
	        // if they accepted the cookie; give them the popup!
	        if ( HasSurveyCookieForHealth( ) ) {
	          window.open( URL, 'SurveyForHealthPopUp',
	                       'toolbar=no,location=no,directories=no,' +
	                       'status=no,scrollbars=no,menubar=no,' +
	                       'width=' + Width + ',height=' + Height + ',top=' + Top + ',left=' + Left);
	        }
	      }
	    }
	}    
  }
}

//start media_popup section
function DisplayPopUpForMandM( ) {
  var PERCENT = 100;    // Set this to the Percentage of users to see PopUp
  var Height  = 460;   // Height and Width of popup window
  var Width   = 366;
  var URL     = "/public/MandM_popup.html"; // URL of new Window
  var Debug   = 0;     // Set this to 1 to turn on Testing Mode (0 otherwise)

  var oneDay = 24 * 60 * 60 * 1000;  // (milliseconds)
  var oneMonth= oneDay * 30;
  var Left = 0;
  var Top = 0;

  var expDate = new Date( );
  expDate.setTime( expDate.getTime( ) + oneDay * 10 ); // Expires in Ten Days

  // ----- DO NOT MODIFY BELOW THIS LINE ------

  var agent = navigator.userAgent;
  if ( agent.indexOf( 'Mozilla' ) != -1 ) { // almost all browsers send this

    // only select users who haven't seen the popup recently.
    if ( (( ! HasLoginCookie() ) && HasUserTypeCookie() != 'subscribed') || Debug ) {
	    if ( ( ! HasSurveyCookieForMandM() ) || Debug ) {
	
	      // only select a percentage of those potential users.
	      var theDate = new Date( );
	      if ( ( theDate.getTime( ) % 100 ) < PERCENT ) {
	
	        // try to set the cookie.
	        document.cookie = 'ForMandM=true; expires=' +
	                          expDate.toGMTString( ) + '; path=/';
	
	        // if they accepted the cookie; give them the popup!
	        if ( HasSurveyCookieForMandM( ) ) {
	          window.open( URL, 'SurveyForMediaAndMarketingPopUp',
	                       'toolbar=no,location=no,directories=no,' +
	                       'status=no,scrollbars=no,menubar=no,' +
	                       'width=' + Width + ',height=' + Height + ',top=' + Top + ',left=' + Left);
	        }
	      }
	    }
	}    
  }
}

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 GetUBID (ubid) {

	var str = ubid;
	if(str == null) return "";	
	var end=(str.indexOf("!"));
	
	if (end == "0" || end == "") {
		
		return "";
		
	} else {
		
		return escape(str.substring(0,end));
	}

}

// Assign UBID value to userid
var userid = GetUBID(GetCookie("UBID"));

	
function HasSurveyCookie( ) {
  var idx = parseInt( document.cookie.indexOf( 'survey' ) );
  return ( idx > -1 );
}

function HasSurveyCookieForHealth( ) {
  var idx = parseInt( document.cookie.indexOf( 'ForHealth' ) );
  return ( idx > -1 );
}

function HasSurveyCookieForMandM( ) {
  var idx = parseInt( document.cookie.indexOf( 'ForMandM' ) );
  return ( idx > -1 );
}

function HasLoginCookie( ) {
  var idx = parseInt( document.cookie.indexOf( 'WSJIE_LOGIN' ) );
  return ( idx > -1 );
}

function HasUserTypeCookie(){

// this function sees if the the user_type is subscribed
var usertypepos= parseInt(document.cookie.indexOf('user_type='));
var value = "";
if (usertypepos !=-1){
	var valstart = usertypepos + 10; //start of the cookie value
	var valend = parseInt(document.cookie.indexOf(";",valstart));
	if (valend == -1) end = document.cookie.length;
	value = document.cookie.substring(valstart, valend);
	value = unescape(value);
	
	}
	
return value;

}

function setCookie(name, value, expire) {
   document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString() + "; domain=.wsj.com";
}
// END home_popup section

//START lib_Hide_Module_Javascript section
			var selEdWindow;
		  	function hideConfirmation(category) {
				re = / /g;	
		     	category = category.replace(re,"+");
				var setURL = "/setup/hide_confirmation?category=" + category
				selEdWindow = window.open(setURL,'newwin','height=260,width=310,status=yes,menubar=no,scrollable=no,resizable=no,top=100,left=300')
  			}
//END lib_Hide_Module_Javascript section

<!-- Begin Generic Popup
function GenericPopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480');");
}
// End -->



//start REUTERS link section
function NewWindow(mypage, myname, w, h, scroll) {
var winl = 100;
var wint = 100;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
win = window.open(mypage, myname, winprops);
win.window.focus();
}
//end REUTERS link section



	// Added by WFK, 04/23/2001
	// Personal Journal, Define the default field to receive focus on rendering
	function PJ_SetDefaultFocus () {
		// alert ('We are in PJ_SetDefaultFocus test value = ' + document.myForm.category.value);
		if (document.myForm != null) {
			if (document.myForm.category != null) {
				switch (document.myForm.category.value) {
					case "Columns":	{	document.myForm.companyList.selectedIndex = 0;
										document.myForm.companyList.focus();
										break;
									}
					case "Companies":	{	document.myForm.companyfund_1.selectedindex = 0;
											document.myForm.companyfund_1.focus();
											break;
										}
					case "Industries":	{	document.myForm.companyList.selectedIndex = 0;
											document.myForm.companyList.focus();
											break;
										}
					case "Layout":	{	document.myForm.myLayout.selectedIndex = 0;
										document.myForm.myLayout.focus();
										break;
									}
					case "Markets":	{	document.myForm.companyList.selectedIndex = 0;
										document.myForm.companyList.focus();
										break;
									}
					case "Topics":	{	document.myForm.companyList.selectedIndex = 0;
										document.myForm.companyList.focus();
										break;
									}
					default: break;
				}
			}
		}
	}
//END lib_Onload_Javascript section

//START lib_Dropdown_Nav_Javascript section
function update_frame(myoptions) 
{
destination=myoptions[myoptions.selectedIndex].value;
if(destination=="null")
{
return true;
}
window.open(destination, '_top');
myoptions.selectedIndex=0;
return true;
}
//END lib_Dropdown_Nav_Javascript section

function HasSunAdCookie( ) {
  var idx = parseInt( document.cookie.indexOf( 'sunad' ) );
  return ( idx > -1 );
}

function DisplaySunPopup () {
	var Height  = 412;
	var Width   = 545;
	IE=(navigator.appName.substring(0,9)=="Microsoft")?true:false;
	NS6=(navigator.userAgent.indexOf("Netscape6")>0)?true:false;
	if(NS6==true){
	  Width=545
	  Height=412
	}else if(IE!=true){
	  Width=539
	  Height=420
	}else{
	  Width=545
	  Height=412
	}	
	var Left = 400;
	var Top = 0;
	var URL     = "/wsjgate?source=sunsite&URI=/public/microsite_sun/main_frameset.htm&force=y"; // URL of new Window
	
	if ( HasSunAdCookie( ) ) {
	  window.open( URL, 'InfoCenter',
	               'toolbar=no,location=no,directories=no,' +
	               'status=no,scrollbars=no,menubar=no,' +
	               'width=' + Width + ',height=' + Height + ',top=' + Top + ',left=' + Left);
	}
}

function getDist(obj,isTop)
{
	var acum = 0;
	while(obj.tagName != "BODY")
	{
		acum += isTop ? obj.offsetTop : obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return acum;
}
function resizeSlider() 
{
		if((document.all.sliderSplash) && (document.all.sliderSplash.style.pixelWidth >0))
		{
			document.all.sliderSplash.style.left=getDist(window.top.document.all.iframe4,false);
			document.all.sliderSplash.style.pixelWidth=document.all.iframe4.style.pixelWidth;
		}
		if((document.all.sliderOpen) && (document.all.sliderOpen.style.pixelWidth >0))
		{
			document.all.sliderOpen.style.pixelWidth=document.all.iframe4.style.pixelWidth;
			document.all.sliderOpen.style.left=getDist(window.top.document.all.iframe4,false);
			blueBar=90;
			iframeTop=getDist(document.all.iframe4,true);
			height=iframeTop-blueBar+250;
			if(height<540)
				height=540
			document.all.sliderOpen.style.height=height;
		}
}
fileNOTloaded = false;
window.onresize=resizeSlider;
DisplaySunPopup

//start exit popup section

document.onmousedown = isJournalURL;
var suppress_popup = false;

if(document.captureEvents) {
	document.captureEvents(Event.MOUSEDOWN);
 }
		
function isJournalURL(e){
//alert("isJournalURL")
	var re = /wsj.com/;

	if (!e) var e = window.event;


	if (e.srcElement) {
		if (re.test(e.srcElement.href)) suppress_popup = true;
	} else if (e.target.parentNode) { 
		if (re.test(e.target.parentNode)) suppress_popup = true;
	} else {
		if (re.test(e.target)) suppress_popup = true;
	}
}

function exitPopup() {

     var exitPath = /public\/us/; 
     var Height   = 477;
     var Width    = 374;
     var Top      = 0;
     var Left     = 0;

       
	if(!suppress_popup && !HasLoginCookie() && 
		(HasUserTypeCookie() != 'subscribed') &&
		(exitPath.test(document.location))) {
		var URL = 'http://public.wsj.com/creative8.html';
		var newwindow = window.open(URL, 'Farewell',
	                       'toolbar=no,location=no,directories=no,' +
	                       'status=no,scrollbars=no,menubar=no,' +
	                       'width=' + Width + ',height=' + Height + ',top=' + Top + ',left=' + Left);
	}
}
