var agt=navigator.userAgent.toLowerCase();
// browserVer und Version bestimmen
var nav = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)));
var ie = (agt.indexOf("msie") != -1);
var version = parseInt(navigator.appVersion);
var ns = navigator.userAgent.indexOf('Netscape')!=-1;
var ns6 = (!document.layers) && ns?true:false;

// browserVerversion in Ordnung?
var browserVer=0;
if ((nav && version > 2) || (ie && version > 3)) {
     browserVer = 1;
} else { 
     browserVer = 0;
}


var defInfo = "CalSky - calculates the sky for you, the astronomical calendar of your sky!";

// Functions for line info
//  function s(txt) { window.status=txt; return 1;}
  function s(txt) { 
    window.status=txt;
	if (document.F && document.F.objectname) {
      if (txt.length) {
	    txt = txt.replace(/Alp \s*/,"alpha ");
	    txt = txt.replace(/Bet \s*/,"beta ");
	    txt = txt.replace(/Gam \s*/,"gamma ");
	    txt = txt.replace(/Del \s*/,"delta ");
	    txt = txt.replace(/Eps \s*/,"epsilon ");
	    txt = txt.replace(/Zet \s*/,"zeta ");
	    txt = txt.replace(/Eta \s*/,"eta ");
	    txt = txt.replace(/The \s*/,"theta ");
	    txt = txt.replace(/Iot \s*/,"iota ");
	    txt = txt.replace(/Kap \s*/,"kappa ");
	    txt = txt.replace(/Lam \s*/,"lambda ");
	    txt = txt.replace(/My \s*/,"my ");
	    txt = txt.replace(/Ny \s*/,"ny ");
	    txt = txt.replace(/Xi \s*/,"xi ");
	    txt = txt.replace(/Omi \s*/,"omicron ");
	    txt = txt.replace(/Pi \s*/,"pi ");
	    txt = txt.replace(/Rho \s*/,"rho ");
	    txt = txt.replace(/Sig \s*/,"sigma ");
	    txt = txt.replace(/Tau \s*/,"tau ");
	    txt = txt.replace(/Yps \s*/,"ypsilon ");
	    txt = txt.replace(/Phi \s*/,"phi ");
	    txt = txt.replace(/Chi \s*/,"chi ");
	    txt = txt.replace(/Psi \s*/,"psi ");
	    txt = txt.replace(/Ome \s*/,"omega ");
	    document.F.objectname.value = txt;
		
	  }
//	  else document.F.objectname.value=defInfo;
	}
  }
  
  s(defInfo);
  
  
  function myMouseMove() { }
  
// Functions for OnMouseOver/OnMouseOut
  if (browserVer == 1) {
       button = new Array();
  }

  
  function Grafik(name,bild) {
  	base=this;
    if (browserVer == 1) {
//            base.bild = new Image();
//            base.bild.src = "/observer/menu/" + bild + "0.gif";
//            base.bild_invers = new Image();
//            base.bild_invers.src = "/observer/menu/" + bild + "1.gif";
            base.name = new Image();
            base.name.src = "/observer/menu/" + bild + "0.gif";
            base.name_invers = new Image();
            base.name_invers.src = "/observer/menu/" + bild + "1.gif";
    }
  }


  function wechsle_normal(id,state) {
       if ((browserVer == 1 && !state)) {
               document[id].src = button[id].name.src;
       }
//	   s(defInfo);
  }
      
  function wechsle_invers(id,state,info) {
//	   alert(id + '  ' + button[id].name_invers.src)
       if (browserVer == 1 && !state) {     
               document[id].src = button[id].name_invers.src;
       }
	   if (info) window.status=info;
  }

  function wechsle_alle_invers(id) {
       if (browserVer == 1) {
               for (var name in button) {
                       if (name != id) {
                               wechsle_normal(name);
                       }
               }
       }
  }


  function loadImages() {
	if (browserVer >= 1) 
	{
    	 button["Intro"] = new Grafik("Intro","Intro");
    	 button["Calendar"] = new Grafik("Calendar","Calendar");
    	 button["Sun"] = new Grafik("Sun","Sun");
    	 button["Moon"] = new Grafik("Moon","Moon");
    	 button["Planets"] = new Grafik("Planets","Planets");
    	 button["Comets"] = new Grafik("Comets","Comets");
    	 button["Asteroids"] = new Grafik("Asteroids","Asteroids");
    	 button["Meteors"] = new Grafik("Meteors","Meteors");
    	 button["Deep-Sky"] = new Grafik("Deep-Sky","Deep-Sky");
    	 button["Satellites"] = new Grafik("Satellites","Satellites");
    	 button["nIntro"] = new Grafik("nIntro","night/Intro");
    	 button["nCalendar"] = new Grafik("nCalendar","night/Calendar");
    	 button["nSun"] = new Grafik("nSun","night/Sun");
    	 button["nMoon"] = new Grafik("nMoon","night/Moon");
    	 button["nPlanets"] = new Grafik("nPlanets","night/Planets");
    	 button["nComets"] = new Grafik("nComets","night/Comets");
    	 button["nAsteroids"] = new Grafik("nAsteroids","night/Asteroids");
    	 button["nMeteors"] = new Grafik("nMeteors","night/Meteors");
    	 button["nDeep-Sky"] = new Grafik("nDeep-Sky","night/Deep-Sky");
    	 button["nSatellites"] = new Grafik("nSatellites","night/Satellites");
	}
  }
  loadImages();




// Pop-up Window for Spacewarn
  var winname='viewer';
  var defwidth=480;
  var defheight=320;
  var winfeatures = 'scrollbars,resizable';
  function popup(url,win,size,height,features) {
	  if (win) { winname=win; }
	  if (features) { winfeatures=features; }
	  if (size) { defwidth=size; defheight=size; }
	  if (height) { defheight=height; }
	  winfeatures = "width="+defwidth+",height="+defheight+","+winfeatures;
	  if (winname) { newwin = window.open(url, winname, winfeatures); }
	  else { newwin = window.open(url, winfeatures); }	
	  newwin.focus();	
  }

  var winext="external";
  function launch(url,win) { 
    w=winext; 
	if (win) {w=win;} 
	newwin = window.open(url,w);
	newwin.focus();	
  }


  var standbyText = ''
  function showstandby()
  {
    if (standbyText.length) {
	  var w = 200;
	  var h = 300;
	  if (ns6 && document.getElementById("loadingIE")) {
    	  document.getElementById("loadingIE").innerHTML=standbyText;
		  document.getElementById("loadingIE").style.top = h;
		  document.getElementById("loadingIE").style.left = w;
		  document.getElementById("loadingIE").style.visibility = "visible";
	  }	
	  else if (document.layers && document.layers.loading) {
    		alert(standbyText);
			document.layers.loading.document.open();
    		document.layers.loading.document.write(standbyText);
    		document.layers.loading.document.close();
    		document.layers.loading.style.top = h;
    		document.layers.loading.style.left = w;
    		document.layers.loading.style.visibility = "visible";
	  }
	  else if (document.all && window.print && document.all.loadingIE && standbyText) {
		document.all.loadingIE.innerHTML = standbyText;
    	document.all.loadingIE.style.top  = h;
    	document.all.loadingIE.style.left = w;
    	document.all.loadingIE.style.visibility = "visible";
	  }  
	}
  }
  
  var toutId;

  function loader() {
    if (toutId) window.clearTimeout(toutId);
	if (standbyText.length) {
		if (ns) {
			if (ns6 && document.getElementById("loadingIE")) {
				document.getElementById("loadingIE").style.visibility = "hidden";
				//document.getElementById("loadingIE").innerHTML = "";
			}	
			else if (document.layers && document.layers.loading) {
 				document.layers.loading.visibility = 'hidden';
	    		//document.layers.loading.document.open();
				//document.layers.loading.document.write("");
	    		//document.layers.loading.document.close();
	//			var main = document.layers.loading.parentLayer;
	//			main.visibility = 'visible';
			}
		} else {
			if (document.all && window.print && document.all.loadingIE) {
     			document.all.loadingIE.style.visibility = "hidden";
				//document.all.loadingIE.innerHTML = "";
			}
		}
	}
  }


  function drawBox( win, text, title,width) {
  	if (!width) { width=160; }
	var w1=width-2; var w2=width-18;
		
	win.document.writeln('<table width="'+width+'" cellspacing="0" cellpadding="0" border="0">');
	win.document.writeln('<tr><td><img src="icons/empty.gif" width=1 height=1></td><td><img src="icons/empty.gif" width="8" height="1"></td><td colspan="2"><img src="icons/empty.gif" width="'+w2+'" height="1"></td><td><img src="icons/empty.gif" width="8" height="1"></td><td><img src="icons/empty.gif" width="1" height="1"></td></tr>');

	if (title) {
	  win.document.writeln('<tr><th class="titleBar" colspan="6"><img src="icons/empty.gif" width="1" height="2"></th></tr>');
	  win.document.writeln('<tr><th class="titleBar"><img src="icons/empty.gif" width="1" height="1"></th><th class="titleBar"><img src="icons/empty.gif" width="8" height="1"></th>');
	  win.document.writeln('<th align="left" colspan="2" class="titleBar">');
	  win.document.writeln(title);
	  win.document.writeln('</th><th class="titleBar"><img src="icons/empty.gif" width="1" height="1"></th><th class="titleBar"><img src="icons/empty.gif" width="1" height="1"></th></tr>');
	  win.document.writeln('<tr><th class="titleBar" colspan="6"><img src="icons/empty.gif" width="1" height="2"></th></tr>');
	  win.document.writeln('<tr><td width="1" rowspan="2" class="boxBorder"><img src="icons/empty.gif" width="1" height="10"></td>');
	  win.document.writeln('<td colspan="4" height="10"><img src="icons/empty.gif" width="'+w1+'" height="10" alt="" border="0"></td>');
	  win.document.writeln('<td width="1" rowspan="2" class="boxBorder"><img src="icons/empty.gif" width="1" height="10"></td></tr>');
    } 
	else {
	  win.document.writeln('<tr><th class="titleBar" colspan="6"><img src="icons/empty.gif" width="1" height="1"></th></tr>');
	  win.document.writeln('<tr><td width="1" rowspan="2" class="boxBorder"><img src="icons/empty.gif" width="1" height="1"></td>');
	  win.document.writeln('<td colspan="4" height="1"><img src="icons/empty.gif" width="'+w1+'" height="1" alt="" border="0"></td>');
	  win.document.writeln('<td width="1" rowspan="2" class="boxBorder"><img src="icons/empty.gif" width="1" height="1"></td></tr>');
	}
	

	win.document.writeln('<tr><td></td><td colspan="2" valign="top">'+text+'</td><td></td></tr>');
	win.document.writeln('<tr><td class="boxBorder" height="1" colspan="6"><img src="icons/empty.gif" width="'+width+'" height="1"></td></tr>');
	win.document.writeln('<tr><td height="10" colspan="6"><img src="icons/empty.gif" width="1" height="10" alt="" border="0"></td></tr></table>');
	
	
  }


  function refresh_data(selected_data)
  {
	  opener.document.forms['post'].data.value = selected_data;
	  opener.focus();
	  window.close();
  }



// Image Swapper
var imagorg = new Array();

function ImagesOff()
{
  var empty = 'icons/empty.gif';
  for (var i = 0; i < document.images.length; i++) {
    if(document.images[i].name.indexOf("Deep-Sky")!=-1 || document.images[i].name.indexOf("Supernova")!=-1 || document.images[i].name.indexOf("Nova")!=-1)
	  document.images[i].src = empty;
  }
}

function ImagesOn()
{
  if (imagorg.length)
	for (var i = 0; i < document.images.length; i++) {
      if(document.images[i].name.indexOf("Deep-Sky")!=-1 || document.images[i].name.indexOf("Supernova")!=-1 || document.images[i].name.indexOf("Nova")!=-1)
		document.images[i].src = imagorg[i];
	}
}

function ImagesSwitch()
{
  if (document.forms[0].hideimages.checked) ImagesOff(); else ImagesOn();
}

function ImagesSave()
{
  if (document.images)
	for (var i = 0; i < document.images.length; i++) imagorg[i] = document.images[i].src;
}

function PrintImageMap()
{
	if (chartmap) {
		// Netscape before v6 did not support innerHTML
		if ((!ie && !ns6) || !document.getElementById("map")) {
			document.writeln(chartmap); // add map at end of file
		}
		else {
		  document.getElementById("map").innerHTML = chartmap;
		}
		s(defInfo);
	}
}

function toggleGlossary() {
	if (ie || ns6) {
		var toc=document.getElementById('glossary');
		var but=document.getElementById('hideglos');
		if (but) {
			if(!but.checked) {
				toc.style.display = tocWas;
			} else {
				tocWas = toc.style.display;
				toc.style.display = 'none';
			}
		}
	}
}

function submitenter(field,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
	   field.form.submit();
	   return false;
	}
	else return true;
}

function hrefCtrlLink(ths, event, ctrlurl)
{
	if (event.ctrlKey==true) ths.href=ctrlurl;
	return false;
}


function showHide(id)
{ 
 if(document.getElementById) {
  var style = document.getElementById(id).style
  if (style.visibility == "hidden")
   style.visibility = "visible";
  else  
   style.visibility = "hidden";
 }
}

function addField(name, value)
{
   var form = document.forms[0];
   var el = document.createElement("input");
   el.type = "hidden";
   el.name = name;
   el.value = value;
   form.appendChild(el);
}

