//Test for browser compatibility

bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
    if ((bName == "Netscape" && bVer >= 3) |(bName == "Microsoft Internet Explorer" && bVer >= 4))
        browser = "compatible";
    else browser = "incompatible";

function setMenu(currTopItem) {        
    // Keep this function. Though it is doing anything.
    // At least it will not through a javascript error in cace anyone call this function.
}
// Code for Pop-up Browser window

function popRemote(winurl,winname,winfeatures)
{
    if (winfeatures == null){
      //var scrheight = window.screen.height;
      //var scrwidth = window.screen.width;
      //winfeatures = 'WIDTH=' + scrwidth/2 + ',HEIGHT=' + scrheight/2 + ',SCROLLBARS=1,RESIZABLE=1,DIRECTORIES=0,menubar=0,screenX=' + scrwidth/4 + ',screenY=' + scrheight/4 + ',LEFT=' + scrwidth/4 + ',TOP=' + scrheight/4 ;

      var scrheight = 500;
      var scrwidth = 720;
      winfeatures = 'WIDTH=' + scrwidth + ',HEIGHT=' + scrheight + ',SCROLLBARS=1,RESIZABLE=1,DIRECTORIES=0,menubar=0,screenX=' + scrwidth/4 + ',screenY=' + scrheight/4 + ',LEFT=' + scrwidth/4 + ',TOP=' + scrheight/4 ;

    }

    var newwin = window.open(winurl,winname,winfeatures);
    newwin.focus();
}

function popRemote2(winurl,winname,winfeatures)
{
    if (winfeatures == null){
      var scrheight = 500;
      var scrwidth = 720;
      winfeatures = 'WIDTH=' + scrwidth + ',HEIGHT=' + scrheight + ',SCROLLBARS=1,RESIZABLE=1,DIRECTORIES=0,menubar=0,screenX=' + scrwidth/4 + ',screenY=' + scrheight/4 + ',LEFT=' + scrwidth/4 + ',TOP=' + scrheight/4 ;
    }

    var newwin = window.open(winurl,winname,winfeatures);
    newwin.focus();
    return false;
}

function popPostalStore(winurl,winname,winfeatures,opener)
{
    document.cookie = "testForCookieEnablement=true";
    var cookiesAreEnabled = (document.cookie != "");

    if (cookiesAreEnabled != true) // Forward to the browser preferences page.
    {
      winurl = "http://shop.usps.com/cgi-bin/vsbv/postal_store_non_ssl/customer_care/browserPreferences.html";
    }

    var newwin;
    newwin = window.open(winurl,winname,winfeatures);
    newwin.focus();
}

//End Code for Pop Browser window

// ----------------------------------------------------------------------------------------------------------------------------------------
// This section contains miscellaneous browser related routines and variables.
// You DON'T need to make any changes to this file.
// ----------------------------------------------------------------------------------------------------------------------------------------

var browserName      = "";
var browserVersion   = "";
var browserWidth     = 0;
var browserHeight    = 0;
var browserSupported = true;

   detectBrowser ();
   detectBrowserSize ();
//   testBrowserVersion ();

// ----------------------------------------------------------------------------------------------------------------------------------------
// detects browser name and version
// ----------------------------------------------------------------------------------------------------------------------------------------

function detectBrowser ()
{
	browserName = navigator.appName;

        if (navigator.userAgent.indexOf ("Opera/") > -1)
        {
                browserName = "Opera";
                var index = navigator.userAgent.indexOf ("Opera/");
                browserVersion = extractBrowserVersion (navigator.userAgent.substring (index + 6));
        }

	else if (navigator.userAgent.indexOf ("Opera") > -1)
	{
		browserName = "Opera";
		var index = navigator.userAgent.indexOf ("Opera");
		browserVersion = extractBrowserVersion (navigator.userAgent.substring (index + 5));
	}

	else if (navigator.userAgent.indexOf ("MSIE") > -1)
	{
		browserName = "Internet Explorer";
		var index = navigator.userAgent.indexOf ("MSIE");
		browserVersion = extractBrowserVersion (navigator.userAgent.substring (index + 4));
	}

	else if (navigator.vendor == "Netscape6" || navigator.vendor == "Netscape")
	{
		browserName = "Netscape";
		browserVersion = navigator.vendorSub;
	}

	else if (navigator.userAgent.indexOf ("Gecko") > -1)
	{
		browserName = "Mozilla";
		var index = navigator.userAgent.indexOf ("rv:");
		browserVersion = extractBrowserVersion (navigator.userAgent.substring (index + 3));
	}

	else if (navigator.appName.indexOf ("Netscape") != -1)
	{
		browserName = "Netscape";
		var index = navigator.appVersion.indexOf (" ");
		browserVersion = navigator.appVersion.substring (0, index);
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------
// extracts browser version
// ----------------------------------------------------------------------------------------------------------------------------------------

function extractBrowserVersion (browserVersion)
{
	browserVersion = trim (browserVersion);

        var index = navigator.userAgent.indexOf ("Opera/");

        if (index > -1) {
                index = browserVersion.indexOf (" ");
                browserVersion = browserVersion.substring (0, index);
        } else {

	  index = browserVersion.indexOf (";");
	  if (index > -1)
		browserVersion = browserVersion.substring (0, index);
	  else
	  {
		index = browserVersion.indexOf (")");
		if (index > -1)
			browserVersion = browserVersion.substring (0, index);
		else
		{
			index = browserVersion.indexOf (" ");
			if (index > -1)
				browserVersion = browserVersion.substring (0, index);
		}
	  }
	}

	return browserVersion;
}

// ----------------------------------------------------------------------------------------------------------------------------------------
// tests browser name and version
// ----------------------------------------------------------------------------------------------------------------------------------------

function testBrowserVersion ()
{
	if (! ((browserName == "Internet Explorer" && browserVersion >= "4.0") ||
	       (browserName == "Netscape"          && browserVersion >= "4.0") ||
	       (browserName == "Mozilla"           && browserVersion >= "1.0") ||
	       (browserName == "Opera"             && browserVersion >= "5.0")))
	{
		browserSupported = false;
		alert ("Warning, you are using " + browserName + " Version " + browserVersion + "\n"
			+ "The recommended browsers to view this page are:\n"
			+ "- Internet Explorer 4.0 or better\n"
			+ "- Netscape 4.0 or better\n"
			+ "- Mozilla 1.0.1 or better\n"
			+ "- Opera 5.0 or better\n"
		);
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------
// detects browser size
// ----------------------------------------------------------------------------------------------------------------------------------------

function detectBrowserSize ()
{
	if (browserName == "Internet Explorer")
	{
		browserWidth  = document.body.clientWidth; // + document.body.scrollLeft;
		browserHeight = document.body.clientHeight; // + document.body.scrollTop;

		if (browserVersion >= "6.0" && browserHeight < screen.availHeight)
		{
			browserHeight = screen.availHeight;
		}
	}

	else if (browserName == "Netscape" || browserName == "Mozilla" || browserName == "Opera")
	{
		browserWidth = window.innerWidth;
		browserHeight = window.innerHeight;
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------
// This section contains miscellaneous utility functions.
// You DON'T need to make any changes to this file.
// ----------------------------------------------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------------------------------------------
// utility method that trims input string off of blank spaces to left and right.
// ----------------------------------------------------------------------------------------------------------------------------------------

function trim (str)
{
	while (str.length != 0 && isSpace (str.charAt (0))) // trim to the left
		str = str.substring (1, str.length);

	while (str.length > 0 && isSpace (str.charAt (str.length - 1))) // trim to the right
		str = str.substring (0, str.length - 1);

	return str;
}

// ----------------------------------------------------------------------------------------------------------------------------------------
// utility method that checks that the input ASCII code is a blank space (space, tab, new line, or &nbsp;).
// ----------------------------------------------------------------------------------------------------------------------------------------

function isSpace (c)
{
	return (c == ' ' || c == '\t' || c == '\n' || c == '\xA0');
}

// ----------------------------------------------------------------------------------------------------------------------------------------
// utility method that opens a browser window with the proper parameters depending on the browser version.
// ----------------------------------------------------------------------------------------------------------------------------------------
// tested on Netscape 2.02
// tested on Netscape 3.01, 3.01B1, 3.02, 3.03, 3.04
// tested on Netscape 4.03, 4.05, 4.08, 4.5, 4.51, 4.61, 4.7, 4.72, 4.73, 4.74, 4.75, 4.76, 4.77, 4.78, 4.79, 4.8
// tested on Netscape 6.01, 6.1, 6.2, 6.2.1, 6.2.2, 6.2.3
// tested on Netscape 7.0
// tested on Mozilla 1.0.1, 1.1, 1.2B
// tested on Opera 6.05, 7.0
// tested on Internet Explorer 5.0, 5.5, 6.0
// ----------------------------------------------------------------------------------------------------------------------------------------
// BUGS: in Netscape 6.x, if locationbar=1, then resizable can only be 0
// BUGS: in Netscape 2.x and 3.x and 4.x, no space is allowed after the commas
// BUGS: in Netscape 2.x and 3.x, window locations cannot be set
// BUGS: in Netscape 2.x, only unresizable windows can be created
// BUGS: in Opera 6.x, cannot hide menubar
// BUGS: in Opera 6.x, cannot hide toolbar
// BUGS: in Opera 6.x, cannot hide the status bar
// BUGS: in Opera 6.x, hiding location bar also hides all other chrome
// BUGS: in Opera 6.x and 7.x, cannot create non-resizable windows (all windows are resizable)
// BUGS: in Opera 7.x, cannot hide scrollbars if they are needed
// BUGS: in Opera 7.x, the window location is relative to the MDI container instead of the screen
// BUGS: in Opera 7.x, the toolbar is not located in the window
// BUGS: in Opera 7.x, the menubar is not located in the window
// BUGS: in Opera 7.x, there is no statusbar
// ----------------------------------------------------------------------------------------------------------------------------------------

function openWindow (url, name, size, x, y, parent, attributes)
{
	// ----------------------------------------------------------------------------------------------------------------------------------
	// compute location of window relative to parent
	// ----------------------------------------------------------------------------------------------------------------------------------

	if (parent != null && typeof (parent) != "undefined")
	{
		if (browserName == "Internet Explorer")
		{
			x += parent.screenLeft;
			y += parent.screenTop;
		}
		else
		{
			x = x + parent.screenX + parent.outerWidth - parent.innerWidth;
			y = y + parent.screenY + parent.outerHeight - parent.innerHeight;
		}
	}

	// ----------------------------------------------------------------------------------------------------------------------------------
	// create location attributes
	// ----------------------------------------------------------------------------------------------------------------------------------

	var location = "";
	if (browserName == "Netscape")
	{
		location = ",screenX=" + x + ",screenY=" + y;
	}
	else
	{
		location = ",left=" + x + ",top=" + y;
	}

	// ----------------------------------------------------------------------------------------------------------------------------------
	// create and return window
	// ----------------------------------------------------------------------------------------------------------------------------------

	if (attributes != null && attributes != "" && typeof (attributes) != "undefined")
	{
		return window.open (url, name, size + location + "," + attributes);
	}
	else
	{
		return window.open (url, name, size + location);
	}
}

function popPostalStore2_7 (url, name, size, x, y, parent, attributes)
{
	// ----------------------------------------------------------------------------------------------------------------------------------
	// compute location of window relative to parent
	// ----------------------------------------------------------------------------------------------------------------------------------

	if (parent != null && typeof (parent) != "undefined")
	{
		if (browserName == "Internet Explorer")
		{
			x += parent.screenLeft;
			y += parent.screenTop;
		}
		else
		{
			x = x + parent.screenX + parent.outerWidth - parent.innerWidth;
			y = y + parent.screenY + parent.outerHeight - parent.innerHeight;
		}
	}

	// ----------------------------------------------------------------------------------------------------------------------------------
	// create location attributes
	// ----------------------------------------------------------------------------------------------------------------------------------

	var location = "";
	if (browserName == "Netscape")
	{
		location = ",screenX=" + x + ",screenY=" + y;
	}
	else
	{
		location = ",left=" + x + ",top=" + y;
	}
	
	
	//-----------------------------------------------------------------------------------
	//cookie check
	//-----------------------------------------------------------------------------------
	
	document.cookie = "testForCookieEnablement=true";
	var cookiesAreEnabled = (document.cookie != "");

	if (cookiesAreEnabled != true) // Forward to the browser preferences page.
	{
		url = "http://shop.usps.com/cgi-bin/vsbv/postal_store_non_ssl/customer_care/browserPreferences.html";
	}

	// ----------------------------------------------------------------------------------------------------------------------------------
	// create and return window
	// ----------------------------------------------------------------------------------------------------------------------------------

	if (attributes != null && attributes != "" && typeof (attributes) != "undefined")
	{
		return window.open (url, name, size + location + "," + attributes);
	}
	else
	{
		return window.open (url, name, size + location);
	}
}
