﻿
var imageDir = "/charts/historic/";
var intraDir = "/charts/public/intraday/";
var iconDir = "/images/buttons/";
var browserVer;
var dispImage = "display";
var dispImageIntra = "displayIntra";
var currentPeriod = "12";
var currentRef = null;

browserVer = 2;
agent = navigator.userAgent;
if (agent.substring(0,7) == "Mozilla") {
    if (parseInt(agent.substring(8,9)) >= 3) {browserVer = 1;}
}

function changeImage(security, period, refplot) {
   if (browserVer != 1) {
      // Skip the script
      return true;
   };

   swapImage("icn_1mnd", iconDir + "icn_1mnd_g.gif");
   swapImage("icn_3mnd", iconDir + "icn_3mnd_g.gif");
   swapImage("icn_6mnd", iconDir + "icn_6mnd_g.gif");
   swapImage("icn_12mnd", iconDir + "icn_12mnd_g.gif");
   swapImage("icn_24mnd", iconDir + "icn_24mnd_g.gif");
   swapImage("icn_36mnd", iconDir + "icn_36mnd_g.gif");
   swapImage("icn_60mnd", iconDir + "icn_60mnd_g.gif");
   swapImage("icn_120mnd", iconDir + "icn_120mnd_g.gif");
   swapImage("icn_180mnd", iconDir + "icn_180mnd_g.gif");

   swapImage("icn_intradag", iconDir + "icn_intradag_g.gif"); 	
   swapImage("icn_totx",  iconDir + "icn_totx_g.gif");

   var refpostfix = "";

   if(refplot != null) {
   	if(refplot == currentRef) {
	   refplot = null;
        }
	currentRef = refplot;
   } else {
	refplot = currentRef;
   }

   if(refplot != null) {
	swapImage("icn_totx", iconDir + "icn_totx.gif");
        refpostfix = "-"+refplot;
   }

   if(period == null) {
	period = currentPeriod;
   }

   if(period != "intra") {
     swapImage(dispImage, imageDir + security + "-" + period + refpostfix + ".png");
     swapImage("icn_" + period + "mnd", iconDir + "icn_" +period + "mnd.gif");
     //update intraday as well if refplot has been chosen
     swapImage(dispImageIntra, intraDir + security + refpostfix + ".png");	
   }  
   else {
     swapImage(dispImage, intraDir + security + refpostfix + ".png");	
     swapImage("icn_intradag", iconDir + "icn_intradag.gif");	
   }

   currentPeriod = period;
   return false;							                
};

function swapImage(imgObjName, imgSrc) {
   if (typeof document.images[imgObjName] != "undefined") {
     document.images[imgObjName].src = imgSrc;
   };
};
