//////////////////////////////////////////////////////////////////////////////////
//
//		divillä toteutettu popup ikkuna
//		21.11.2008  by  Veikko Salminen
//
//////////////////////////////////////////////////////////////////////////////////

document.write('<div id="div_darken" style="z-index:1004;width:100%;min-width:1002px;display:none;position:fixed;top:0;left:0;filter:alpha(opacity=70);-moz-opacity:.70;opacity:.70;background-color: white;height: 100%"></div>');
document.write('<div id="div_popup" style="display:none;position:absolute;z-index:1005;display:none;top:0;left:50%;margin:137px 31px 0 -175px;background-color: white;border: medium solid #C8C8C8;padding: 5px 10px 10px 10px;background: #FFFFFF url(images/window_header.png) repeat-x;"></div>');

function popup_set_width(new_width) {
	var popup = document.getElementById("div_popup");
	popup.style.width = new_width+"px";
	popup.style.marginLeft = "-"+(new_width/2)+"px";
}

function show_popup_old(content) {
	
	// haetaan scrollaus kohta - koodinpätkä kopsittu http://www.west-wind.com/WebLog/posts/4607.aspx
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0) {
    if (window.pageYOffset)
      ScrollTop = window.pageYOffset;
	  else
      ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	
	var popup = document.getElementById("div_popup");
	popup.innerHTML = content;
	//alert(popup.style.width);
	//if(!popup.style.width) 
		popup.style.marginLeft = "-"+(popup.offsetWidth/2)+"px";
		
	popup.style.marginTop = ""+(50+ScrollTop)+"px";
		
	popup.style.display = 'block';	
	document.getElementById("div_darken").style.display = 'block';	
}

function show_popup_error(error) {
	show_popup("Virhe<br><br>"+error+"<br><br><a href=\"javascript: hide_popup()\">Sulje ikkuna</a><br><br>");
}

function show_popup_url_old(url) {
	show_popup_old('Odota <a href=\"javascript:hide_popup()\">Sulje</a>');
	aw_get_content_from(url, function(content) {show_popup_old(content);});
}

function hide_popup() {
	document.getElementById("div_darken").style.display = 'none';	
	document.getElementById("div_popup").style.display = 'none';	
}
