//Clickarea
//(c)2009 Stefan + Michael Brand

var debug_status = false; //debugging disabled
var debug;
var coords_output;
var area;
var clickzones_div

var coords_array = new Array(0,0);

var clickzones = [[0,60], [65,185], [195, 250]];

function VarInit()
{
	debug = document.getElementById("debug");
	coords_output = debug;
	area = document.getElementById("clicktransparent");
	document.getElementById("clicktransparent").onclick = GetCoords; //onlick event handler => event object for GetCoords()
	clickzones_div = debug;
	
}

function Debug(text)
{
	if (debug_status == true)
	{
		//alert("Debug()" + debug.innerHTML);
		if (debug.innerHTML.search(/Keine Debug Meldung/) == -1)
		{
			//alert("Append");
			debug.innerHTML += "<br>" + text;
		}
		else
		{
			//alert("New");
			debug.innerHTML += text;
		}
	}
}

function GetCoords(e)
{
	//alert("GetCoords()");
	Debug("GetCoords: Enter");
	
	//Debug("GetCoords: " + window.event);
	
	//MSIE needs window.event Opera can handle window.event AND e Mozialla needs e
	
	//MSIE, Opera use offset Mozilla uses layer
	try 
	{
		//Opera (offset     e)
		if (e.offsetX != null)
		{
			//Debug("GetCoords: Opera");
			coords_array[0] = e.offsetX;
			coords_array[1] = e.offsetY;
		}
		//Mozialla (no offset     e)
		else
		{
			//Debug("GetCoords: Mozilla");
			coords_array[0] = e.layerX;
			coords_array[1] = e.layerY;
		}
	}
	//MSIE will throw an exception on seeing the e => catch
	catch (error)
	{
		//Debug("GetCoords: " + error);
		try
		{
			if (window.event != null)
			{
				//Debug("GetCoords: MSIE");
				coords_array[0] = window.event.offsetX;
				coords_array[1] = window.event.offsetY;
			}
		}
		catch (error2)
		{
			//Debug("GetCoords: " + error2 + " ! Dieser Fehler sollte nie auftreten, weil jetzt alle Browser durch sind...");
		}
	}

	//Debug("GetCoords: Values set");
	
	WriteCoords();
	
	click = GetClickZone();
	if (click == 0)
	{
		SendRequest(false)
	}
	if (click == 1)
	{
		//do nothing xD => click on the current pic doesnt change anything
	}
	if (click == 2)
	{
		SendRequest(true)
	}
//	else
//	{
//		alert("Keine Klickzone? (" + click + ")");
//	}
}

function WriteCoords()
{
	//Debug("WriteCoords: Enter");
	Debug("X: " + coords_array[0] + "<br>Y: " + coords_array[1]);
}

function GetClickZone()
{
	//Debug("GetClickZone: Enter");
	clickzone = -1;
	for (i = 0; i < clickzones.length; i++)
	{
		//alert();
		if ( (coords_array[0] >= clickzones[i][0]) && (coords_array[0] <= clickzones[i][1]))
		{
			//return "Klickzone: " + i;
			return i
		}
	}
	//return "Keine Klickzone?";
	return -1;
}

