function addevent(elem,ev,handler) {
	if(!elem) {
		return false;
	}
	if(elem.attachEvent) {
		return elem.attachEvent("on"+ev,handler);
	}
	else {
		return elem.addEventListener(ev,handler,false);
	}
}

function removeevent(elem,ev) {
	if(!elem) {
		return false;
	}
	if(elem.detachEvent) {
		elem.detachEvent("on"+ev);
	}
	else {
		elem.removeEventListener(ev,null,false);
	}
}

function objcoords(which) {
	if(!which) {
		return false;
	}
	var fleft = 0;
	var ftop  = 0;
	var fwidth = which.offsetWidth;
	var fheight = which.offsetHeight;

	while (which.offsetParent){
		fleft += which.offsetLeft;
		ftop  += which.offsetTop;
		which     = which.offsetParent;
	}

	fleft += which.offsetLeft;
	ftop  += which.offsetTop;

	return { x : fleft, y : ftop, w : fwidth, h : fheight };
}

function mousecoords(e) {
	e = e || window.event;
	if(e.pageX || e.pageY){
		var coords = { x : e.pageX, y : e.pageY };
	}
	else {
		var coords = {
			x : (e.clientX + document.body.scrollLeft - document.body.clientLeft),
			y : (e.clientY + document.body.scrollTop  - document.body.clientTop)
		};
	}
	return coords;
}

function ajaxpost(url,query) {
	//Clear our fetching variable
	var xmlhttp=false;
    var contentType = "application/x-www-form-urlencoded; charset=iso-8859-1";
	//Try to create active x object
	try {
	    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e) {
	    try {
	         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch(E) {
	         xmlhttp = false;
	    }
	}
	if(!xmlhttp && typeof XMLHttpRequest!="undefined") {
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("POST",url,false);
	xmlhttp.setRequestHeader("Content-Type", contentType);
	if(typeof(xmlhttp.send)!="undefined") {
		xmlhttp.send(query);
	}
	else if(typeof(xmlhttp.load)!="undefined") {
		xmlhttp.async = false;
		xmlhttp.load(url);
    }
    if ( xmlhttp.parseError && xmlhttp.parseError.errorCode != 0 ) {
        return false;                       // failed
    }
    // HTTP response code
    if ( xmlhttp.status-0 > 0 &&
         xmlhttp.status != 200 &&          // OK
         xmlhttp.status != 206 &&          // Partial Content
         xmlhttp.status != 304 ) {         // Not Modified
        return false;                       // failed
    }
    return xmlhttp;
}

function explode(str,sep) {
	if(!sep || sep=="") {
		sep = " ";
	}
	osat_arr = new Array("");
	osanro = 0;
	for(var i=0;i<str.length;i++) {
		merkki = str.substr(i,1);
		if(merkki==sep) {
			osanro++;
			osat_arr[osanro] = "";
		}
		else {
			osat_arr[osanro] += merkki;
		}
	}
	return osat_arr;
}

function inarray(elem,array) {
	for(var i=0;i<array.length;i++) {
		if(array[i]==elem) {
			return true;
		}
	}
	return false;
}
