/* Path for this file: /content/dam/nissan/codepack/nissan/components/pages/layout/mainlayout.js/jcr:content/renditions/original */
// these were pulled from main JS file into mainlayout.js
/*
jQuery(document).ready(function() {
    if(jQuery("#frameBg").size()>0){
        //jQuery("#frameBg").height(jQuery("#frameContent").height()+20);
    }
    jQuery("#frameContent").click(function(){
        //jQuery("#frameContent").html(jQuery("#frameContent").html()+"<br /><br />");
        //resizeMe(jQuery("#frameContent").height());
    });    
});
function resizeMe(hgt){
    if(jQuery("#frameBg").size()>0){
        jQuery("#frameBg").height(hgt+20);
        if(jQuery("#frameContent").height() + 50 > jQuery("#pageBg").height()){
            //jQuery("#pageBg").height(jQuery("#pageBg").height()+20);
        }
    }
}
*/

jQuery(document).ready(function() {
    if(jQuery.browser.msie && parseInt(jQuery.browser.version) === 6) jQuery('#frameBg + #frameContent').addClass('frameContentHasBg');
 
    if(jQuery("#frameContent").height() + 50 > jQuery("#pageBg").height()){         
            jQuery("#pageBg").css("margin-bottom","50px");
        }
    
});


//added popExtSwf() function as per SR 17191
// Open External swf in new window
// Argument swfName, querystr, width and height are required, the others optional
// Usage: <a href="#" onclick="return popExtSwf('mySwf.swf', 'a=b', 600, 400, 'myWin', 'resizeable=no,location=no')">
function popExtSwf(swfName, querystr, width, height, title, params){
  var features = "";
  var myurl = '/html/popSwf.html?swfname=' + swfName;
  var isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != -1);

  if (width) {
    var winWidth = width;
    if(isSafari) winWidth += 20;    // hack to enlarge window for Safari
    features += "width=" + winWidth + ",left=" + Math.floor( (screen.width - width) / 2);
    myurl += '&width=' + width;
  }

  if (height) {
    var winHeight = height;
    if(isSafari) winHeight += 20;   // hack to enlarge window for Safari
    features += ",height=" + winHeight + ",top="+Math.floor( (screen.height - height) / 2);
    myurl += '&height=' + height;
  }

  if (querystr) {
    myurl += '&' + querystr;

    var qsSrc = getStringParam(querystr, 'src');
    if (qsSrc != '')
      myurl += '&Model=' + qsSrc;
  }

  if (title) myurl += '&title=' + escape(title);
  if (params) features += ","+params;
  var winname = name ? name : "nissanusa_ext";
  window.open(myurl, winname, features);
}
// Return a value from the query string
function getQueryParam(paramName) {
    var qString = location.search.substring(1);
    if (qString.indexOf(paramName) == -1) return '';
    var pValueStart = qString.indexOf(paramName) + paramName.length + 1;
    var pValueEnd = qString.indexOf('&', pValueStart);
    if ( pValueEnd==-1 ) pValueEnd = qString.length;
    return unescape( qString.substring( pValueStart,pValueEnd ) );
}
// Return a querystring-formatted value from a string
 
function getStringParam(searchString, paramName) {

    if (searchString.indexOf(paramName) == -1) return '';

    var pValueStart = searchString.indexOf(paramName) + paramName.length + 1;

    var pValueEnd = searchString.indexOf('&', pValueStart);

    if ( pValueEnd==-1 ) pValueEnd = searchString.length;

    return unescape( searchString.substring( pValueStart,pValueEnd ) );

}


