var tur="";
var st;

//-------------------Gör AJAX-förfrågan-----------------------------------------

            var http_request = false;
            var svar=0
            function makeRequest(url) {
                http_request = false;
                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { // IE
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }

                if (!http_request) {
                    alert('Avbrott :( Kan inte skapa en XMLHTTP instans');
                    return false;
                }

                http_request.onreadystatechange = alertContents;

                http_request.open('POST', url, false);
                http_request.setRequestHeader("Content-type", "application/xml");
                http_request.send(null);
            }

            function alertContents() {
                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {
                      svar = http_request.responseText;
                      return svar;
                    }
                    else {
                        alert('Frågan kunde inte exekveras.');
                        alert(http_request.status);
                    }
                }
            }

function position(ship) {
	popurl="../ais/realposition.asp?ID=" + ship;
	winpops=window.open(popurl,"","scrollbars=no,width=650,height=500,top=240,left=200");
}

function registrera(ort) {
 if (document.getElementById("AvgHamn").value === '0') {
 	alert("ANGE AVGÅNGSORT!");
 	document.getElementById("AvgHamn").focus();
 	return false;
 }
 if (document.getElementById("antalT").value === "") {
  	alert("ANGE PAXANTAL!");
 	document.getElementById("antalT").focus();
 	return false;
 }
if (tur === "") tur = ort //document.getElementById("AvgHamn").selectedIndex;
window.location.href="paxreg_Ronja_Lagra.asp?AT=" + document.getElementById("antalT").value + "&hamn=" + ort;

return true;
}

function valjhamn(st) {
frdrj=st;
	var idag = new Date();
	
	year = idag.getYear();
	month = idag.getMonth()+1;
	if (month < 10) month = "0" + month;
	day = idag.getDate();
	if (day < 10) day = "0" + day;
	datum = year + "-" + month + "-" + day;
	
	timme = idag.getHours();
	if (timme<10) timme = "0" + timme;
	minut = idag.getMinutes();
	if (minut<10) minut = "0" + minut;
	sekund = idag.getSeconds();
	if (sekund<10) sekund = "0" + sekund;

	var kl =  timme + ":" + minut + ":" + sekund;
	document.getElementById("klk").innerHTML = kl;

if (datum < "2010-06-28" || datum > "2010-08-15") {

//------------------Lågsäsongstider------------
	if (kl > '06:30:00' && kl < '12:30:00') {
	    document.getElementById("turl").innerHTML = "REGULJÄRT";
	   // document.getElementById("man").innerHTML = '<input type=button value="MANUELL REG" onclick="clearTimeout(tid);document.getElementById("AvgHamn").select();">'
		if (kl < '12:07:00') {						//Barsta-Högbonden 12:00 0
			document.getElementById("AvgHamn").selectedIndex=2;
			tur = 0;
			turnr=0;
			harbour = 1
		}
		if (kl > '12:06:00') {						//Högbonden-Barsta 12:15 9
			document.getElementById("AvgHamn").selectedIndex=15;
			tur = 1;
			turnr=9;
			harbour=1
		}
	makeRequest("hb_paxcount.asp?turnr=" + turnr +"&tur=" + tur + "&hamn=" + harbour +  "&dum=" + Math.random());
	document.getElementById("antalT").value=svar;
	tid=setTimeout('valjhamn(st)',1000);
	}
	else {
	    document.getElementById("turl").innerHTML = "EXTRATUR";	
	    tid=setTimeout('valjhamn(st)',1000);
	}
}
else {
	nollfem = "0" + (5+st).toString()
	nollfem=nollfem.substr(nollfem.length-2,2)
// ------------------Högsäsongstider--------------
  		if (kl < '23:59:59') {						//Barsta-Högbonden 09:30 1
  			document.getElementById("AvgHamn").selectedIndex=2;
  			tur = 0;	//ut
  			turnr = 0;
  			  		   harbour = 1;
  		}
  		if (kl < '18:' + (20+st) + ':00') {						//Högbonden-Barsta 18:15 4
  			document.getElementById("AvgHamn").selectedIndex=15;
  			tur = 1;
  			turnr = 14;
  			  		   harbour = 1;
  		}
  		if (kl < '18:' + nollfem + ':00') {						//Bönhamn-Högbonden 18:00 8
  			document.getElementById("AvgHamn").selectedIndex=6;
  			tur = 0;
  			turnr = 8;
  			  		   harbour = 2;
  		}  		
  		if (kl < '17:' + (50+st) + ':00') {						//Högbonden-Bönhamn 17:45 8
  			document.getElementById("AvgHamn").selectedIndex=15;
  			tur = 1;
  			turnr = 18;
  			  		   harbour = 2;
  		}  		
  		if (kl < '17:' + (35+st) + ':00') {						//Barsta-Högbonden 17:30 4
  			document.getElementById("AvgHamn").selectedIndex=2;
  			tur = 0;
  			turnr = 4;
  			  		   harbour = 1;
  		}  		
  		if (kl < '15:' + (20+st) + ':00') {						//Högbonden-Barsta 15:15 3
  			document.getElementById("AvgHamn").selectedIndex=15;
  			tur = 1;
  		   harbour = 1;
  			turnr = 13;
  			  		   harbour = 1;
  		}  		
  		if (kl < '15:' + nollfem + ':00') {						//Bönhamn-Högbonden 15:00 7
  			document.getElementById("AvgHamn").selectedIndex=6;
  			tur = 0;
  			turnr = 7;
  			  		   harbour = 2;
  		}  		
  		if (kl < '14:' + (50+st) + ':00') {						//Högbonden-Bönhamn 14:45 7
  			document.getElementById("AvgHamn").selectedIndex=15;
  			tur = 1;
  			turnr = 17;
  			  		   harbour = 2;
  		}  		
  		if (kl < '14:' + (35+st) + ':00') {						//Barsta-Högbonden 14:30 3
  			document.getElementById("AvgHamn").selectedIndex=2;
  			tur = 0;
  			turnr = 3;
  			  		   harbour = 1;
  		}  		
  		if (kl < '12:' + (20+st) + ':00') {						//Högbonden-Barsta 12:15 2
  			document.getElementById("AvgHamn").selectedIndex=15;
  			tur = 1;
  			turnr = 12;
  			  		   harbour = 1;
  		}
  		if (kl < '12:' + nollfem + ':00') {						//Bönhamn-Högbonden 12:00 6
  			document.getElementById("AvgHamn").selectedIndex=6;
  			tur = 0;
  			turnr = 6;
  			  		   harbour = 2;
  		}
  		if (kl < '11:' + (50+st) + ':00') {						//Högbonden-Bönhamn 11:45 6
  			document.getElementById("AvgHamn").selectedIndex=15;
  			tur = 1;
  			turnr = 16;
  			  		   harbour = 2;
  		}
  		if (kl < '11:' + (35+st) + ':00') {						//Barsta-Högbonden 11:30 2
  			document.getElementById("AvgHamn").selectedIndex=2;
  			tur = 0;
  			turnr = 2;
  			  		   harbour = 1;
  		}
  		if (kl < '10:' + (20+st) + ':00') {						//Högbonden-Barsta 10:15 1
  			document.getElementById("AvgHamn").selectedIndex=15;
  			tur = 1;
  			turnr = 11;
  			  		   harbour = 1;
  		}
  		if (kl < '10:' + nollfem + ':00') {						//Bönhamn-Högbonden 10:00 5
  			document.getElementById("AvgHamn").selectedIndex=6;
  			tur = 0;
  			turnr = 5;
  			  		   harbour = 2;
  		}
  		if (kl < '09:' + (50+st) + ':00') {						//Högbonden-Bönhamn 09:45 5
  			document.getElementById("AvgHamn").selectedIndex=15;
  			tur = 1;	//in;
  			turnr = 15;
  			  		   harbour = 2;
  		}
  		if (kl < '09:' + (35+st) + ':00') {						//Barsta-Högbonden 09:30 1
  			document.getElementById("AvgHamn").selectedIndex=2;
  			tur = 0;	//ut
  			turnr = 1;
  			  		   harbour = 1;
  		}


		makeRequest("hb_paxcount.asp?turnr=" + turnr + "&tur=" + tur + "&hamn=" + harbour + "&dum=" + Math.random());
		document.getElementById("antalT").value=svar;

		tid=setTimeout('valjhamn(frdrj)',1000);
}
return true;
}

function placeracursor() {
   document.getElementById("antalT").select();
}	

function keypressed() {
 clearTimeout(tid);
}