/*
global variables for javascript selectable RASP maps.

Copyright (C) 2010 Thomas Pantzer

This program is free software; you can redistribute it and/or modify it under 
the terms of the GNU General Public License as published by the Free Software 
Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY 
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with 
this program; if not, see http://www.gnu.org/licenses/.
*/


var debug = 0;
var recalc = 0;
var maintaining = 0;
var loadImage = 1;
var CursorSize = 10;
var soundMapLength = 0;
var soundMapIdx = 0;

var siteOptionsLength = 0;
var siteWinchOptionsLength = 0;
var siteOptionIdx = 0;
var siteOptionsArrayError = 0;
var siteWinchOptionsArrayError = 0;

var x_offset = 0;
var y_offset = -2;
var menu_xOffset = 50;
var menu_yOffset = 50;

var fLat = 83.23798712126573;
var fLon = 0.7711233052494313;
var rStart = 3554.224124229896;

var Pr = new Array(2);
Pr[0] = 582.2958993165842;
Pr[1] = -3244.3872964941493;
	
var normA = new Array(2);
normA[0] = -0.10812371023446661;
normA[1] = 0.9941374468780125;

function leadingZero(n)
{
	var st = "";
	st = st + n;
	if (st.length < 2) {
		st = "0" + st;
	}
	return st;
}

function addTakeoff(tname, coords, withWinch)
{
//	alert("siteOptionValue.length:"+siteOptionValue.length +"   siteOptionIdx:"+ siteOptionIdx);
	
	if (siteOptionValue.length > siteOptionIdx) {
		siteOptionValue[siteOptionIdx] = coords;    
		siteOptionText[siteOptionIdx] = tname;	   	
		if (withWinch) {
			if (siteWinchOption.length > siteOptionIdx) {
				siteWinchOption[siteOptionIdx] = 1;    
			} else {
				siteWinchOptionsArrayError++;
			}	
		}	
		siteOptionIdx++;
	} else {
		siteOptionsArrayError++;
	}	
}

function paramScriptName()
{
	var i = 0;
	var el =  document.getElementsByTagName("script") 
	while (i < el.length) {
		var Aussage = el[i].src;
		var Ergebnis = Aussage.match(/(mapparms-[A-Za-z0-9_]*.js)/);
		if (RegExp.$1) {
			return RegExp.$1;
			alert("script["+i+"]:"+el[i].src+" Ergebnis:"+RegExp.$1);
		}	
		i++;
	}
}

function siteOptionErrorCheck()
{
	var sn = paramScriptName();
//	alert ("siteOptionIdx:"+siteOptionIdx+"  siteOptionsLength:"+siteOptionsLength);

	if (siteOptionIdx != siteOptionsLength) {
		alert("implementation fault in \""+sn+"\"!\nupdate \"var siteOptionsLength="+siteOptionsLength+";\"\nshould be \"var siteOptionsLength="+siteOptionIdx+";\"");
	}	
	if (siteOptionsArrayError > 0) {
		var soi = siteOptionsArrayError+siteOptionsLength;
		alert("implementation fault in \""+sn+"\"!\nupdate \"var siteOptionsLength="+siteOptionsLength+";\"\nshould be \"var siteOptionsLength="+soi+";\"");
	}	
	if (siteWinchOptionsArrayError > 0) {
		var soi = siteWinchOptionsArrayError+siteWinchOption.length;
		alert("implementation fault in \""+sn+"\"!\nupdate \"var siteWinchOptionsLength="+siteWinchOptionsLength+";\"\nshould be \"var siteWinchOptionsLength="+soi+";\"");
	}	
	if (soundMapIdx != soundMapLength) {
		alert("implementation fault in \""+sn+"\"!\nupdate \"var soundMapLength="+soundMapLength+";\"\nshould be \"var soundMapLength="+soundMapIdx+";\"");
		soundMapLength = soundMapIdx;
	}
}


