var colors = new Array(14);
var numVersions;
var menuNumberOfColumns = 7;

var menus = new Array(10);
var stringFiles = new Array(10);
var versionNames = new Array(10);
var versionCodes = new Array(10);

var numStrings = 30;	
var strings = new Array(numStrings);
for (i=0;i<numStrings;i++) {
	strings[i] = new Array(30);
}	

var ballgray = new Array(7);
var ballred = new Array(7);
var ballorange = new Array(7);

var params;
var myobjs;
var nobj;
var logFlag;
var debugFlag;
var languageCode;
var	stringVersion;		
var	menuVersion;	
var oldImage;

var	languageName;
var timestamp;
var logstr = "";
var slogstr = "";
var langDir;
var iconFlag = true;
var centericonFlag = false;
var buttonToggled;
var gmt;
var timerVisible = false;
var filter = 1;
var logoIcon;
var followedId = "";
var namesVisible = "hidden";
var withText = false;
var picnum = 0;
var picTimer;
var withSound = true;
var singleStep;

var v_session;
var v_user;
var v_mainwidth;
var v_mainheight;
var v_locwidth;
var v_locheight;
var v_admin = false;

var CurrentX;
var CurrentY;
var currentId;
var currentColor;
var currentNum;
var currentFloy;
var currentIcon;

var tatgetX;
var targetY;

function getDefaultMenubar()
{

	var n1 = location.host.indexOf("127.0.0.1");
	if (n1 > -1) {
		userLevel = 10;
	}
	else 
		userLevel = 1;

	languageCode = getCookie("languageCode");
	getLanguageFiles();

 }	
 
 function getMenubar() {
 var txt;
var filnam;

	filnam = "gofstart.html";
	if (!checkBrowser())
		window.location.href =filnam;		
		
	//loadSessionParams();
	preloadImages();
	getDefaultMenubar();
	loadStrings(stringVersion);
	logstr = "";
	initLog();

	oldLanguageCode = languageCode;

	txt = "<script language='JavaScript1.2' src='" + menuVersion; 
	txt += "' type='text/javascript'></script>";	

	document.write(txt);


 } 

 
 function insertTitle(title) {

	 getMenubar();
	
 }


 function getLanguageFiles() {
	
	menus[0] = "HM_Loader_English.js";
	menus[1] = "HM_Loader_Hebrew.js";
		
	stringFiles[0] = "strings_eng.xml";
	stringFiles[1] = "strings_heb.xml";
	
	if ((isNaN(languageCode)) || (languageCode == null)  || (languageCode == ""))
		languageCode = 0;

	stringVersion = stringFiles[languageCode];		
	menuVersion = menus[languageCode];	
	
	languageName = versionNames[languageCode];

}


function loadStrings(filnam) {
var i,j;
var xmlFile,source,result,root,blocks,block;

	try {
		x = filnam.indexOf("_heb");
		if (x > 0) {
			langDir = "right";
			document.all.item("pleasewait").src = hamtenIcon;
		}
		else {
			langDir = "left";
			document.all.item("pleasewait").src = waitIcon;
		}
	}
	catch(e) {
		addToLog("loadStrings <b>Error:</b> "+e.description,10);
	}

	try {	
	    xmlFile = filnam;
	    source = new ActiveXObject("Microsoft.XMLDOM");
		source.async = false;
		source.load( xmlFile );

		//while (source.readyState != 4) {
		//	addToLog("loop source.readyState= "+source.readyState,10);
		//}
		//addToLog("source.readyState= "+source.readyState,10);
		
		if (source.parseError.errorCode != 0)	{
			result = "loadStrings Error #" + source.parseError.errorCode + "\n" + "Line: "+source.parseError.line+"\nReason:" +source.parseError.reason + "\nFile: \n<" + xmlFile + ">";
		    alert(result);
		}
		else {
			root = source.documentElement;
			for (i=0;i<root.childNodes.length;i++) {
				block = root.childNodes.item(i);
				for (j=0;j<block.childNodes.length;j++) {
					strings[i][j] = block.childNodes.item(j).text;
				}
			}
		}
	} catch (e) {
		addToLog("loadStrings <b>Error:</b> "+e.description,10);
		alert( "loadStrings error number: " + e.number +"	\n Error Occured : " + e.description );
	}

}


function addToLog(txt,cflag) {
var now,datstr;

	if (cflag == 100) {
		slogstr += txt;
	}
	else
	if ((cflag == 10) || ((logFlag) && (cflag == 20) && (currentId == followedId))  || ((logFlag) && (cflag == 20) && (followedId == ""))) {
		if (txt == "") {
			logstr += "<tr><td style='color:white'>.</td><td>.</td>";
		}
		else {

			now = new Date();
			datstr = getDateFormatted(now);
		
			logstr += "<tr><td style='font-size:8pt'>" + datstr + "</td>";
			//logstr += "<tr><td style='font-size:8pt'>" + datstr + "</td>";
			logstr += "<td style='font-size:8pt'>" + txt + "</td></tr>";
		}
	}

}	


function getDateFormatted(dateobj) {
var txt;

	day = dateobj.getDate();
	month = dateobj.getMonth()+1;
	year = dateobj.getYear(); 
	
	hours = dateobj.getHours();
	minutes = dateobj.getMinutes();
	seconds = dateobj.getSeconds();
	mills = dateobj.getMilliseconds();
	
	//txt = day + "/" + month + "/" + year + "    " + hours + ":" + minutes + ":" + seconds

	if (hours < 10) hours = "0" + hours;
	if (minutes < 10) minutes = "0" + minutes;
	if (seconds < 10) seconds = "0" + seconds;
	
	txt = hours + ":" + minutes + ":" + seconds + ":" + mills

	return txt;

}


function getDateFormattedShort(dateobj) {
var txt;

	day = dateobj.getDate();
	month = dateobj.getMonth()+1;
	year = dateobj.getYear(); 
	
	hours = dateobj.getHours();
	minutes = dateobj.getMinutes();
	seconds = dateobj.getSeconds();
	
	if (hours < 10)
		hours = "0" + hours;
	if (minutes < 10)
		minutes = "0" + minutes;
		
	txt = day + "/" + month + "/" + year + "    " + hours + ":" + minutes;
	//txt = hours + ":" + minutes + ":" + seconds

	return txt;

}


function gapHorz(num) {
var txt;

	txt = "<img src='images/dot.jpg' width='" + num + "' height='1' border='0' alt=''>";
	return txt;

}


function gapVert(num) {
var txt;

	txt = "<img src='images/dot.jpg' width='1' height='" + num + "' border='0' alt=''>";
	return txt;

}


function initLog() {
var txt;

	nform = 12;
	logstr= "";
	slogstr = "";
	
	txt = "<table bgcolor='white' width='95%' border='1' bordercolor='black' cellpadding='1' cellspacing='1'>"

	txt += "<tr>";
	txt += "<td width='15%' height='10' bgcolor='#ddedbd'> "
	txt += strings[nform][0];   //Time
	txt += "</td>";	
	txt += "<td width='85%' bgcolor='#ddedbd'> ";
	txt += strings[nform][1];   //Description
	txt += "</td>";
	txt += "</tr>";
	
	logstr += txt;
	
}

function initProgram() {

	//window.onerror = myError;
	debugFlag = true;
	//debuglog("Start");

	sessionParams();

	defaultServer = "http://192.117.100.22:180/AtlasNet/AtlasNet.dll";
	
	loadVersions("versions.xml");

	programVersion = parseInt(readCookie("programVersion"));
	languageCode = parseInt(readCookie("languageCode"));
	rgttop = readCookie("rgttop");
	rgtbot = readCookie("rgtbot");		
	withText = readCookie("withText");	
	withSound = readCookie("withSound");	
	cycleDelay = readCookie("cycleDelay");	
	initialEnergy = readCookie("initialEnergy");
	bonusEnergy = readCookie("bonusEnergy");

	if ((isNaN(languageCode)) || (languageCode == null))
		languageCode = 0;	
	getLanguageFiles();

	if ((rgttop == null) || (rgttop == ""))
		rgttop = 1;		
	if ((rgtbot == null) || (rgtbot == ""))
		rgtbot = 1;		
		
	if ((withText == null) || (withText == ""))
		withText = false;	
	if ((withSound == null) || (withSound == ""))
		withSound = true;			
	if ((cycleDelay == null) || (cycleDelay == ""))
		cycleDelay = 10;	
	if ((initialEnergy == null) || (initialEnergy == ""))
		initialEnergy = 10;	
	if ((bonusEnergy == null) || (bonusEnergy == ""))
		bonusEnergy = 3;						

	cycleDelay = parseInt(cycleDelay);	
	initialEnergy = parseInt(initialEnergy);	
	bonusEnergy = parseInt(bonusEnergy);	
	
	saveCookie("languageCode",languageCode,365)		

    waitIcon = "images/dot.jpg";
    hamtenIcon = "images/dot.jpg";	
	logoIcon = "images/gof1.gif";	
	defaultBackground = "images/trees/trees4.jpg";
	langDir = "left";
	oldMenuVersion = menuVersion;
	oldLanguageCode = languageCode;
   	
	myobjs = document.getElementById("objects").childNodes;
	nobj = myobjs.length;
	myobjnames = document.getElementById("objnames").childNodes;
	nobjnames = myobjnames.length;	

	initColors();
	params = new floyParams();
	for (i=0;i<ntypes;i++) {
		params.getParams(i);
	}

	w = parseInt(screen.width*0.95) - 230;
	document.all.mainarea.style.width = w;
	
	background = readCookie("background");
	if (background == null) background = defaultBackground;	
	
	if (withText == true)
		namesVisible = "visible";
	else
		namesVisible = "hidden";	

	createMapMenu(14);
	createObjMenu(15);

	//debuglog("End");

}


function initLoad() {
	
	//txt = createFlash("loading_wave_stdwave_1_blue.swf",140,56,"#396DA5");
	//document.all.item("msgicon").innerHTML = txt;
	
	//alert("Load");
	//txt = createFlash("../flash/loading_wave_stdwave_2.swf",140,60,"#396DA5");
	//document.all.item("logbar").innerHTML = txt;
	//alert(txt);

}

function initLogout() {
/*
	if (logoutRequest == false) {
		alert("Please log out through File/Logout menu command");
		location = self.location;	
	}
*/		
}


function initFocus() {

}


function initColors() {

	colors[0] = "Aqua";
	colors[1] = "Black";
	colors[2] = "Blue";
	colors[3] = "Fuchsia";
	colors[4] = "Gray";
	colors[5] = "Green";
	colors[6] = "Lime";
	colors[7] = "Maroon";
	colors[8] = "Navy";
	colors[9] = "Olive";
	colors[10] = "Purple";
	colors[11] = "Red";
	colors[12] = "Teal";
	colors[13] = "Yellow";
	
}



function addHandlers(o) {

	o.onkeydown = handler;
	o.onkeyup = handler;
	o.onkeypress = handler;

}


function initEventHandler() {

	try {
		document.all.map.onclick = handler;
	
		document.all.map.ondblclick = handler;
		document.all.map.onmousedown = handler;
		document.all.map.onmouseup = handler;
		document.all.map.onmousemove = handler;
		
		document.all.rubberBand.onmouseup = handler;
		document.all.rubberBand.onmousemove = handler;
		
		addHandlers(document.all.legend);
	}
	catch(e){  
		//var interval = setTimeout("initEventHandler()",initialDelay);
		addToLog("initEventHandler <b>Error:</b> "+e.description,10);
	}

}




function handler(e) {

	e = window.event;

	
	if (e.type == "dblclick"){
		return
	}														
											
	
	if (e.type == "mousedown") {

	}
	else
	if (e.type == "mousemove") {

	}	
	else
	if (e.type == "mouseup") {

	}	
	
	if (e.type == "keydown") {
		if ((e.keyCode == 120)) {   //F9
			showTest(2,"auto");
		}
	}	

}


function debuglog(txt) {
var caller,msg,now,now1,elapsed;

	if ((logFlag) || (debugFlag == true)) {
	
      now = new Date();
	  if (txt.indexOf("Start") < 0) {
	  
		  caller = debuglog.arguments.caller.callee.toString();
		  caller = caller.substring(9, caller.indexOf(")")+1);
			
	      msg = "Function: <b>" + caller + "</b>";  
		  if (txt == "End") {
		      now = new Date();
		      elapsed = now - timestamp;
			  elapsed = format(elapsed/1000,2);	
		      if (elapsed < 60000) {
		         msg += " Time: <b>" + elapsed + "</b> Sec.";
		      }
		  }
		  else
 		  	  msg += "<br>Message:<br><b>" + txt + "</b><br>";

			
		  now1 = new Date();
		  //datstr = now1.toLocaleString();
		  datstr = getDateFormatted(now1);
		  logstr += "<tr><td style='font-size:8pt'>" + datstr + "</td>";
	   	  logstr += "<td style='font-size:8pt'>" + msg + "</td></tr>";	
	  }			

      timestamp = now;

	}
}


function format(number,decimals) {
  var i,d;

  if(number=="") number=parseInt("0");
  if(decimals=="") decimals=parseInt("2");

  number=""+Math.round(number*Math.pow(10,decimals))*Math.pow(10,-decimals);

  d=number.indexOf(".");

  if(d==-1) {
    number=number+".";
    for(i=0;i<decimals;i++)
      number=number+"0";
    return number;
  }

  if(d==0) {
    number="0"+number;
    d++;
  }

  if(d==1 && number.substring(0,1)=="-") {
    number="-0" + number.substring(1,number.length);
    d++;
  }

  number=number.substring(0,d+decimals+1);

  while(number.length<=d+decimals)
    number=number+"0";
	
  return number;
}




function loadVersions(filnam) {

    xmlFile = filnam;
    source = new ActiveXObject("Microsoft.XMLDOM");
	source.async = false;
	source.load( xmlFile );

	if (source.parseError.errorCode != 0)	{
		result = "loadVersions Error #" + source.parseError.errorCode + "\n" + "Line: "+source.parseError.line+"\nReason:" +source.parseError.reason + "\nSource url: \n" + source.url;
	    alert(result);
	}
	else {
		root = source.documentElement;
		//var objs = root.childNodes.item(0);
		for (i=0;i<root.childNodes.length;i++) {
			version = root.childNodes.item(i);
			
			code = parseInt(version.getElementsByTagName("code").item(0).text);	
			versionCodes[code] = code;	
			versionNames[code] = version.getElementsByTagName("name").item(0).text;
			menus[code] = version.getElementsByTagName("menufile").item(0).text;
			stringFiles[code] = version.getElementsByTagName("stringfile").item(0).text;
			strings[24][i] = versionNames[code];
		}
	}
	
	numVersions = root.childNodes.length;

}


function displayMenu() {
var posTop;
var posLeft;

   //checkEvent();

   currentId = getObjId();

   posTop = (screen.availHeight-150)/2;
   posLeft = (screen.availWidth-150)/2;

   window.status = "";
   	
   if (currentId == "map") {
	   closeMenu2();	
	   currentEventX = event.clientX;
	   currentEventY = event.clientY;
   	   currentMenu = 1;	
	   document.all.menu1title.innerHTML = createMapMenuTitle();

	   if (event.offsetX > 100)
	   	  menu1.style.posLeft=event.clientX - 100;
	   else
	   	  menu1.style.posLeft=event.clientX - event.offsetX;	
  
       menu1.style.posTop= event.clientY - 30;

	   menu1.style.display="";
	   menu1.setCapture(true);   

	   document.all.menu1.focus();

   }

}


function displayObjectMenu() {
var posTop;
var posLeft;

   //checkEvent();
   currentId = getObjId();
	
   posTop = (screen.availHeight-150)/2;
   posLeft = (screen.availWidth-150)/2;

   closeMenu1();

   currentEventX = event.clientX;
   currentEventY = event.clientY;   
   //currentEventX = event.screenX;
   //currentEventY = event.clientY;  
   
   currentMenu = 2;
   document.all.menu2title.innerHTML = createObjMenuTitle();

   if (currentEventX > 100)
   	  menu2.style.posLeft=event.clientX - 100;
   else
   	  menu2.style.posLeft=event.clientX - event.offsetX;	
	  
   if (currentEventY > (v_mainheight-80))
      menu2.style.posTop=v_mainheight-80;  
   else
      menu2.style.posTop=(event.clientY - event.offsetY);   

//alert("currentEventY= "+currentEventY+" event.clientY= "+event.clientY+" event.offsetY= "+event.offsetY+" menu2.style.posTop= "+menu2.style.posTop+" (event.clientY - event.offsetY)= "+(event.clientY - event.offsetY)+" v_mainheight= "+v_mainheight);

   menu2.style.display="";
   menu2.setCapture(true);
   document.all.menu2.focus();

}


function createObjMenuTitle() {
var txt,title,R;
	
	txt = "";
	try {
	    //R = getObjectById(currentId);
	    //title = R.title;
		
		txt = "<table width='90%'>";
		txt += "<tbody><tr>";
		txt += "<td align='left' class='smallbutton' width='50%'>Floy Id:</td>";
		txt += "<td align='right' class='smallbutton'  width='50%'>";
		txt += currentId;
		txt += "</td>";
		txt += "</tr></tbody></table>";
	}
	catch(e) {
		addToLog("centerMenuTitle <b>Error:</b> "+e.description,10);
	}

	return txt;
	
}	

function createMapMenuTitle() {
var txt,title,R;

	//alert("event.clientX= "+event.clientX+" event.offsetX= "+event.offsetX);
	txt = "<table width='90%'>";
	txt += "<tbody><tr>";
	txt += "<td align='left' class='smallbutton' width='50%'>";
	txt += "x= "+event.offsetX;
	txt += "</td>";
	txt += "<td align='right' class='smallbutton'  width='50%'>";
	txt += "y= "+event.offsetY;
	txt += "</td>";
	txt += "</tr></tbody></table>";

	targetX = event.offsetX;
	targetY = event.offsetY;
	
	return txt;
	
}		 



function showMsg(txttop,txtbot) {
var posLeft,posTop;

    posTop = (screen.availHeight-150)/2;
    posLeft = (screen.availWidth-150)/2;
	posTop = currentEventY - 170;
	posLeft = currentEventX - 100;

	document.all.msgtop.innerHTML = txttop;
	document.all.msgbot.innerHTML = txtbot;

	//msgblock.style.leftPos+=10;
    msgblock.style.posLeft=posLeft;
    msgblock.style.posTop=posTop;
	msgblock.style.display="";

}


function showMsgGen(txttop,txtbot,w,h) {
var posLeft,posTop;

	if (h == 0) {
		posTop = 30;
		posLeft = 10;	
	}
	else {
	    posTop = (screen.availHeight-h)/2;
	    posLeft = (screen.availWidth-(w/2))/2-100;
	}

	document.all.msgtop.innerHTML = txttop;
	document.all.msgbot.innerHTML = txtbot;

	msgblock.style.width = w;
    msgblock.style.posLeft=posLeft;
    msgblock.style.posTop=posTop;
	msgblock.style.display="";

}


function closeMsg() {

	msgblock.style.display="none";
	
}


function showMsgWindow(txt) {

	menu1.style.display="none";
	
	txttop = "<img src='images/dot.jpg' width='1' height='10' border='0' alt=''>";
	txttop += "<hr><p>";
	txttop += txt;
	txttop += "<hr><p>";
	
	txtbot = "<p><input type='button' name='close_showlocation' value='Close' onclick='javascript:closeMsg()' class='buttonCSS'>";
	
	showMsg(txttop,txtbot);
}


function clickMenu() {
var el,flagscale,nid;

   el=event.srcElement;
		
   if (currentMenu == 1) {	
	   menu1.releaseCapture();

	   if (el.id=="mnu1Attraction") {
	   		showCenterIcon();
			menu1.style.display="none";
	   } 
	   else 
	   if (el.id=="mnu1Close") {
	   	    menu1.style.display="none";
	   } 
   }
   else
   if (currentMenu == 2) {
	   menu2.releaseCapture();
	   menu2.style.display="none";
	   	
	   if (el.id=="mnu2Assign") {
		  startFollow();
		  menu2.style.display="none"; 
	   } 
	   else 
	   if (el.id=="mnu2Hide") {
	      x = setObj(currentId,"",0,"hidden"); 
		  menu2.style.display="none"; 
	   } 	   	   
	   else 
	   if (el.id=="mnu2Reset") {
		  stopFollow();
		  menu2.style.display="none";   
	   } 
	   else 
	   if (el.id=="mnu2Delete") {
		  n = getObjectInumber(currentId);
		  deleteFloy(n);
	   } 	   
	   else 
	   if (el.id=="mnu2Data") {
		  withMsg = false;
		  showProperties();
		  withMsg = true;
		  menu2.style.display="none"; 
	   } 
	   else 
	   if (el.id=="mnu2Message") {
	      //sendMessageToId(currentId);  
		  menu2.style.display="none"; 
	   } 	   
	   else 
	   if (el.id=="mnu2Refresh") {
		  menu2.style.display="none"; 
	   } 	
	   else 
	   if (el.id=="mnu2neighbors") {
	      //displayNeighbors(currentId);  
		  menu2.style.display="none"; 
	   } 		
	   else 
	   if (el.id=="mnu2Close") {
	      menu2.style.display="none"; 
	   }   
	}          

}



function switchMenu() {   
   el=event.srcElement;
   if (el.className=="menuItem") {
      el.className="highlightItem";
   } else if (el.className=="highlightItem") {
      el.className="menuItem";
   }
}

function closeMenu1() {

	menu1.style.display="none";

}


function closeMenu2() {

	menu2.style.display="none";
	
}


function getObjId() {
var id, found, R, i;

	id =  window.event.srcElement.id;

	return id;

}





function getRightPanel() {

	if (rgtbot == 1)
		document.all.legend.innerHTML = createLegend();
	else
	if (rgtbot == 2)	
		document.all.legend.innerHTML = createFastButtons();
	else
	if (rgtbot == 3)
		document.all.legend.innerHTML = createCustomGraphics();
	else	
	if (rgtbot == 4)
		document.all.legend.innerHTML = createEmptyPanel();
	else
		document.all.legend.innerHTML = "";		

	updateLightButtons();	
	//putSmallMap();

}

function boldText(txt,typ,func) {
var newtxt;

	if (typ == 0) {
		newtxt = "<a href='javascript:" + func + "()'>";
	 	newtxt += "<b>" + txt + "</b></font></a>";	
	}
	else
	if (typ == 1) {
		newtxt = "<a href='javascript:" + func + "()'>";
	 	newtxt += "<font color='#FF0000'><b>" + txt + "  &hearts;" + "</b></font></a>";
	}
	else
	if (typ == 2) {
		newtxt = "<a href='javascript:" + func + "()'>";
		newtxt += "<font color='#FFFFFF'><b>" + txt + "</b></font></a>";
	}

	return newtxt;	

}


function updateLightButtons() {
var id, num, func;

	nform = 1;

	try {
		id = "loglight";
		num = 4;	
		func = "toggleLog";
		if (logFlag == true) {
			document.all.item(id).innerHTML = boldText(strings[nform][num],1,func);
		}
		else {
			document.all.item(id).innerHTML = boldText(strings[nform][num],0,func);		
		}

		id = "nalight";
		num = 5;	
		func = "toggleTooltips";		
		if (namesVisible == "visible")	{
			document.all.item(id).innerHTML = boldText(strings[nform][num],1,func);			
		}
		else {
			document.all.item(id).innerHTML = boldText(strings[nform][num],0,func);			
		}

		id = "cilight";
		num = 6;	
		func = "toggleCenterIcon";		
		if (centericonFlag == true) {
			document.all.item(id).innerHTML = boldText(strings[nform][num],1,func);		
		}
		else {
			document.all.item(id).innerHTML = boldText(strings[nform][num],0,func);			
		}	
					
	}
	catch(e) {
		addToLog("updateLightButtons <b>Error:</b> "+e.description,10);
	}

}





function toggleLog() {

	if (!logFlag) {
		logFlag = true;
		//document.all.loglight.src = ballred[4].src;  //"images/ballred1.gif";
	}
	else {
		logFlag = false;
		//document.all.loglight.src = ballgray[4].src;  //"images/ballgray1.gif";
	}	
	
	updateLightButtons();
	buttonToggled = true;

}


function toggleCenterIcon() {

	if (!centericonFlag) {
		centericonFlag = true;
		//document.all.cilight.src = ballred[6].src;  //"images/ballred1.gif";
		document.all.item("centericon").style.visibility = "visible";
	}
	else {
		centericonFlag = false;
		//document.all.cilight.src = ballgray[6].src;  //"images/ballgray1.gif";
		document.all.item("centericon").style.visibility = "hidden";
	}	
	
	updateLightButtons();
	buttonToggled = true;

}


function showCenterIcon_old(flag) {

	if (flag) {
		//centericonFlag = true;
		//document.all.cilight.src = ballred[6].src;  //"images/ballred1.gif";
		document.all.item("centericon").style.visibility = "visible";
	}
	else {
		//centericonFlag = false;
		//document.all.cilight.src = ballgray[6].src;  //"images/ballgray1.gif";
		document.all.item("centericon").style.visibility = "hidden";
	}	
	
	updateLightButtons();
	buttonToggled = true;

}


function initMap() {
var map1;
var map2;
var items;
var txt;

	//window.status = strings[16][30];   //"Initializing program";
	initProgram();
	//debuglog("Start");	

	//setDeveloperAttributes();
	//map1 = v_serverurl + "?action=s&x_map=" + v_startx + "&y_map=" + v_starty + "&zoom_level=" + v_scale + "&cached=0&format=map&session_id=" + v_session+ "&cid=" + Math.random();

	targetX = parseInt(v_mainwidth/2);
	targetY = parseInt(v_mainheight/2);
	
	document.all.map.style.width = v_mainwidth;
	document.all.map.style.height = v_mainheight;	
	document.all.map.style.top = 2;
	document.all.map.style.left = 2;	

	document.all.maingroup.style.width = v_mainwidth;
	document.all.maingroup.style.height = v_mainheight;	
	document.all.maingroup.coordsize = v_mainwidth + " " + v_mainheight;	

	document.all.map.src = background; 

	document.all.sidemap.style.width = v_locwidth;
	document.all.sidemap.style.height = v_locheight;	
	document.all.sidemap.style.top = 2;
	document.all.sidemap.style.left = 2;	

	document.all.sidegroup.style.width = v_locwidth;
	document.all.sidegroup.style.height = v_locheight;	
	document.all.sidegroup.coordsize = v_locwidth + " " + v_locheight;	

	putSmallMap();
	getRightPanel();

	initEventHandler();

	setObjsVisibility("hidden");
	//var interval = setTimeout("initItems()",initialDelay);

	initCenterIcon();
	window.status = "";
	//debuglog("End");

}

function setObjsVisibility(flag) {
var i;
var R;

	try {
		nobj = myobjs.length;
		if (nobj > 0) {
			for (i=0;i<nobj;i++) {
				R = myobjs.item(i);
				R.style.visibility = flag;
			}
		}
	} catch (e) {
		//alert( "Error number: " + e.number +"	\n Error Occured : " + e.description );
		addToLog("setObjsVisibility 2 <b>Error:</b> "+e.description,0);
	}	
			
}		

function sessionParams() {
var dateobj, month;

	v_mainwidth = Math.floor(screen.availWidth *.74);
	v_mainheight = Math.floor(screen.availHeight *.65);

	languageCode = readCookie("languageCode");
	if ((isNaN(languageCode)) || (languageCode == null))
		languageCode = 0;	

	v_locwidth = 100;
	v_locheight = 250;
	
	dateobj = new Date();
	month = dateobj.getMonth()+1;
	if ((month > 5) && (month < 10))
	//if (summerTime == 1)
		gmt = Math.abs(gmt*60*1000)+60*60*1000;   
	else
		gmt = Math.abs(gmt*60*1000);	

}

function initCenterIcon() {

	document.all.item("centericon").src = "images/target2.gif";
	document.all.item("centericon").title = "Attraction point";  //strings[16][28];
	document.all.item("centericon").style.zIndex = 50;
	document.all.item("centericon").style.width = 32;
	document.all.item("centericon").style.height = 32;
	document.all.item("centericon").style.left = parseInt(v_mainwidth/2-16);
	document.all.item("centericon").style.top = parseInt(v_mainheight/2-16);
	document.all.item("centericon").style.visibility = "hidden";
	centericonFlag = false;

}

function showCenterIcon() {

	document.all.item("centericon").style.left = targetX - 10;
	document.all.item("centericon").style.top = targetY - 10;
	document.all.item("centericon").style.visibility = "visible";
	centericonFlag = true;
	//document.all.cilight.src = ballred[6].src;  //"images/ballred1.gif";
	updateLightButtons();
	
}

function hideCenterIcon() {

	document.all.item("centericon").style.visibility = "hidden";
	centericonFlag = false;
	
}

function closeAllMenus() {

	try {
		closeMenu1();
		closeMenu2();
	}
	catch(e) {
		addToLog("closeAllMenus <b>Error:</b> "+e.description,10);
	}

}

function hoverinx(id,num)
{

	lastHover = document[id].src;
	
	
	if (buttonToggled == false) {
		document.images[id].src = ballorange[num].src;  //"images/ballorange1.gif";
	}		
	else
		buttonToggled = false;	
	
}

function hoveroutx(id,num)
{

	if (buttonToggled == false) {
	    document.images[id].src = lastHover;   
	}		
	else
		buttonToggled = false;	

}


function hoverinx2(id,num) {
	document.images[id].src = ballred[num].src;  //"images/ballred1.gif";
	//document.all.item(id).innerHTML = "<font size='+1'>&hearts;</font>";
}

function hoveroutx2(id,num) {
	document.images[id].src = ballgray[num].src;  //"images/ballgray1.gif";
	//document.all.item(id).innerHTML = "<font size='+1'>&spades;</font>";
}

function hoverinx3(id,num) {
	document.all.item(id).innerHTML = boldText(strings[1][num],1);
}

function hoveroutx3(id,num) {
	document.all.item(id).innerHTML = boldText(strings[1][num],0);
}

function hoverinx1(id)
{

	lastHover = document.all.item(id).innerHTML;
	
	if (buttonToggled == false) {
		if (id.substring(0,2) == "au")
			//document[id].src="images/ballorange.gif";
			document.all.item(id).innerHTML = "<font size='+1'>&hearts;</font>";
		else
		if (id.substring(0,2) == "lo")
			//document[id].src="images/ballorange.gif";
			document.all.item(id).innerHTML = "<font size='+1'>&hearts;</font>";
		else
		if (id.substring(0,2) == "na")
			//document[id].src="images/ballorange.gif";
			document.all.item(id).innerHTML = "<font size='+1'>&hearts;</font>";	
		else
		if (id.substring(0,2) == "te")
			//document[id].src="images/ballorange.gif";	
			document.all.item(id).innerHTML = "<font size='+1'>&hearts;</font>";
		else
		if (id.substring(0,2) == "st")
			//document[id].src="images/ballorange.gif";	
			document.all.item(id).innerHTML = "<font size='+1'>&hearts;</font>";											
		else		
	    	//document[id].src="images/ballorange.gif";
			document.all.item(id).innerHTML = "<font size='+1'>&hearts;</font>";
	}		
	else
		buttonToggled = false;	
	
	
}

function hoveroutx1(id)
{

	if (buttonToggled == false) {
		if (id.substring(0,2) == "aa")
	    	document[id].src="images/ballblue1.gif";
		else
		if (id.substring(0,2) == "bb")
	    	document[id].src="images/ballred1.gif";		
		else
	    	document.all.item(id).innerHTML = lastHover;   
	}		
	else
		buttonToggled = false;	

}



function getLanguageCodeByName(name) {

	languageCode = 0;
	
	for (i=0;i<numVersions;i++) {
		if (name == versionNames[i]) {
			languageCode = versionCodes[i];
			break;
		}
	}
	
	return languageCode;

}


function updateLanguageVersion() {

	if (oldLanguageCode != languageCode) {
	    window.status = "";	
		getLanguageFiles();
		document.location.reload(true);
		loadStrings(stringVersion);
		oldLanguageCode = languageCode;				
	}	
	else {
		putSmallMap();
	}
}

function gotest(num) {

	if (num == 1) {
		deleteFloy(1);
	}
	if (num == 2) {
		 document.all.sound.src = "Joy.au";
	}	
	else
	if (num == 3) {
		initNeighbors();
	}
	else
	if (num == 4) {
		//insertFloy(1);
		checkBrowser();
	}

}


function toggleTimer() {

	if (timerVisible) {
		getRightPanel();
		timerVisible = false;
	}
	else {
		initTimer();
		timerVisible = true;
	}
	
	putSmallMap();
	
}

function testPlayFlash() {

	txt = createFlash("loading_wave_stdwave_1_blue.swf",140,56,"#396DA5");
	document.all.item("msgicon").innerHTML = txt;
	alert("Continue");
	txt = createFlash("loading_wave_stdwave_1.swf",140,56,"#f7efde");
	document.all.item("msgicon").innerHTML = txt;	
	alert("Continue");
	txt = createFlash("teina_wave_stdwave_1.swf",140,56,"#f7efde");
	document.all.item("msgicon").innerHTML = txt;			
	alert("Continue");
	txt = createFlash("loading_rotate_turn_4.swf",140,56,"#f7efde");
	document.all.item("msgicon").innerHTML = txt;
	alert("Continue");
	txt = createFlash("teina_rotate_turn_4.swf",140,56,"#f7efde");
	document.all.item("msgicon").innerHTML = txt;					
	alert("Stop");
	document.all.item("msgicon").innerHTML = "";
		
}		


function initTimer() {

	document.all.item("firstmsg").innerHTML = createTimerGui();
	//document.all.item("firstmsg").style.visibility = "hidden";
	
}


function toggleLayer(layer) {

	if(document.all.item(layer).style.visibility != "hidden")
		document.all.item(layer).style.visibility = "hidden";
	else
		document.all.item(layer).style.visibility = "visible";
	
}




function switchLayer(layer,flag) {

	try {
		//document.all.item(layer).style.visibility = flag;
		eval ("document.all." + layer + ".style.visibility='" + flag + "'");
	}
	catch(e) {
		//addToLog("switchLayer <b>Error:</b> "+e.description,0);
	}
	
}


function greffect(filter) {

	if (filter == 1) {
		window.status = "Xray";
		document.all.map.style.filter = "xray";
	}
	else
	if (filter == 2) {
		window.status = "Invert";
		document.all.map.style.filter = "invert";
	}	
	else
	if (filter == 3) {
		window.status = "Flip";
		document.all.map.style.filter = "flipH";
	}		
	else
	if (filter == 4) {
		window.status = "Gray";
		document.all.map.style.filter = "gray";
	}		
	else
	if (filter == 5) {
		window.status = "Wave";
		document.all.map.style.filter = "wave(freq=6, strength=15, phase=0, lightstrength=0, add=0, enabled=1)";
	}			
	else
	if (filter == 6) {
		window.status = "";
		document.all.map.style.filter = "none";
	}	
}

function getFunctionName() {
var caller;

	caller = test8.arguments.caller.callee.toString();
	caller = caller.substring(9, caller.indexOf(")")+1);
	  
	alert("caller= "+caller);
	
}

function toggleDebug() {

	debtoggle();
	alert("Debug mode: "+debugFlag);

}

function debtoggle() {

	debugFlag = !debugFlag;
	
}
	
	

function bgColor(color) {

	if (color == "red") 
		document.all.map.src = "images/rect_red.jpg";
	else
	if (color == "gray") 
		document.all.map.src = "images/rect_gray.jpg";
	else
	if (color == "black") 
		document.all.map.src = "images/rect_black.jpg";
	else
		document.all.map.src = "images/rect_beige.jpg";
	
}

function bgPicture(filename) {

	//document.all.sidemap.src = filename;
	document.all.map.src = filename;
	
}


function showLog() {
var txt;

	nform = 12;
	txt = logstr + "</table>";
	showString(txt);
	//popTextWindow(10,strings[12][2],txt,0,0,0);
	
}

function showHelp() {

	showText("gof_overview");
	
}

function popTextWindow(nform,title,txtdata,fw,fh,tim) {
var txt,ftxt,w,h;

	nform = 12;
	if (fh == 0)
    	h = screen.availHeight-150;
	else
		h = parseInt(screen.availHeight/fh);
		
	if (fw == 0)
    	w = screen.availWidth-100;
	else
		w = parseInt(screen.availWidth/fw);
	
	ftxt = "<script language='javascript'>";	
	ftxt += "function showMe() {";
	if (tim == 0) {
		ftxt += "";
	}
	else
		if (tim < 10) {
			ftxt += "window.focus();";
			ftxt += "iv = setTimeout('window.close()',"
			ftxt += parseInt(updateInterval*60*1000/tim);
			ftxt += ")";
		}
	else {
		ftxt += "window.focus();";
		ftxt += "iv = setTimeout('window.close()',"
		ftxt += tim*1000;
		ftxt += ")";
	}
	ftxt += "}";
	ftxt += "</script>";

	var w = window.open("","","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, height=" + h + " , width=" + w + ", left=50, top=30"); 
	var d = w.document;
	
	txt = "<html><head>"
	txt += "<style type='text/css'>"
	txt += ".ButtonCSS {"
    txt += "font-family : Arial, Tahoma, Helvetica, sans-serif;"
    txt += "font-size: 8pt;"
	txt += "font-weight: bold;"
	txt += "width: 150px;"
	txt += "height: 30px;}"	
	txt += "</style>"
	txt += "<link rel=stylesheet type='text/css' href='xv.css'>";
	//txt += "<script language='javascript'>";
	//txt += "function showMe() {";
	//txt += "window.focus();";
	//txt += "iv = setTimeout('window.close()',"
	txt += ftxt;
	//txt += ")}";
	//txt += "</script>";
	txt += "</head><body bgcolor='#f7efde' onload='showMe()'>"
	txt += "<div align='center'>";
	txt += "<div class='header3'>" + title + "</div>";
	txt += "</div>";
	txt += "<p>";
	txt += txtdata;
	txt += "<p>";

	txt += "<div align='center'>";
	txt += "<input type='button' name='";
	txt += "print";
	txt += "' value='";
	txt += strings[nform][3];   //"Print";
	txt += "' onclick='window.print()' class='buttonCSS'>";	

	txt += "<img src='images/dot.jpg' width='20' height='1' border='0' alt=''>";

	txt += "<input type='button' name='";
	txt += "close";
	txt += "' value='";
	txt += strings[nform][4];   //"Close";
	txt += "' onclick='self.close()' class='buttonCSS'>";	

	txt += "</div>";
	txt += "</from></div></body></html>";
	d.write(txt);
	d.close();
	//addToLog("popTextWindow ftxt= "+putPre(ftxt),10);	
	//addToLog("popTextWindow txt= "+putPre(txt),10);
}	

function notReady() {

	alert("Not ready yet");
	
}

function startFollow() {

	if (followedId != "") {
		x = setObj(followedId,params.color[0],0,"");
		R = getObjectById(followedId);
		ni = getObjectInumber(R.id);	
		R.fillColor = params.color[0];
	}
	x = setObj(currentId,"fuchsia",0,"top");
	followedId = currentId;

}


function stopFollow() {

	x = setObj(currentId,params.color[0],0,"visible"); 
	R = getObjectById(currentId);
	ni = getObjectInumber(R.id);		
	R.fillColor = params.color[0];	
	followedId = "";
		  
}	


function blinkFloy() {

	x = setObj(currentId,params.color[0],0,"visible"); 
	R = getObjectById(currentId);
	ni = getObjectInumber(R.id);		
	R.fillColor = "white";	
	var interval = setTimeout("unblinkFloy()",2000);
		  
}	

function unblinkFloy() {

	x = setObj(currentId,params.color[0],0,"visible"); 
	R = getObjectById(currentId);
	ni = getObjectInumber(R.id);		
	R.fillColor = floys[ni].icon.fillColor;	
		  
}	


function getObjectById(id) {
var i,R;

	R = null;
	nobj = myobjs.length;

	for (i=0;i<nobj;i++) {
		R = myobjs.item(i);
		if (R.id == id) {
			return R;
		}
	}

	return R;
}

function getObjectInumber(id) {
var num,R;

	num = -1;
	try {
		myobjs = document.getElementById("objects").childNodes;
		nobj = myobjs.length;
		for (i=0;i<nobj;i++) {
			R = myobjs.item(i);
			if (R.id == id) {
				num = i;
				break;	
			}
		}
	}
	catch(e) {
		addToLog("getObjectInumber <b>Error:</b> "+e.description,10);
	}

	return num;
}



function setObj(id,color,size,vis) {
var id, found, R, i;

	try {
		myobjs = document.getElementById("objects").childNodes;
		nobj = myobjs.length;	
		found = false;

		for (i=0;i<nobj;i++) {
			R = myobjs.item(i);
			if (R.id == id) {
				found = true;
				break;
			}
		}
	
		if (found == true) {	
			if (size > 0) {
				R.style.width = size;
				R.style.height = size;	
			}
				
			if (color != "") {
				R.fillColor = color;
			}
	
			if (vis != "") {
				if (vis == "top") {
					R.style.zIndex = 20;
					R.style.visibility = "visible";
				}
				else {
					R.style.zIndex = 8;
					R.style.visibility = vis;				
				}
			}	

		}
	}
	catch(e) {
		addToLog("setObj <b>Error:</b> "+e.description,10);
	}

}

function showProperties() {
var R,n,txt,id;
	
	id = currentId;
	R = getObjectById(id);
	n = getObjectInumber(R.id);	
	txt = floys[n].getProperties();
	document.all.item("smallmap").innerHTML = txt;	
	
}

function toggleFloys(flag) {

	try {
		for (i=0;i<nf;i++) {
			floys[i].icon.style.visibility = flag;
		}
	
		if (namesVisible == "visible") {
			for (i=0;i<nf;i++) {
				floys[i].tooltip.style.visibility = flag;
			}	
		}
	}
	catch(e) {
	}

}

function printPage(flag) {

	nform = 13;
	if (flag == 1) {
	    if (window.print) {
	        if (confirm(strings[nform][0])) {
	            window.print();
	        }
	    }
	}
	else {
	    if (window.print) {
            window.print();
	    }
	}
	
}

function copyToClipboard(txt) {

	window.clipboardData.setData('text',txt);
	
}




function getCookieVars(txt) {
var n,nn,i,pair;

	var names = new Array(50);
	var values = new Array(50);

	if (txt == null) {
		return;
	}
	else {	
		i = 0;
		n = txt.indexOf("&");
	
		while (n > 0) {
			pair = txt.substr(0,n);
			nn = pair.indexOf("=");
			names[i] = pair.substr(0,nn);
			values[i] = pair.substr(nn+1);
			txt = txt.substr(n+1);
			n = txt.indexOf("&");
			i++;
		}
		
		pair = txt
		nn = pair.indexOf("=");
		names[i] = pair.substr(0,nn);
		values[i] = pair.substr(nn+1);	
	}

}

function getCookieValue(txt,field) {
var n,nn,i,pair,name,value;

	if (txt == null) {
		return "";
	}
	else {
		i = 0;
		n = txt.indexOf("&");
	
		while (n > 0) {
			pair = txt.substr(0,n);
			nn = pair.indexOf("=");
			name = pair.substr(0,nn);
			value = pair.substr(nn+1);
			if (name == field) {
				return value;
			}
			txt = txt.substr(n+1);
			n = txt.indexOf("&");
			i++;
		}
		
		pair = txt
		nn = pair.indexOf("=");
		name = pair.substr(0,nn);
		value = pair.substr(nn+1);	
		if (name == field)
			return value;
		else
			return "";
	}

}

function showText(code) {
var txt, t;
	//openWindScroll("gof_overview.html", 700, 400);
	
	nform = 11;
	t = document.all.map.innerHTML;
	if (t.indexOf("<vml:image") > 0) {
		oldImage = document.all.map.innerHTML;
	}	
		
	txt = "<div style='width:" + parseInt(v_mainwidth*0.95) + ";height:" + parseInt(v_mainheight*0.9) + ";overflow:scroll' align='left'>";
	txt += GetText(code);
	txt += "</div>";
	
	txt += gapVert(30);

	//txt += "<div align='center>"
	txt += "<input type='button' name='but1' value='";
	txt += strings[nform][2];   //"Close"  
	txt += "' onclick='javascript:restoreImage()' class='buttonCSS'  align='center'>"
	//txt += "</div>";

	stopFloys();
	toggleFloys("hidden");
	document.all.item('map').innerHTML = txt;
}


function showString(text) {
var txt, t;
	//openWindScroll("gof_overview.html", 700, 400);
	
	nform = 11;
	t = document.all.map.innerHTML;
	if (t.indexOf("<vml:image") > 0) {
		oldImage = document.all.map.innerHTML;
	}	
		
	txt = "<div style='width:" + parseInt(v_mainwidth*0.95) + ";height:" + parseInt(v_mainheight*0.9) + ";overflow:scroll' align='left'>";
	txt += text;
	txt += "</div>";
	
	txt += gapVert(30);

	//txt += "<div align='center>"
	txt += "<input type='button' name='but1' value='";
	txt += strings[nform][2];   //"Close"  
	txt += "' onclick='javascript:restoreImage()' class='buttonCSS'  align='center'>"
	//txt += "</div>";

	toggleFloys("hidden");
	document.all.item('map').innerHTML = txt;
}

function restoreDefaultAttributess() {

	params.defaultParams();
	
	background = "images/trees/trees4.jpg";
	document.all.map.src = background;
	saveCookie("background",background,365);
	
	rgtbot = 1;
	getRightPanel();
	saveCookie("rgtbot",rgtbot,365);
	
	if (floysActivated) resetFloys();

}


function preloadImages() {
var i;

	for (i=0;i<7;i++) {
		ballgray[i] = new Image();
		ballgray[i].src = "images/ballgray1.gif";
		ballred[i] = new Image();
		ballred[i].src = "images/ballred1.gif";
		ballorange[i] = new Image();
		ballorange[i].src = "images/ballorange1.gif";	
	}	

}


function playStartButton(num) {

	if (num == 1)
		window.location.href = "gof.html";
	else
	if (num == 2)
		document.all.item("starticon").src = "images/Start_1b.gif";
	else
	if (num == 3)
		document.all.item("starticon").src = "images/Start_1a.gif";

}


function playHomeButton(num) {

	if (num == 1)
		window.location.href = "../index.html";
	else
	if (num == 2)
		document.all.item("homeicon").src = "images/Home_1b.gif";
	else
	if (num == 3)
		document.all.item("homeicon").src = "images/Home_1a.gif";

}


function showViewlet(filename) {

	openViewlet(filename, 859,690);
	
}


