﻿var nDefaultChartHeight;
var nDefaultChartWidth;
var nDefaultSeatingCanvasHeight;
var nDefaultSeatingCanvasWidth;
var bPanning=false;
var nPanFromX;
var nPanFromY;
var divSeatingChart;
var divSeatingCanvas;
var imgSeatingChart;

function loadSeatingChart() {
    initSeatingChart();
    initSeatingCanvas();
    initSeatingScroll();
    centerSeatingChart();
}

function centerSeatingChart()
{
	if(imgSeatingChart!=null)
	{ 
		imgSeatingChart.width=nDefaultChartWidth;
		imgSeatingChart.height=nDefaultChartHeight;
		initSeatingScroll();
		if (nDefaultChartHeight > 500 && nDefaultChartWidth > 500) {
		    zoomOutLevel = Math.min(Math.round((nDefaultChartHeight - 499) / 150), Math.round((nDefaultChartWidth - 499) / 150));
		    for (n = 0; n < zoomOutLevel; n++) { 
                zoomSeatingChart("OUT");
            }
        }
    }
	else
	{
		 initSeatingChart();
		 initSeatingCanvas();
		 initSeatingScroll();
	}  
} 

function panSeatingChart(direction)
{

	if(divSeatingChart!=null)
	{
		var nPanPixelsVertical = Math.round(divSeatingChart.offsetHeight/2);
		var nPanPixelsHorizontal = Math.round(divSeatingChart.offsetWidth/2);
		switch(direction)
		{
			case "UP":
				divSeatingChart.scrollTop=divSeatingChart.scrollTop-nPanPixelsVertical;
				break;
			case "DOWN":
				divSeatingChart.scrollTop=divSeatingChart.scrollTop+nPanPixelsVertical;
				break;
			case "LEFT":
				divSeatingChart.scrollLeft=divSeatingChart.scrollLeft-nPanPixelsHorizontal;
				break;
			case "RIGHT":
				divSeatingChart.scrollLeft=divSeatingChart.scrollLeft+nPanPixelsHorizontal;
				break;
		}
	}
	else
	{
		 initSeatingChart();
		 initSeatingCanvas();
		 initSeatingScroll();
	}  
}

function zoomSeatingChart(mode)
{
	if(imgSeatingChart!=null)
	{ 
		var imgHeight = imgSeatingChart.height;
		var imgWidth = imgSeatingChart.width;
		switch(mode)
		{
			case "IN":
			   imgHeight = Math.round(imgHeight*1.25); 
			   imgWidth = Math.round(imgWidth*1.25);
			   if(imgWidth<divSeatingCanvas.offsetWidth)
			   {
				   imgSeatingChart.width=imgWidth;
				   imgSeatingChart.height=imgHeight;
			   }
				break;
			case "OUT":
			   imgHeight = imgHeight*.8; 
			   imgWidth = imgWidth*.8;
			   imgSeatingChart.width=imgWidth;
			   imgSeatingChart.height=imgHeight;
				break;
		}  
	}
	else
	{
		 initSeatingChart();
		 initSeatingCanvas();
		 initSeatingScroll();
	}  
}

function initSeatingChart()
{
	try
	{
		imgSeatingChart = document.getElementById("imgSeatingChart");
		nDefaultChartHeight = imgSeatingChart.offsetHeight;
		nDefaultChartWidth = imgSeatingChart.offsetWidth;
		divSeatingChart = document.getElementById("divSeatingChart"); 
	}
	catch(ex)
	{
		try{
		var strErrorLog = getDebugInfo()+getExceptionInfo(ex)+"<hr />";
		var strParams = "strErrorMsg="+strErrorLog+"&strSubject=JS_Exception [seating.js initSeatingChart]&bIsHtmlMsg=true";
		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError");
		}catch(e){/**/}
	}
} 

function initSeatingCanvas()
{
	try
	{
		nDefaultSeatingCanvasHeight = nDefaultChartHeight;
		nDefaultSeatingCanvasWidth = nDefaultChartWidth;
		divSeatingCanvas = document.getElementById("divSeatingCanvas");
	}
	catch(ex)
	{
		try{
		var strErrorLog = getDebugInfo()+getExceptionInfo(ex)+"<hr />";
		var strParams = "strErrorMsg="+strErrorLog+"&strSubject=JS_Exception [seating.js initSeatingCanvas]&bIsHtmlMsg=true";
		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError");
		}catch(e){/**/}
	}
} 

function initSeatingScroll()
{
	try
	{
		var strPaddingVertical = Math.round(nDefaultSeatingCanvasHeight/2);
		var strPaddingHorizontal = Math.round(nDefaultSeatingCanvasWidth/2);
		divSeatingCanvas = document.getElementById("divSeatingCanvas");
		divSeatingCanvas.style.width=(nDefaultSeatingCanvasWidth+(strPaddingHorizontal*2))+"px";
		divSeatingCanvas.style.paddingTop=strPaddingVertical+"px";
		divSeatingCanvas.style.paddingBottom=strPaddingVertical+"px";
		divSeatingChart.scrollLeft = (divSeatingChart.scrollWidth-divSeatingChart.offsetWidth)/2;
		divSeatingChart.scrollTop = (divSeatingChart.scrollHeight - divSeatingChart.offsetHeight) / 2;
	}
	catch(ex)
	{
		try{
		var strErrorLog = getDebugInfo()+getExceptionInfo(ex)+"<hr />";
		var strParams = "strErrorMsg="+strErrorLog+"&strSubject=JS_Exception [seating.js initSeatingScroll]&bIsHtmlMsg=true";
		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError");
		}catch(e){/**/}
	}
}

function panChartStart(e)
{
	if(divSeatingChart!=null)
	{
		bPanning = true;
		if(e.preventDefault){e.preventDefault();}
		divSeatingChart.style.cursor="move";
		try
		{
			var posx = 0;
			var posy = 0;
			if (!e){var e = window.event;}
			if (e.pageX || e.pageY)
			{
				posx = e.pageX;
				posy = e.pageY;
			}
			else if (e.clientX || e.clientY)
			{
				posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
				posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			}
			nPanFromX=posx;
			nPanFromY=posy;
		}
		catch(x)
		{
			/*panning not available*/
		}
	}
	else
	{
		 initSeatingChart();
		 initSeatingCanvas();
		 initSeatingScroll();
	}  
}

function panChartEnd()
{
	bPanning = false;
	if(divSeatingChart!=null)
	{ 
		divSeatingChart.style.cursor="move";
	}
}

function panChart(e)
{
	try
	{ 
		if(bPanning)
		{
			var posx = 0;
			var posy = 0;
			if (!e){var e = window.event;}
			if (e.pageX || e.pageY)
			{
				posx = e.pageX;
				posy = e.pageY;
			}
			else if (e.clientX || e.clientY)
			{
				posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
				posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			}
			divSeatingChart.scrollTop=divSeatingChart.scrollTop+((nPanFromY-posy));
			divSeatingChart.scrollLeft=divSeatingChart.scrollLeft+((nPanFromX-posx));
			nPanFromX=posx;
			nPanFromY=posy;
		}
	}
	catch(x)
	{/*panning not available*/}
}



