
innerBoxName = "innerBox";
outerBoxName = "outerBox";

function getHTTPObject(){
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) return new XMLHttpRequest();
	else {
		alert("Your browser does not support AJAX.");
		return null;
	}
}
// Change the value of the outputText field
function setOutput(){
	if(httpObject.readyState == 4){
		document.getElementById(innerBoxName).innerHTML = httpObject.responseText;
	}
}
// Implement business logic
function doWork(workId,throwBoxValue){
	if(throwBoxValue == 1){
		throwBox();
	}
	httpObject = getHTTPObject();
	if (httpObject != null) {
		if(workId == 0){
			httpObject.open("GET", "arvonta.html", true);
		}else{
			httpObject.open("GET", "tarkastaArvo.php?k="+kayttajatunnus+"&p="+salasana, true);
		}
		httpObject.send(null);
		httpObject.onreadystatechange = setOutput;
	}
}


boxVisible = false;

function throwBox(){
	
	content = "";
	
	ab = document.getElementById(outerBoxName);
	abox = document.getElementById(innerBoxName);
	ab.style.display = "block";
	ab.style.width = getWindowWidth() +"px";
	ab.style.height = getWindowHeight() +"px";
	ab.style.width = Viewport()[0] +"px";
	
	if(Viewport()[1] < getWindowHeight()){
		ab.style.height = getWindowHeight() +"px";
	}else{
		ab.style.height = Viewport()[1] +"px";
	}
	abox.style.visibility = "hidden";
	abox.style.display = "block";
	abox.style.left = getWindowWidth()/2 - getOff(innerBoxName)[0]/2 +"px";
	abox.style.top = getWindowHeight()/2 - getOff(innerBoxName)[1]/2 +"px";
	abox.style.visibility = "visible";
	boxVisible = true;
	abox.innerHTML = content;
}

function hideBox(){
	boxVisible = false;
	ab = document.getElementById(outerBoxName);
	abox = document.getElementById(innerBoxName);
	ab.style.display = "none";
	abox.style.display = "none";
}

function checkBox(){
	if(boxVisible){
		ab = document.getElementById(outerBoxName);
		abox = document.getElementById(innerBoxName);
		
		ab.style.width = getWindowWidth() +"px";
		ab.style.height = getWindowHeight() +"px";
		
		ab.style.width = Viewport()[0] +"px";
		ab.style.height = Viewport()[1] +"px";
			
		abox.style.left = getWindowWidth()/2 - getOff(innerBoxName)[0]/2 +"px";
		abox.style.top = getWindowHeight()/2 - getOff(innerBoxName)[1]/2 +"px";
	}
}

window.onresize = checkBox;
