nn6 = (!document.all && document.getElementById) ? true : false;
ie4 = (document.all)? true:false;
Opera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

var model="dwd";
var modelURL;
var dwdURL = "prognumer";
var aladinURL = "prognumer";
var query;

document.onmousedown=Ruch;

function checkAll() {
  for (var j = 0; document.chekboxy[j]; j++){
    if(document.chekboxy[j].checked)
      show(document.chekboxy[j].value);
    else
      hide(document.chekboxy[j].value);
  }
}

function wczytaj()
{
	moveTo("Marker", document.forms[1].choragiewkaX.value, document.forms[1].choragiewkaY.value);
}

function zm(object) {
  if(object.checked)
    show(object.value);
  else
    hide(object.value);
}

function moveTo(ident,x,y) {
  if(ie4) {  
    document.all[ident].style.left = x;
    document.all[ident].style.top = y;
  }
  else if (nn6)
  {
	document.getElementById(ident).style.left=x;
	document.getElementById(ident).style.top=y;
  }
}

function show(ident) {
  if(ie4) {
    document.all[ident].style.visibility = "visible";
  } else if(nn6) {
	document.getElementById(ident).style.visibility="visible";
  }
}

function hide(ident) {
  if(ie4) {
    document.all[ident].style.visibility = "hidden";
  } else if(nn6) {
	document.getElementById(ident).style.visibility="hidden";
  }
}

function chooseModel(m){
	model = m.value;

	if(model=="dwd")
		modelURL=dwdURL;
	else
		modelURL=aladinURL;

//	window.status = model;

}

function updateModel(m){
	model = m.value;

	if(model=="dwd")
		modelURL=dwdURL;
	else
		modelURL=aladinURL;

	if(query == null)
		query = "";
alert( modelURL);
	window.open("/wl/" + modelURL + query,
'atmogram','toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,directories=no,status=no,resizable=yes,top=50,left=380 width=700,height=300');
}

function Ruch(e) {
if (nn6) {
	x=e.pageX;
	y=e.pageY;
	}
if (ie4) {
	x=event.clientX+document.body.scrollLeft;
	y=event.clientY+document.body.scrollTop;
	}
	woj1=x;
	woj2=y;
	wpmg=69+25;//84 wysokosc paska menu glownego
	
	wpmg=wpmg+82;
	zool=6;//zmiana odledlosci od lewej z "-"
	
	zool=zool-7
	
	y=y-wpmg;
	x=x+zool;
if (x>434+11 || y>415+16) return;
if (x<zool || y<11) return; //worn

document.forms[1].choragiewkaX.value=(x-2-zool);
document.forms[1].choragiewkaY.value=(y-21+wpmg);
moveTo("Marker",x-2-zool,y-21+wpmg);
/* wsp.geog (pix) - start*/
lm0=21;
R=4003;
t=x-308;
u=3839-(y-17);
tmp0=Math.pow(t,2)+Math.pow(R,2);
tmp1=tmp0/Math.pow(R,2);
k=Math.sqrt(tmp1);
tmp3=Math.sin(u/R)/k;
my_fi=Math.asin(tmp3);
my_la=Math.asin(t/(R*Math.cos(u/R)));		
my_la_s=my_la*180/Math.PI + 21;
my_fi_s=my_fi*180/Math.PI;
my_la_s_c=Math.floor(my_la_s); // Wartosc calkowita z my_la_s
my_la_s_r=my_la_s-my_la_s_c; // Czesc ulamkowa z my_la_s
my_la_s_min=Math.round(my_la_s_r*60); // my_la_s_r przeliczone z ulamkow dziesietnych na minuty
my_fi_s_c=Math.floor(my_fi_s); // Wartosc calkowita z my_fi_s
my_fi_s_r=my_fi_s-my_fi_s_c; // Czesc ulamkowa z my_fi_s
my_fi_s_min=Math.round(my_fi_s_r*60); // my_fi_s_r przeliczone z ulamkow dziesietnych na minuty
/* wsp.geog (pix) - end  */
/* geog2nodes start */
Pi18=0.01745329251994330;
la0=10.0;
fi0=57.5;
FiB=32.5*Pi18;
lamin=2.25;
fimin=-8.5;
dla=0.125;
dfi=0.125;
LaLa0 = (my_la_s-la0)*Pi18;
fi_ = my_fi_s*Pi18;
r1  = -Math.cos(FiB)*Math.cos(LaLa0)*Math.cos(fi_)+Math.sin(FiB)*Math.sin(fi_);
	rfi = Math.asin(r1);
	r1  = (Math.cos(FiB)*Math.sin(fi_)+Math.sin(FiB)*Math.cos(LaLa0)*Math.cos(fi_));
	r1  = r1/Math.cos(rfi);
	if (r1>1) {
		r1=1;
	}
	rla = Math.acos(r1)/Pi18;
	if ((my_la_s-la0)<0) {
		rla = -rla;
	}
	rfi = rfi/Pi18;
	nx=Math.round((rla-lamin)/dla+1);
	ny=Math.round((rfi-fimin)/dfi+1);
/* geog2nodes end */
rla=Math.round(my_la_s*100);
rfi=Math.round(my_fi_s*100);
rla=rla/100;
rfi=rfi/100;
status="Współrzędne:  "+rla+" E  "+rfi+" N";

//if(model=="dwd")
//	modelURL=dwdURL;
//else
//	modelURL=aladinURL;

// szer_st=52&szer_min=12&dlug_st=20&dlug_min=58&model=cosmo&lang=pl	
	
//window.status=model + " " + url;
query = "?szer_st="+my_fi_s_c+"&szer_min="+my_fi_s_min+"&dlug_st="+my_la_s_c+"&dlug_min="+my_la_s_min+"&model=cosmo&lang=en&form=tab&cancelled=y";
query2 = "?szer_st="+my_fi_s_c+"&szer_min="+my_fi_s_min+"&dlug_st="+my_la_s_c+"&dlug_min="+my_la_s_min+"&model=aladin&lang=en&form=tab&cancelled=y";
query3 = "?szer_st="+my_fi_s_c+"&szer_min="+my_fi_s_min+"&dlug_st="+my_la_s_c+"&dlug_min="+my_la_s_min+"&model=cosmo&lang=en&form=plot&cancelled=y";
query4 = "?szer_st="+my_fi_s_c+"&szer_min="+my_fi_s_min+"&dlug_st="+my_la_s_c+"&dlug_min="+my_la_s_min+"&model=aladin&lang=en&form=plot&cancelled=y";
window.open("/cgi/prognumer" + query,
'atmogram','toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,directories=no,status=no,resizable=yes,top=50,left=380 width=700,height=300')
window.open("/cgi/prognumer" + query2,
'atmogram2','toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,directories=no,status=no,resizable=yes,top=50,left=380 width=700,height=300')
window.open("/cgi/prognumer" + query3,
'atmogram3','toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,directories=no,status=no,resizable=yes,top=50,left=380 width=700,height=300')
window.open("/cgi/prognumer" + query4,
'atmogram4','toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,directories=no,status=no,resizable=yes,top=50,left=380 width=700,height=300')
}

//Tymczasowe
function openwin(w){

	window.open(w,
'atmogram','toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,directories=no,status=no,resizable=yes,top=50,left=380 width=700,height=300');
}

