//###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 submitForm(){
  needToCorrectDate = false;
  newUrl=returnUrlStart();
  newUrl+=returnDefaultIdentifier();
  var period = document.chartForm.period.options[document.chartForm.period.options.selectedIndex].value;
  if (period == "-") {
    returnCorrectDateStr = returnCorrectDateFormItems('from','to','/');
    if(returnCorrectDateStr){
      newUrl += returnCorrectDateStr;
      newUrl += getReturnPeriod();
    } else {
      needToCorrectDate = true;
    }
  } else {
    newUrl += '&period=' + period;
  }
  if(!needToCorrectDate){
    newUrl += getFormParams();
    goToGraphURL(newUrl);
  }
	return false;
}

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 = ''
loadedCompId1 = ''

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.isCoyid1.value != ""){if(comparisons != ""){comparisons += ","} comparisons += document.chartForm.isCoyid1.value}
  }
  if(comparisons != ""){comparisons = '&comparisons=' + comparisons}
  return comparisons    
}

function getAxisSwap(){
  //return a blank for older graphs without this variable defined in page specific js
  tempNewUrlAxis = ''
   if(document.chartForm.yaxisLocation.checked == false){tempNewUrlAxis += '&yaxisLocation=right'}
  return tempNewUrlAxis 
}

function findCompany(whichComp){
  clearTimeout(findTO);
  clearHelpMsg();
	
	var searchterm = trim(getElementById('isComp' + whichComp).value);
	if (searchterm != "") findWin = this.open("?page=popup-search&search="+getElementById('isComp' + whichComp).value, "findWindow", "toolbar=no,menubar=no,height=500,width=600,location=no,scrollbars=yes,resizable=no,status=no,left=100,top=100");
	else alert("Please enter a search term");

  changingWhichComp = whichComp;
}

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 selectedIndexVal = ""

  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(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
  }
}

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()
  }
}