
/**
 * correctly handle PNG transparency in Win IE 5.5 & 6.
 */
function correctPNG()
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (version < 7.0) && (document.body.filters))
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i];
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG" && img.className && img.className.indexOf("png-image") != -1)
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML;
            i = i-1;
         }
      }
   }
}
/**
 * Set the select values
 * @param invForm the inventory form name
 * @param selectName the select box name
 * @param setValue the select box value
 * @param optionProperty the select box property
 */
function selectValue(invForm,selectName,setValue,optionProperty)
{
  var options = document.forms[invForm][selectName].options;
  for(var i = 0; i < options.length; i++)
  {
    var optionValue = options[i][optionProperty];
    if(optionValue == setValue)
    {
      document.forms[invForm][selectName].selectedIndex = i;
      return true;
    }
  }
  return false;
}

/**
 * Returns an object for current page dimension, that includes height and width of the page.
 */
function getPageDimensions()
{
    var pageHeight;
    var pageWidth;

	if (window.innerHeight && window.scrollMaxY) // For Firefox
	{
		pageHeight = window.innerHeight + window.scrollMaxY;
		pageWidth = window.innerWidth + window.scrollMaxX;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) // For all but Explorer Mac
	{
		pageHeight = document.body.scrollHeight;
		pageWidth = document.body.scrollWidth;
	}  // For Explorer 6 Strict, Mozilla (not FF) and Safari
	else
	{
		pageHeight = document.body.offsetHeight;
		pageWidth = document.body.offsetWidth;
  	}

	return { height: pageHeight, width: pageWidth };
}
/** 
 * To change the class of iframe container div(page-core-container) to custom-html-page-core-container(of width 966px), if the included iFrame is of width 966px;. 
 */
function setCustomHTMLContainerWidth(){
  var customPageContainer = document.getElementById('page-core-container');
  for(var i=0; i<customPageContainer.childNodes.length;i++){
    if(customPageContainer.childNodes[i].tagName=='IFRAME' & customPageContainer.childNodes[i].offsetWidth=="966"){
      customPageContainer.className = "custom-html-page-core-container";
      customPageContainer.style.height = "auto";
      break;
    }
  }
}


/**
 * Function to fire an explicit omniture call.
 * Requires: s_code.js to be included
 */
function fireOmnitureEventToS1() {
    // test id not null
    if (s !== null) {
        // t is defined in the Omniture API, if any event is to be appended
        // to the event already defined on the page then it should be passed as
        // an argument
        // to it. This is not required in the current specs.
        s.tl(this, 'o', s.prop5);
    }
}
/**
 * Fire Omniture Events with Page name as Pev2 Value
 * @return
 */
function fireOmnitureEventToRE() {
    // test id not null
    if (s !== null) {
        // t is defined in the Omniture API, if any event is to be appended
        // to the event already defined on the page then it should be passed as
        // an argument
        // to it. This is not required in the current specs.
        s.tl(this, 'o', s.pageName);
    }
}
/**
 * Fucntion to track links from modelshowroom page
 * Params: pageType, modelYear, make and modelName
 * @param pageType the page type
 * @param modelYear the vehile mode year
 * @param make the vehicle make
 * @param modelName the vehicle model name
 */
function omnitureCallBP(pageType, modelYear, make, modelName)
{
  if (s !== null) {
    s.templtv= s.linkTrackVars;
    s.linkTrackVars='hier1,eVar1,prop1,eVar5,prop5,eVar12,prop12,channel,eVar3,prop3,eVar2,prop2,eVar4,prop4,eVar14,prop14,eVar15,prop15,eVar16,prop16';
    var isShowroomPage = (pageType == "new");
    // add param
    s.hier1 = isShowroomPage ? "dc: showroom: new" : "dc: shopping tools: new: model details";
    s.prop5 = isShowroomPage ? "dc: build and price: new" : "dc: build and price: model details";
    s.eVar12 = modelYear;
    s.prop12 = modelYear;
    s.eVar5 = "new";    // add new to param 
    s.channel = "new";     // set home to ch
    s.eVar3 = s.prop3;
    s.prop16 = s.eVar16 = make + " " + modelName;
    s.prop12 = modelYear;
    fireOmnitureEventToS1();    //call fire omnitur event
    if(s.templtv){
      s.linkTrackVars=s.templtv;
    }
  }
}

/**
 * Fucntion to track links from embedded SWF
 * Params: model, make and year
 * @param model the vehicle model
 * @param make the vehile make
 * @param year the vehicle make year
 */
function omnitureCallFromFlashBP(model, make, year)
{
  if (s !== null) {
    s.templtv= s.linkTrackVars;
    // link the required params
    s.linkTrackVars='hier1,eVar1,prop1,eVar5,prop5,eVar12,prop12,channel,eVar3,prop3,eVar2,prop2,eVar4,prop4,eVar9,prop9,eVar14,prop14,eVar15,prop15,eVar16,prop16';
    s.hier1 = "dc: shopping tools: home";
    //add new to param
    s.eVar5 = "new";
    s.prop5 = "dc: build and price: home";
    // set home to ch
    s.channel = "home";
    s.eVar3 = s.prop3;
    s.prop16 = s.eVar16 = make + " " + model;
    s.eVar12 = year;
    s.prop12 = year;
    //call fire omnitur event
    fireOmnitureEventToS1();
    if(s.templtv){
      s.linkTrackVars=s.templtv;
    }
  }
}

/**
 * Function to fire an explicit omniture call.
 * Requires: s_code.js to be included
 */
function fireOmnitureEvent() {
  if (s !== null) {
    // t is defined in the Omniture API, if any event is to be appended 
    // to the event already defined on the page then it should be passed as an
    // argument to it. This is not required in the current specs.
    s.t("");
  }
}

/**
 * forward reference the global object MetricsManager. see MetricsManager.js
 * for details.
 */
var MetricsManager;

/**
 *  save the current omnitureState with stateId.
 */
function saveOmnitureStateIfEnable(stateId)
{
   if(MetricsManager)
   {
      MetricsManager.saveState(stateId);
   }
}

/**
 *  restore the current omnitureState with stateId.
 */
function restoreOmnitureStateIfEnable(stateId)
{
   if(MetricsManager)
   {
      MetricsManager.restoreState(stateId);
   }  
}

/**
 * 
 * @param prop5
 * @param channel
 * @return
 */
function onClickFireOmnitureTags(prop5, channel) {
  saveOmnitureStateIfEnable(prop5 + channel);
  
  if (s !== null) {
    s.templtv = s.linkTrackVars;
    s.linkTrackVars = 'channel,eVar1,eVar2,eVar3,eVar4,eVar12,eVar14,eVar15,eVar16,prop1,prop2,prop3,prop4,prop5,prop12,prop14,prop15,prop16';
    s.pageName = prop5;
    s.channel = channel;
    s.prop5 = prop5;
    s.eVar3 = s.prop3;
    fireOmnitureEventToS1();
    if(s.templtv){s.linkTrackVars=s.templtv;}
  }  
  
  restoreOmnitureStateIfEnable(prop5 + channel);
}

/**
 * 
 * @param prop5
 * @param channel
 * @return
 */
function onClickFireOmnitureForReferralExit(prop5, channel) {
  if (s !== null) {
    s.templtv = s.linkTrackVars;
    s.linkTrackVars = 'channel,eVar1,eVar2,eVar3,eVar4,eVar5,eVar6,eVar12,eVar14,eVar15,eVar16,prop1,prop2,prop3,prop4,prop5,prop6,prop12,prop14,prop15,prop16';
    s.templte = s.linkTrackEvents;
    s.linkTrackEvents = 'event4';
    s.pageName = prop5;    //assign track event vars
    s.channel = channel;
    s.eVar6 = s.prop5 = "referral: tier2-isis offer";
    s.prop5 = s.prop6 = s.eVar6;
    s.eVar5 = 'both';
    s.eVar3 = s.prop3;
    s.events = "event4";
    s.linkTrackVars += ',events';
    fireOmnitureEventToRE();
    if(s.templtv){s.linkTrackVars=s.templtv;}
    if(s.templte){s.linkTrackEvents=s.templte;}
  }  
}
