var Pyynto;
var shoutpyynto; 

function initialize() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map_canvas")); 
	 	var marker = new GMarker(new GLatLng(62.087901, 28.920372));
		
		//var position = new GLatLng(62.087373,28.917818);
 		//var opt = { latlng:position,enableFullScreen: true };
  		//var street = new GStreetviewPanorama(document.getElementById("divp"), opt);
		
		map.enableDoubleClickZoom();
		map.setCenter(new GLatLng(62.087521, 28.919878), 13);
		map.addOverlay(marker);
		map.setUIToDefault();
	}
}

function haeTeksti(button) {
	var e2 = document.getElementById('hakutxt'+button);
	location.replace('hae.php?hakutxt='+e2.value);
}

function alustaPyynto() 
{ 
    if(window.ActiveXObject) { 
        Pyynto = new ActiveXObject("Microsoft.XMLHTTP"); 
    } else if(window.XMLHttpRequest) { 
        Pyynto = new XMLHttpRequest(); 
    } 
}

function suoritaPyynto(kmonth,kyear,kteam) 
{ 
    alustaPyynto(); 
    Pyynto.onreadystatechange = kasitteleVastaus; 
	kteam2 = kteam;
    Pyynto.open("GET", "tulosta_kalenteri2.php?kmonth="+kmonth+"&kyear="+kyear+"&kteam="+kteam2, true); 
    Pyynto.send(null); 
}

function suoritaPyyntooikea(kmonth,kyear,kteam) 
{ 
    alustaPyynto(); 
    Pyynto.onreadystatechange = kasitteleVastaus2; 
	kteam2 = kteam;
    Pyynto.open("GET", "oikea_kalenteri2.php?kmonth="+kmonth+"&kyear="+kyear+"&kteam="+kteam2, true); 
    Pyynto.send(null); 
}


function kasitteleVastaus() 
{ 
	var e3 = document.getElementById('kloading');
	if(Pyynto.readyState == 1) {
		e3.innerHTML = 'LADATAAN KALENTERIA! ... ';
	}
    if(Pyynto.readyState == 4) 
    { 
        if(Pyynto.status == 200) 
        { 
			var e2 = document.getElementById('enpycalendar');
			var r = Pyynto.responseText;
			e2.innerHTML = r;
        } else {
			e3.innerHTML = 'KALENTERIN LATAAMINEN EI ONNISTUNUT!';
		}
    }
}

function kasitteleVastaus2() 
{ 
	var e3 = document.getElementById('kloading2');
	if(Pyynto.readyState == 1) {
		e3.innerHTML = 'LADATAAN KALENTERIA! ...';
	}
    if(Pyynto.readyState == 4) 
    { 
        if(Pyynto.status == 200) 
        { 
			var e2 = document.getElementById('rightenpycalendar');
			var r = Pyynto.responseText;
			e2.innerHTML = r;
        } else {
			e3.innerHTML = 'VIRHE KALENTERIN LATAAMISESSA!';
		} 
    } 
}

// SHOUTBOX ****************************************************

if (document.images) {
	var shoutimage1 = new Image(); shoutimage1.src="kuvat/ball_grey.gif";
	var shoutimage2 = new Image(); shoutimage2.src="kuvat/ball_red.gif";
	var shoutimage3 = new Image(); shoutimage3.src="kuvat/ball_green.gif";
	var shoutimage4 = new Image(); shoutimage4.src="kuvat/button_laheta.gif";
	var shoutimage5 = new Image(); shoutimage5.src="kuvat/button_laheta2.gif";
	var haeimage1 = new Image(); haeimage1.src="kuvat/button_hae_ani.gif";
	var haeimage2 = new Image(); haeimage2.src="kuvat/button_hae2.gif";
}

function alustashoutpyynto() 
{ 
    if(window.ActiveXObject) { 
        shoutpyynto = new ActiveXObject("Microsoft.XMLHTTP"); 
    } else if(window.XMLHttpRequest) { 
        shoutpyynto = new XMLHttpRequest(); 
    } 
}

function loadenpyshoutbox(supdate,sid,scount,sfirstid) 
{ 
	
    alustashoutpyynto(); 
    shoutpyynto.onreadystatechange = showenpyshoutbox; 
	shoutpyynto.open("GET", "tulosta_enpyshoutbox.php?sid="+sid+"&scount="+scount+"&sfirstid="+sfirstid, true); 
    shoutpyynto.send(null); 
}

function showenpyshoutbox() 
{ 
	if(shoutpyynto.readyState == 1) {
		document.shoutlight.src = shoutimage2.src;
	}
    if(shoutpyynto.readyState == 4) 
    { 
        if(shoutpyynto.status == 200) 
        { 
			var s1 = document.getElementById('content');
			var r = shoutpyynto.responseText;
			rivi = r.split("#enpyshoutboxtimer#");
			for (var i=0; i< rivi.length-1; i++) {
				shoutupdate = rivi[0];
				shoutfirtsid = rivi[1];
				shoutlastcount = rivi[2];
				shoutlastid = rivi[3];
				shouttimer = rivi[4];
				shouttxt = rivi[5];
			}
   			setTimeout ('loadenpyshoutbox(shoutupdate,shoutlastid,shoutlastcount,shoutfirtsid)',shouttimer);
			if (shoutupdate == '1') {
				s1.innerHTML = shouttxt;
				resizeshoutbox();
				document.shoutlight2.src = shoutimage3.src;
			}
			setTimeout (shoutlightoff,100);
        } 
    } 
}

function shoutlightoff()
{ 
	document.shoutlight.src = shoutimage1.src;
}

function resizeshoutbox()
{ 
	scroller.docH = document.getElementById("content").offsetHeight;
	scroller.contH = document.getElementById("container").offsetHeight;
	scroller.scrollAreaH = document.getElementById("scrollArea").offsetHeight;
	scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH;
	if(scroller.scrollH < 30) scroller.scrollH = 30;
	document.getElementById("scroller").style.height = Math.round(scroller.scrollH) + "px";
	scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH);
	Drag.init(document.getElementById("scroller"),null,0,0,0,scroller.scrollDist);
	document.getElementById("scroller").onDrag = function (x,y) {
		var scrollY = parseInt(document.getElementById("scroller").style.top);
		var docY = 0 - (scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist);
		document.getElementById("content").style.top = docY + "px";
	}
}
