//###See gg_shareprice.js for all config options
setDefaultsForMaxFeatures();

//###Start Config Values.
tooltipsHTMLBefore = '<table border="0" cellspacing="1" cellpadding="2" style="background-color: #1E8FBF"><tr><td style="font-family: Arial, sans-serif; font-size:11px; background-color: #FFFFFF; color: #1E8FBF"><nobr>'//style the tooltips
tooltipsHTMLAfter = '<span id="tooltipsDivWidthFinder" style="position:relative; left:0px; top:0px; width:0px; height:0px; z-index:5; visibility:visible;"></span></nobr></td></tr></table>'


function ggPageOnload(){
  //not this is a poor test but basically we assume if there is no index comparatoe then there will
  //be no comparators at all.
  if(document.chartForm.theIndex){
    setComparisonsSelected();
    setIndexSector();
  }
  //All page specific onloads must go in here. This is called by onloadAllGG()
}

//NOTE::No need to set up comparisons anymore as long as they are named comparison1, comparison2 etc...

loadedCompName1 = ''
loadedCompName2 = ''
loadedCompName3 = ''
loadedCompName4 = ''
loadedCompId1 = ''
loadedCompId2 = ''
loadedCompId3 = ''
loadedCompId4 = ''

findTO = false
function setComparisonsSelected(){
  for(i=0;i<comparatorsArray.length;i++){
      eval('document.chartForm.isCoyid'+(i+1)+'.value = "'+comparatorsArray[i][0] + '"')
      eval('document.chartForm.isComp'+(i+1)+'.value = "'+comparatorsArray[i][1] + '"')
      eval('loadedCompName'+(i+1)+' = "'+comparatorsArray[i][1]+'"')//These two create variables used by stopCompXSelection
      eval('loadedCompId'+(i+1)+' = "'+comparatorsArray[i][0]+'"')
    }
}
function getComparisons(){
  var comparisons = "";

  //not this is a poor test but basically we assume if there is no index comparatoe then there will
  //be no comparators at all.
  if(document.chartForm.theIndex){
    if(document.chartForm.theIndex.value != ""){comparisons += document.chartForm.theIndex.value + "@IT"}
    if(document.chartForm.theSector.value != ""){if(comparisons != ""){comparisons += ","} comparisons += document.chartForm.theSector.value + "@GRP"}
    if(document.chartForm.isCoyid1.value != ""){if(comparisons != ""){comparisons += ","} comparisons += document.chartForm.isCoyid1.value}
    if(document.chartForm.isCoyid2.value != ""){if(comparisons != ""){comparisons += ","} comparisons += document.chartForm.isCoyid2.value}
    if(document.chartForm.isCoyid3.value != ""){if(comparisons != ""){comparisons += ","} comparisons += document.chartForm.isCoyid3.value}
    if(document.chartForm.isCoyid4.value != ""){if(comparisons != ""){comparisons += ","} comparisons += document.chartForm.isCoyid4.value}
  }
  if(comparisons != ""){comparisons = '&comparisons=' + comparisons}
  return comparisons    
}

function findCompany(whichComp){
  if (eval('document.chartForm.isComp'+whichComp+'.value').length > 2) {
  clearTimeout(findTO)
  clearHelpMsg()
  findWin = this.open("/companies/company-chart-find.do?search="+escape(eval('document.chartForm.isComp'+whichComp+'.value')), "findWindow", "toolbar=no,menubar=no,height=500,width=400,location=no,scrollbars=yes,resizable=no,status=no,left=100,top=100");

  changingWhichComp = whichComp
  }
  else {
	  alert('Please enter more than 2 characters')
  }
}

function receiveDetails(coyid,name){
  theCoyid = coyid
  theCompName = name
  eval('document.chartForm.isCoyid'+changingWhichComp+'.value = unescape(theCoyid)')
  eval('document.chartForm.isComp'+changingWhichComp+'.value = unescape(theCompName)')
  eval('doShowTempComp'+changingWhichComp+' = true')
  eval('hasCompName'+changingWhichComp+' = true')
  self.location.hash = 'hasherrorDiV'
  doHelpMsg('Please click &#145;Draw Graph&#146; to obtain company data')
}

function getCoyid(theString){
  theStringSplit = theString.split('@')
  return theStringSplit[0]
}

function stopCompXSelection(theCompNum){
  if(eval('document.chartForm.isComp'+theCompNum+'.value == loadedCompName'+theCompNum)){
    clearHelpMsg()
    eval('document.chartForm.isCoyid'+theCompNum+'.value = loadedCompId'+theCompNum)
  } else {
    eval('document.chartForm.isCoyid'+theCompNum+'.value = ""')
    if(eval('document.chartForm.isComp'+theCompNum+'.value != ""')){
      findMessageTimeout()
    } else {
      clearHelpMsg()
    }
  }
  eval('document.chartForm.isComp'+theCompNum+'.focus()')
}
function setIndexSector(){
  var tmpComparatorsArray = new Array()
  var indexArray = new Array()
  var sectorArray = new Array()
  var selectedIndexVal = ""
  var selectedSectorVal = ""

  selectedComparitors = comparisonsParam
  tmpComparatorsArray = selectedComparitors.split(",")
  for(i=0;i<tmpComparatorsArray.length;i++){
    if(tmpComparatorsArray[i].indexOf("@IT") != -1){
      indexArray = tmpComparatorsArray[i].split("@")
      selectedIndexVal = indexArray[0]
    }
    if(tmpComparatorsArray[i].indexOf("@GRP") != -1){
      sectorArray = tmpComparatorsArray[i].split("@")
      selectedSectorVal = sectorArray[0]
    }
  }   
  if(selectedIndexVal != ""){
    for(i=0;i<document.chartForm.theIndex.options.length;i++){
      if(document.chartForm.theIndex.options[i].value == selectedIndexVal){
        document.chartForm.theIndex.options[i].selected = true
        break
      }
    }
  }else{
    document.chartForm.theIndex.options[0].selected = true
  }

  if(selectedSectorVal != ""){
    for(i=0;i<document.chartForm.theSector.options.length;i++){
      if(document.chartForm.theSector.options[i].value == selectedSectorVal){
        document.chartForm.theSector.options[i].selected = true
        break
      }
    }
  } else {
    document.chartForm.theSector.options[0].selected = true
  }
}
function findMessageTimeout(){
  findTO = setTimeout("doHelpMsg('Please click &#145;Find&#146; to verify this company')",200)
}
function clearHelpMsg(){
  writeToDiv('errorDiv','')
}
function doHelpMsg(whatText){
  writeToDiv('errorDiv',whatText)
}
function changedIndex(t){
  if(t.options[t.options.selectedIndex].value != ''){
    doHelpMsg('Please click &#145;Draw Graph&#146; to obtain index data')
  } else {
    clearHelpMsg()
  }
}
function changedSector(t){
  if(t.options[t.options.selectedIndex].value != ''){
    doHelpMsg('Please click &#145;Draw Graph&#146; to obtain sector data')
  } else {
    clearHelpMsg()
  }
}
