// browser detection
function browserStats() {
  var ua = " " + navigator.userAgent.toLowerCase();
  this.nn = ua.indexOf( "mozilla" ) > 0;
  ua.indexOf( "compatible" ) > 0 ? this.nn = false : "";
  this.ie = ua.indexOf( "msie" ) > 0;
  this.version = parseInt( navigator.appVersion );
  this.mac = ua.indexOf( "mac" ) > 0;
  this.ie ? ua.indexOf( "msie 5" ) > 0 ? this.version = 5 : "" : "";
  return this;
}

var b = new browserStats();


// browser/platform font size cascade
var cssPath = prefix + "css/", cssFile;
b.mac && b.nn && b.version >= 5 ? cssFile = "half_size_smaller.css" : b.mac && b.version >= 5 || !b.mac && b.ie || b.nn && b.version >= 5 ? cssFile = "one_size_smaller.css" : cssFile;
cssFile ? document.write( '<link rel="stylesheet" href="' + cssPath + cssFile + '" type="text/css" />' ) : "";


// netscape browser resize fix
if( b.nn ) {widthCheck = window.innerWidth;heightCheck = window.innerHeight;window.onresize = resizeFix;}

function resizeFix() {widthCheck != window.innerWidth || heightCheck != window.innerHeight ? window.location.reload( true ) : "";}

var wrapMsg = "";
wrapMsg += 'The contents in the current "Build Your Own" window will be erased   \n';
wrapMsg += 'and a new session will be started. Click OK to continue and restart,\n';
wrapMsg += 'or Cancel to retain the contents of the window.';
var pandeWindow = null;
var universalWindow = null;

function wrap(argApp, argTracking, argFamily, argModel) {
  argApp = argApp.toLowerCase();
  var launchUrl = "/bridge/index.html?";
  if( argTracking != '' ) launchUrl += argTracking + "&";
  launchUrl += "app=" + argApp + "&family=" + argFamily + "&model=" + argModel;

  if( argApp == "priceequip" ) {
    if( b.ie && b.mac && b.version < 5 ) {
      openit( argApp, launchUrl );
    } else {
      if( pandeWindow && !pandeWindow.closed ) {
        if( confirm( wrapMsg ) ) {
          pandeWindow.focus();
          window.pandeWindow.location = launchUrl;
        } else {
          pandeWindow.focus();
        }
      } else {
        openit( argApp, launchUrl );
      }
    }
  } else {
    openit( argApp, launchUrl );
  }
  
  // nested function
  function openit( argApp, launchUrl ) {
    var winWidth = 618, winHeight = 452;    
    if( argApp == "priceequip" || argApp == "myfolder" || argApp == "vehicleselector" || argApp == "vehiclespecs" || argApp == "preownedinventory" || argApp == "gap" )
      winWidth = 790;
    if( window.screen && argApp == "priceequip" || argApp == "myfolder" || argApp == "vehicleselector" || argApp == "vehiclespecs" || argApp == "preownedinventory" || argApp == "gap" )
      winHeight = ( window.screen.availHeight - 130 );
    var options = "resizable,scrollbars,toolbar,"
    
    //var options = "resizable, scrollbars,";
    //if( argApp != "priceequip" ) options += "toolbar,";
    
    options += "width=" + winWidth + ",height=" + winHeight;
    if( window.screen ) {
      var xPos = ( screen.availWidth - winWidth ) / 2;
      var yPos = ( ( screen.availHeight - winHeight ) / 2 ) - 40;
      options += ",left=" + xPos + ",screenX=" + xPos;
      options += ",top=" + yPos + ",screenY=" + yPos;
    }
    if( argApp == "priceequip" ) pandeWindow = window.open( launchUrl, "priceequip", options );
      else if( argApp == "dealer" ) window.location = launchUrl;
      else universalWindow = window.open( launchUrl, "universal", options );
  }
  // end nested function
}

function askWin() {
  var winWidth = 611, winHeight = 448;
  var options = "resizable,scrollbars,toolbar,"
    options += "width=" + winWidth + ",height=" + winHeight;
  if( window.screen ) {
      var xPos = ( screen.availWidth - winWidth ) - 20;
      var yPos = ( ( screen.availHeight - winHeight ) / 2 ) - 40;
      options += ",left=" + xPos + ",screenX=" + xPos;
      options += ",top=" + yPos + ",screenY=" + yPos;
    }
  window.open( "", "askWindow", options );
  return true;
}
