var ThePlayer=new Array();
var AveragePlayer=new Array();
var ObjectKey=new Array();
ObjectKey['panelMain']=1
ObjectKey['panelMap']=2
ObjectKey['CC']=3
ObjectKey['PromoteContainer0']=4
ObjectKey['PromoteContainer1']=5
ObjectKey['PromoteContainer2']=6
ObjectKey['PromoteContainer3']=7
ObjectKey['ChartPopupContainer']=8
ObjectKey['panelBulletin']=9
ObjectKey['panelTeamInfo']=10
ObjectKey['panelReviewDecisions']=11
ObjectKey['panelSavedDecisions']=12

ObjectKey['panelMRKT']=13
ObjectKey['panelMRKTCost']=14
ObjectKey['panelCompInfoDec']=15
ObjectKey['panelSAReport']=16

ObjectKey['panelOPERDec']=17
ObjectKey['panelPlantDec']=18
ObjectKey['panelPAC']=19
ObjectKey['panelMIC']=20
ObjectKey['panelCOGS']=21
ObjectKey['panelWHOp']=22
ObjectKey['panelPlant']=23
ObjectKey['panelRM']=24

ObjectKey['panelFINADec']=25
ObjectKey['panelBalSheet']=26
ObjectKey['panelIncome']=27
ObjectKey['panelCashFlow']=28
ObjectKey['panelRatio']=29

ObjectKey['HelpRequest']=30
ObjectKey['SwitchQuarter']=31

ObjectKey['ChartPopupContainer']=32;
ObjectKey['ResearchReport']=33;
ObjectKey['PerfReport']=34;
ObjectKey['SummaryReport']=35;
ObjectKey['BusConsultant']=36;

ObjectKey['VideoCenter']=37;


var ST =new Date()
var StartTime = ST.getTime();
var GlobalActionString='';
var GlobalVariableString='';
function RecordVariableAction(TheVariable){
   var CurTime = new Date();
   var Difference = Math.floor((CurTime.getTime() - StartTime)/1000);
   if (GlobalVariableString !='') GlobalVariableString+="QQ";
   GlobalVariableString+=TheVariable+','+Difference.toString();
   if (GlobalVariableString.length+GlobalActionString.length>500) SendInActions();
}

function RecordObjectAction(Object,Action,Params){
   if (!ObjectKey[Object])return false;
   var ActionCode=0;
   if (Action=='Open') ActionCode=1;
   if (Action=='Close') ActionCode=2;
   if (Action=='Switch') ActionCode=3;
   if (Action=='Print') ActionCode=4;
   if (Action=='Warning') ActionCode=5;
   
   var CurTime = new Date();
   var Difference = Math.floor((CurTime.getTime() - StartTime)/1000);
   if (GlobalActionString !='') GlobalActionString+="QQ";
   if (Params=='' || Params==undefined) Params='';
   GlobalActionString+=ObjectKey[Object].toString()+','+ActionCode.toString()+','+Params.toString()+','+Difference.toString();
   if (GlobalVariableString.length+GlobalActionString.length>500) SendInActions();
}

function SendInActions(){
  var URL="HandleCom.cgi?SessionID="+SessionID+"&Action=SaveActivity&Quarter="+CurrentQuarter+"&GameID="+GameID
  URL+='&UserActivityID='+ UserActivityID
  URL+='&GlobalActionString='+ GlobalActionString
  URL+='&GlobalVariableString='+ GlobalVariableString
//  alert('length='+URL.length+" "+URL)
  parent.ComFrame2.document.location=URL;
  GlobalActionString='';
  GlobalVariableString='';
}





var PlayerDisplayName;
var PlayerComments;
var UserSelect;

function doShowHint(point, series, chart, hint, hover_select) {
     var hint;
     if (hover_select == "hover") {
       hint = 'Hovering over: [x],[y]';
     } else {
       hint = '[series_title]<br />' + 'Selected Point: [x],[y]';
     }
     return hint;
}


function CloseRatingPopup(){
  div = document.getElementById('RatingPopup');
  div.style.visibility="hidden";
}


function DisplayUserRatingDiv(UserID){
  obj=document.getElementById('Rating'+UserID);
  div = document.getElementById('RatingPopup');
  var thePos = findPos(obj);
  div.style.top=thePos[1];
  div.style.left=thePos[0] + findWidth(obj);
  div.style.display = 'block';
  div.style.visibility="visible";
  BuildRatingChart();
  document.getElementById("PlayerComments").innerHTML = PlayerComments;
  document.getElementById("RatingDivHeader").innerHTML = RatingDivHeader;
 }
 
 
function BuildRatingChart(){
   var chart = new EJSC.Chart("RatingPopupChart", {
               title: "Rating Over Time" ,
               axis_bottom: {
               stagger_ticks: true,
               size:40,
               		formatter: new EJSC.DateFormatter({ format_string: 'MMM DD' }),
               		crosshair: { show: true, 
               		       color: "#f90"
               		       }  ,
               		caption: "Date",
               		cursor_position:{ caption:'Date: ', show:true, color: "#f90" }
               },
               axis_left: { caption: "Rating" , crosshair: { color: "#f90", show: true } } ,
               show_legend: true, 
               auto_zoom: 'y' ,
               auto_find_point_by_x: true,
               onShowHint: doShowHint
               });

     chart.addSeries(new EJSC.LineSeries(
        new EJSC.ArrayDataHandler( ThePlayer ),
       { title: PlayerDisplayName }
     ));

     chart.addSeries(new EJSC.LineSeries(
        new EJSC.ArrayDataHandler( AveragePlayer ),
       { title: "Average Player" }
     ));

}


function GetUserRatingDiv(obj){
  var UserID = obj.id.match(/\d+/);
  SubmitComRequest("HandleCom.cgi?SessionID="+SessionID+"&Action=GetUserRating&GameID="+GameID+"&GameMasterID="+GameMasterID+"&UserID="+UserID,'Getting Rating Information');
}

function DisplayClassActivityReport(theLeft,theTop,StudID){
  div = document.getElementById('RatingPopup');
  document.getElementById("PlayerComments").innerHTML = PlayerComments;
  document.getElementById("RatingDivHeader").innerHTML = RatingDivHeader;
  div.style.top=theTop;
  div.style.left=theLeft;
  div.style.display = 'block';
  div.style.visibility="visible";
  
  TheSel=document.getElementById('StudID');
  for(index = 0; index < TheSel.length; index++) {
    if(TheSel[index].value == StudID) TheSel.selectedIndex = index;
  }
}

var globalchart;
function ClearActivityLegend(){
  setTimeout("globalchart.legendMinimize();", 4000);
}  
function ClassShowHintCode(point, series, chart, hint, hover_select) {
         var hint;
         if (hover_select == "hover") {
           hint = '[series_title]: Quarter [x] Standing [y]';
         }
         return hint;
    }
function ClassShowHintCodeTime(point, series, chart, hint, hover_select) {
         var hint;
         if (hover_select == "hover") {
           hint = '[series_title]: [x] = [y]';
         }
         return hint;
    }
function ClassShowHintCodePie(point, series, chart, hint, hover_select) {
       return "[label]: [x] of [total] ([percent]%)";
    }
function BuildClassActivityChartPie(TheTitle){
   globalchart = new EJSC.Chart("RatingPopupChart", {
               title: TheTitle ,
               onShowHint: ClassShowHintCodePie
               }
               )
 ClearActivityLegend();
 }


function BuildClassActivityChartTime(TheTitle){
   globalchart = new EJSC.Chart("RatingPopupChart", {
               title: TheTitle ,
               onShowHint: ClassShowHintCodeTime,
               axis_bottom: {
               stagger_ticks: true,
               size:40,
               		formatter: new EJSC.DateFormatter({ format_string: 'MMM DD' }),
               		crosshair: { show: true, 
               		       color: "#f90"
               		       }  ,
               		caption: "Date",
               		cursor_position:{ caption:'Date: ', show:true, color: "#f90" }
               },
               axis_left: { caption: "Sessions" , crosshair: { color: "#f90", show: true } } ,
               axis_right: { caption: "Time" , crosshair: { color: "#f90", show: true } } ,
               show_legend: true, 
               auto_zoom: 'y' ,
               auto_find_point_by_x: true
               });

 ClearActivityLegend();
   
}














