﻿// JScript File


var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)


var lastSelectedViewer=0;
var DataWorld={};
DataWorld.DTP={};
DataWorld.DTP.Process={};
DataWorld.DTP.Process.AJAX=function(argument)
{
    this.fadeInTime=2;
    this.v1=document.getElementById("Viewer1");
    this.v2=document.getElementById("Viewer2");
   
    this.spotId=null;
    this.imagePath="http://localhost:1403/App/Images/";
    this.viewer1Slider_LastValue=0;
    this.viewer1Slider_CurrentValue=0;
  
    this.viewer2Slider_LastValue=0;
    this.viewer2Slider_CurrentValue=0;
    this.lastSelectedViewer=0;
}

DataWorld.DTP.Process.AJAX.prototype=
{
        GetResultSet: function(spotId) 
        {
            try
            {       document.getElementById("dtpResultPanel").style.display="block";
                   document.getElementById("dtpResultPanelFinalValue").innerHTML="<br><br>&nbsp;&nbsp;History loading.Please wait.....";
                  var url= location.href.substring(0,location.href.lastIndexOf('/')) 
                 Controls_ResultPanel.GetHotSpotDetails(spotId,url,this.Calling_AJAXReturn);
             }
             catch(e)
             {
                ErrorCatcher(e,"GetResultSet");
             }
        },
        
        Calling_AJAXReturn: function(res)
        {
                document.getElementById("dtpResultPanelFinalValue").innerHTML=res.value;
                document.getElementById("dtpResultPanel").style.display="block";
                _objDTP.LoadDefaultImage_Viewer1();
                
        },
        
        LoadDefaultImage_Viewer1: function()
        {
            var strValue=document.getElementById("dtpDefaultLoad").innerHTML
            var valArray=strValue.split(";");
            _objDTP.setViewerImages(valArray[0],1,valArray[2],valArray[1]);
           
        },
        
        
        //for Filling the
        DTP_GetImageDetails:function(imgId,ViewerId)
        {
            
            this.lastSelectedViewer=ViewerId; 
            lastSelectedViewer=ViewerId;
            Controls_ResultPanel.GetHotSpotImageDeatils(imgId,this.DTP_FillImageDetails);
        
        
        },
        
        DTP_FillImageDetails:function(res)
        {
           var viewerTopString="";
           var viewerDescription="";
           try
           {
           
                if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
	            {
	   	                var dat=res.value.Tables[0].Rows[0].SightPhotoDate; //Tue Dec 4
	   	               
	   	                viewerTopString="-&nbsp;"+ res.value.Tables[0].Rows[0].ImageName +"<b> <font  style='color:black;'> </font></b> " + dat ;//+ " <b><font  style='color:black;'>Hot Spot</font></b> "+ res.value.Tables[0].Rows[0].HotSpot  +")";
	                    viewerDescription= res.value.Tables[0].Rows[0].Description;
                    
               }
               //alert(lastSelectedViewer +":"+viewerDescription);
                switch(lastSelectedViewer)
                {
                
                    case 1:
                        document.getElementById("imgViewerDescription").innerHTML=viewerDescription;    
                        document.getElementById("Viewer1ForHotSpotImageName").innerHTML=viewerTopString;
                        
                    break;
                
                    case 2:
                        document.getElementById("Viewer2ForHotSpotImageName").innerHTML=viewerTopString;
                        document.getElementById("imgViewer2Description").innerHTML=viewerDescription;
                    break;
                
                }
             }catch(e)
             {
                ErrorCatcher(e,"DTP_FillImageDetails");
             
             }
        },
        
        
        DTP_SetSliderYaw:function(viewerId,CurrentSliderValue)
        {
            switch(viewerId)
            {
                case 1:
                    var newYaw;
                    var changeYaw=CurrentSliderValue-this.viewer1Slider_LastValue;
                    if(this.viewer1Slider_LastValue<CurrentSliderValue)
                    {
                        newYaw=this.v1.GetViewYaw()+changeYaw;
                    }
                    else
                    {
                        newYaw=this.v1.GetViewYaw()+changeYaw;
                    }
                    this.v1.SetViewYaw(newYaw);  
                    this.v2.SetViewYaw(newYaw);   
                   // document.getElementById("res123").innerHTML="LastValue"+this.viewer1Slider_LastValue+":Current"+CurrentSliderValue +":newYaw"+newYaw;     
                    this.viewer1Slider_LastValue=CurrentSliderValue;
                    
                    break;
                case 2:
                    var newYaw;
                    if(this.viewer2Slider_LastValue<CurrentSliderValue)
                    {
                        newYaw=this.v2.GetViewYaw()+CurrentSliderValue;
                    }
                    else
                    {
                        newYaw=this.v2.GetViewYaw()+CurrentSliderValue;
                    }
                    this.v2.SetViewYaw(newYaw);     
                    this.viewer2Slider_LastValue=CurrentSliderValue;
                    
                 break;
             } 
             
        },
        
        DTPYaw:function(viewer,Yaw)
        {
           try
           {
              if(Yaw>0)
              {
                    
                    viewer.SetViewYaw(Yaw);
              }
           
           }catch(e)
           {
             ErrorCatcher(e,"DTPYaw");
           }
        
        },
        
        setViewerImages: function(imageName,viewerId,imgId,defaultYaw)
        {
                this.v1=document.getElementById("Viewer1");
                this.v2=document.getElementById("Viewer2");
                
       
            try
            {
                            var fileName="";
                            fileName= location.href.substring(0,location.href.lastIndexOf('/')) ;
                            fileName=fileName+"/Images/"+imageName;
                           
                switch(viewerId)
                {
                    case 1:
                            this.DTP_GetImageDetails(imgId,1);     
                            //this.v1.OpenMovie(fileName);  
                            this.v1.OpenMovie(fileName, -1, true);  
                            this.DTPYaw(this.v1,defaultYaw);   
                            carpeLeft("Viewer1Slider",0);                       
                            
                            this.viewer1Slider_LastValue=0;
                            document.getElementById("spanViewer1Slide").style.display="block";
                            this.v1.SetGUIElementVisibility("GUI_FIXED_PLAY_BAR",false); 
                            //document.getElementById("imgViewerDescription").innerHTML=description;
                            break;
                    case 2:
                            this.DTP_GetImageDetails(imgId,2);     
                            this.v2.OpenMovie(fileName, -1, true);  
                            this.DTPYaw(this.v2,defaultYaw);                    
                            carpeLeft("Viewer2Slider",0);                             
                            this.viewer2Slider_LastValue=0;
                            document.getElementById("spanViewer2Slide").style.display="block";
                            this.v2.SetGUIElementVisibility("GUI_FIXED_PLAY_BAR",false); 
                            //document.getElementById("imgViewerDescription").innerHTML=description;
                         break;
                    
                }
            }
            catch(e)
            {
              ErrorCatcher(e,"setViewerImages");
            
            }
        
        }
        
   }
   
   
   
   
   
   var _objDTP = new DataWorld.DTP.Process.AJAX("DTP");


function getSpotDetails(spotId)
{
    try
    {
        
        switchColor(spotId);
        _objDTP.GetResultSet(spotId);
    }catch(e)
    {
      //alert(e.description);
    
    }

}

function switchColor(spotId)
{
    try
    {
           for(var i=1;i<=7;i++)
           {
              var id="hot"+i;
              if(i==spotId)
              {
                document.getElementById(id).className ='popupMenu1';   
              }
              else
              {
                 document.getElementById(id).className ='popupMenu';  
              }
           
           }
    }catch(e)
    {

    }

}

function UpdateViewers(sliderId)
{
    try
    {
        switch(sliderId)
        {
          case "Viewer1Slider":
                _objDTP.DTP_SetSliderYaw(1,carpeLeft("Viewer1Slider"));
                break;
          case "Viewer2Slider":
                _objDTP.DTP_SetSliderYaw(2,carpeLeft("Viewer2Slider"));
                break;
        }
    }
    catch(e)
    {
      //  alert(e.description);
    }
}

function GetSliderValue()
{
  try
  {
    //alert(carpeLeft("Viewer2Slider"));
    //alert(carpeLeft("Viewer1Slider"));
  
  }
  catch(e)
  {
    //alert(e.description);
  
  }


}



function LoadView1(imgName,defaultYaw,description)
{
   
   _objDTP.setViewerImages(imgName,1,description,defaultYaw);
   

}


function LoadView2(imgName,defaultYaw,description)
{
    _objDTP.setViewerImages(imgName,2,description,defaultYaw);
    
}





function CreatePoint()
{
        try
        {
            
                var jg = new jsGraphics("dtpMapImgdiv"); 
                jg.setStroke(2);
                jg.setColor("yellow"); // blue
                
                var jgTxt = new jsGraphics("dtpMapImgdiv"); 
                jgTxt.setStroke(1);
                jgTxt.setColor("Cyan"); // blue
                
                jg.drawOval(250,5,100,40); //1
                jgTxt.drawString("<a id='hot1' onmouseover='javascript:LoadHoverImage(event,this,1);' href='#' class='popupMenu' style='cursor:hand;' onclick='javascript:getSpotDetails(1);'>TRADE ZONE</a>",265,16);
                
                jg.drawOval(240,75,90,60); //2
                jgTxt.drawString("<a id='hot2' onmouseover='javascript:LoadHoverImage(event,this,2);' href='#' class='popupMenu' style='cursor:hand;' onclick='javascript:getSpotDetails(2);'>CONTROL<br/>&nbsp;TOWER / <br/>TERMINAL</a>",253,85);
                
                jgTxt.drawString("<a id='hot3' onmouseover='javascript:LoadHoverImage(event,this,3);' href='#' class='popupMenu' style='cursor:hand;' onclick='javascript:getSpotDetails(3);'>&nbsp;&nbsp;&nbsp;FUEL<br/>STORAGE</a>",180,120);
                jg.drawEllipse(170,115,80,40); //3
               
                
                jg.drawEllipse (90,140,90,40);
                jgTxt.drawStringRect("<a id='hot4' onmouseover='javascript:LoadHoverImage(event,this,4);' href='#' class='popupMenu' style='cursor:hand;' onclick='javascript:getSpotDetails(4);'>&nbsp;&nbsp;AGRIZONE</a>",95,150,70,'center');   //4
                
                jg.drawOval(110,190,75,40);
                jgTxt.drawStringRect("<a id='hot5'onmouseover='javascript:LoadHoverImage(event,this,5);' href='#' class='popupMenu' style='cursor:hand;' onclick='javascript:getSpotDetails(5);'>MAIN CAR<br/>PARK</a>",100,200,100,'center');
                
                jg.drawOval (170,220,80,30);
                jgTxt.drawStringRect("<a id='hot6' onmouseover='javascript:LoadHoverImage(event,this,6);' href='#' class='popupMenu' style='cursor:hand;' onclick='javascript:getSpotDetails(6);'>TERMINAL</a>",180,230,80,'left');
                
               
                 jg.drawOval(260,180,70,40);
                 jgTxt.drawStringRect("<a id='hot7' onmouseover='javascript:LoadHoverImage(event,this,7);' href='#' class='popupMenu' style='cursor:hand;' onclick='javascript:getSpotDetails(7);'>RUNWAY</a>",270,190,55,'center');
      
                 jg.drawOval(350,240,105,40);
                 jgTxt.drawStringRect("<a id='hot8' onmouseover='javascript:LoadHoverImage(event,this,8);' href='#' class='popupMenu' style='cursor:hand;' onclick='javascript:getSpotDetails(8);'>INTERCHANGE</a>",360,250,90,'center');
      
      
                jgTxt.paint();
                jg.paint();
                
        }
        catch(e)
        {
          alert(e.description);
        
        }                
}


var timerForDrawing=window.setTimeout("CreatePoint()",4000); 

function ResizeImageTimerH()
{
  
         window.clearTimeout(timerForDrawing);
	      timerForDrawing=null;
 
}

document.attachEvent("onclick", XY);

function XY(e)
{
    //alert("X:"+e.clientX+"Y:"+e.clientY);
}



function OpenNewWindow(imgName)
{
   //alert(imgName);
	window.open('PopUp.aspx?Img=' + imgName + '','','resizable=no,scrollbars=yes,top=150,left=150,width=400,height=400');
	
}

function UploadImageURL()
{
  window.open('UploadImage.aspx?Img=' + 'imgName'+ 'UploadDTPImages','UploadDTPImages','resizable=no,scrollbars=yes,top=150,left=250,width=470,height=290');

}



function NumericTextBoxWithoutDecimal(e)
        {
            if(String.fromCharCode(e.keyCode) < '0' || String.fromCharCode(e.keyCode) > '9')
            {
                  e.keyCode = 0;
            }
        
        }



function LoadHoverImage(e,object,hotSpotId)
{

            try
            {
                var _objHover=document.getElementById("dtpHoverImage");
                _objHover.style.left=e.clientX +"px";
                _objHover.style.top=e.clientY +"px";;
                 if((hotSpotId==8)||(hotSpotId==7) )
                 {
                    _objHover.style.left=e.clientX-150 +"px";
                    _objHover.style.top=e.clientY +"px";;
                 }
                
                var obj_dtpImage_Hover=document.getElementById("dtpImage_Hover");
                obj_dtpImage_Hover.src=preImages[hotSpotId].src;                
                
                if(IE)
                {
                    _objHover.style.filter="blendTrans(duration=" + _objDTP.fadeInTime + ")";
                    _objHover.filters.blendTrans.apply();
                    _objHover.style.display="block";
                    _objHover.filters.blendTrans.play();
                    
                }
                else
                {
                    _objHover.style.display="block"; 
                }   
               
             }
             catch(e)
             {
                _objHover.style.display="block"; 
                //alert(e.description);
             }  

}




function UnloadHover(e,object,hotSpotId)
{
                var _objHover=document.getElementById("dtpHoverImage");
                
                _objHover.style.left="0px";
                _objHover.style.top="0px";
                _objHover.style.display="none"; 
             

}


function CloseHover(_objHover)
{
                var _objHover=document.getElementById("dtpHoverImage");
                _objHover.style.left="0px";
                _objHover.style.top="0px";
                _objHover.style.display="none"; 
             


}


var thumbImages = new Array();
thumbImages[0]="../dube_viewer/images/Thumbnail";
thumbImages[1]="../dube_viewer/images/Thumbnail/TradeZone.jpg";
thumbImages[2]="../dube_viewer/images/Thumbnail/ControlTower.jpg";
thumbImages[3]="../dube_viewer/images/Thumbnail/FuelStorage.jpg";
thumbImages[4]="../dube_viewer/images/Thumbnail/AgriZone.jpg";
thumbImages[5]="../dube_viewer/images/Thumbnail/MainCarpark.jpg";
thumbImages[6]="../dube_viewer/images/Thumbnail/Terminal.jpg";
thumbImages[7]="../dube_viewer/images/Thumbnail/Runway.jpg";
thumbImages[8]="../dube_viewer/images/Thumbnail/InterChange.jpg";



var preImages = new Array();

function loadImages()
 { 
	for ( i = 0; i < thumbImages.length; i++) 
	{ 
		preImages[i] = new Image();
		preImages[i].src = thumbImages[i];
	}
	

}
loadImages();





var mousecheck1='';
var mouseCheck2='';

var mousecheckT='';
var mousecheckB='';

function mousedown(option)
{
   try
   {
        switch(option)
        {
            case "l1":
                 mousecheck1='down';
                 clik_L(1);
                 break;
            case "r1":
                 mousecheck1='down';
                 clik_R(1);   
                 break; 
            
            
            case "l2":
                 mousecheck2='down';
                 clik_L(2);
                 break;
            
            case "r2":
                  mousecheck2='down';   
                  clik_R(2);   
                 break;     
             
           
           case "t1":
                  mousecheckT='down';   
                  clik_T(1);   
                 break;      
           
            case "b1":
                  mousecheckT='down';   
                  clik_B(1);   
                 break;    
                 
            case "t2":
                  mousecheckB='down';   
                  clik_T(2);   
                 break;      
           
            case "b2":
                  mousecheckB='down';   
                  clik_B(2);   
                 break;         
                     
                 
        }
    
    }catch(e)
    {
	//        alert(e.description);
    }
}


function clik_L(viewerId)
{
        switch(viewerId)
        {
            case 1:
                 _objDTP.v1.SetViewYaw(_objDTP.v1.GetViewYaw()-1);
                 //_objDTP.DTP_SetSliderYaw(1,1);
                if (mousecheck1 == 'down')
                {
                    setTimeout("clik_L(1)", 0);
                }
               break;
           
           case 2:
                 _objDTP.v2.SetViewYaw(_objDTP.v2.GetViewYaw()-1);
                 //_objDTP.DTP_SetSliderYaw(2,1);
                if (mousecheck2 == 'down')
                {
                    setTimeout("clik_L(2)", 0);
                }
               break;  
             
             
          }
}

function clik_T(viewerId)
{
        switch(viewerId)
        {
            case 1:
                 _objDTP.v1.SetViewPitch(_objDTP.v1.GetViewPitch()+1);
                if (mousecheckT == 'down')
                {
                    setTimeout("clik_T(1)", 0);
                }
               break;
           
           case 2:
                 _objDTP.v2.SetViewPitch(_objDTP.v2.GetViewPitch()+1);
                if (mousecheckB == 'down')
                {
                    setTimeout("clik_T(2)", 0);
                }
               break;  
             
             
          }
}

function clik_B(viewerId)
{
        switch(viewerId)
        {
            case 1:
                _objDTP.v1.SetViewPitch(_objDTP.v1.GetViewPitch()-1);
                if (mousecheckT == 'down')
                {
                    setTimeout("clik_B(1)", 0);
                }
               break;
           
           case 2:
                _objDTP.v2.SetViewPitch(_objDTP.v2.GetViewPitch()-1);
                if (mousecheckB == 'down')
                {
                    setTimeout("clik_B(2)", 0);
                }
               break;  
             
             
          }
}


function clik_R(viewerId)
{
        switch(viewerId)
        {
            case 1:
                _objDTP.v1.SetViewYaw(_objDTP.v1.GetViewYaw()+1);
                if (mousecheck1 == 'down')
                {
                    setTimeout("clik_R(1)", 0);
                }
               break;
           
           case 2:
                 _objDTP.v2.SetViewYaw(_objDTP.v2.GetViewYaw()+1);
                if (mousecheck2 == 'down')
                {
                    setTimeout("clik_R(2)", 0);
                }
               break;  
             
             
          }
}




function mouseout(option)
{
    try
    {
        
         switch(option)
        {
            case "l1":
                 mousecheck1='up';
                 
                 break;
            case "r1":
                  mousecheck1='up';
                 break; 
            
            
            case "l2":
                 mousecheck2='up';
                 break;
            
           case "r2":
                  mousecheck2='up';
                 break;     
          case "t1":
                 mousecheckT='up';
                 break;
            
            case "b1":
                  mousecheckT='up';
                 break;          
                     break;     
          case "t2":
                 mousecheckB='up';
                 break;
            
            case "b2":
                  mousecheckB='up';
                 break;         
        }
    
     }catch(e)
     {
        //alert("mouseout"+e.description);
     }
}
function mouseup(option)
{
    try
    {
         switch(option)
        {
            case "l1":
                 mousecheck1='up';
                 
                 break;
            case "r1":
                  mousecheck1='up';
                 break; 
            
            
            case "l2":
                 mousecheck2='up';
                 //clik_L(2);
                 break;
            
            case "r2":
                  mousecheck2='up';
                 break;     
           
            case "t1":
                 mousecheckT='up';
                 //clik_T(1);
                 break;
            
            case "b1":
                  mousecheckT='up';
                 break;  
            
             case "t2":
                 mousecheckB='up';
                 //clik_T(1);
                 break;
            
            case "b2":
                  mousecheckB='up';
                 break;      
                 
        }
    
    }
    catch(e)
     {
       // alert("mouseup"+e.description);
     }
}


function ErrorCatcher(e,from)
{
        alert(e.description +":"+from);

}


