function reset_display(id){
	document.getElementById(id).style.display = "none";
	//document.getElementById('perse').innerHTML = "";
}

function getY( oElement ){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement ){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}


function showDiv(id,fromID){
	
	
	
	var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }

	
	
	
	
	var posx = 0;
	var posy = 0;
	posy=getY(document.getElementById(fromID));
	posx=getX(document.getElementById(fromID));
	//var miinus = height/2;
	posx=posx+120;
	laita=posx+480;
	if(laita>viewportwidth) {
		posx=posx-550;
	}
	posy=posy-40;
	if(document.body.scrollTop>posy) {
		posy=document.body.scrollTop +20;
	}
	if(document.body.scrollTop>posy) {
		posy=document.body.scrollTop +20;
	}
	if((posy+400)>(viewportheight+document.body.scrollTop)){
		posy=posy-200;
	}
	
	document.getElementById(id).style.top = posy+'px';
	document.getElementById(id).style.left = posx+'px';
	//document.getElementById(id).style.visibility = "visible";
}


function getAjax(id,file,params,fromID){
	reset_display(id);
// setataan ID mukaiset elementin näkyvyys blockiksi
// Määritetään elementin leveys ja korkeus
//document.getElementById(id).style.width = width+'px';
//document.getElementById(id).style.height = height+'px';
	//document.getElementById(id).style.visibility = "hidden";
	document.getElementById(id).style.display = "block";
//Detects browser type
function makeObject(){
var x;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
x = new ActiveXObject("Microsoft.XMLHTTP");
}else{
x = new XMLHttpRequest();
}
return x;
}

//Call function
var request = makeObject();

//The get method AJAX

//The POST method AJAX
function get_html(){

var domain = window.location.host;
//var domain = fullurl.host


request.open('get', 'http://'+domain+file+params);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = output;
request.send(false);
}

function output()
{
if(request.readyState == 1){
//You can add animated gif while loading //
document.getElementById(id).innerHTML = 'Loading...';
}
if(request.readyState == 4){
var data = request.responseText;
document.getElementById(id).innerHTML = data;
}
}


get_html();
showDiv(id,fromID);
} // END FUNCTION getAjax










function viewDiv(e,id,height){
	
	
	
	var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }

	
	
	
	
	var posx = 0;
	var posy = 0;
	if(!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	//var miinus = height/2;
	posx=posx+40;
	laita=posx+480;
	if(laita>viewportwidth) {
		posx=posx-480;
	}
	posy=posy-200;
	document.getElementById(id).style.top = posy+'px';
	document.getElementById(id).style.left = posx+'px';
}



function setWidthDiv(divID,imgID){
	var newImg = new Image();
	newImg.src=document.getElementById(imgID).src;
	var newWidth=newImg.width;
	//document.getElementById(divID).style.width= newWidth + 10;
}
