// preloading images

var activeImage = "";


// sets the first textitem in the first form as active
function startForm()	{
	document.forms[0].elements[0].focus(); 
}


// changes the image on mouseover/mouseout
function changeImage(img,status)	{
	if(status == "on")	{
		var imgOn = eval(img + "_on.src");
		document.images[img].src = imgOn;
	}
	else if(status == "off")	{
		if (img != activeImage)	{
			var imgOff = eval(img + "_off.src");
			document.images[img].src = imgOff;
		}
	}
}	


// makes one image active
function makeActive(img)  {	
	// Turn off currently active
	if (activeImage != img)  {
		imgTemp = activeImage;
		activeImage = img;
		if(imgTemp != ""){
			changeImage(imgTemp, 'off');
			changeImage(imgTemp, 'off');
		}
	alert("activeImg: " + activeImage + ", imgTemp: " + imgTemp)		
	}
}


// changes the class for the top-menu to the on-colour 
function colorOn(object)	{
	if(object.className == "topmenuOff")	{
		object.className = "topmenuOn";
	}
	
}


// changes the class for the top-menu to the off-colour 
function colorOff(object)	{
	if(object.className == "topmenuOn")	{
			object.className = "topmenuOff";
	}

}



// returns the window width 
function getScreenWidth()	{
	screenWidth = document.body.offsetWidth;
	return screenWidth;
}

// returns the window height 
function getScreenHeight()	{
	screenHeight = document.body.offsetHeight;
	return screenHeight;
}


// returns the right x-value to center a popup-window
function getMidWidth(newWinWidth)	{
	var winWidth = getScreenWidth();
	var midWidth = ((winWidth + (screen.width - winWidth))/2) - (newWinWidth/2);
	return midWidth;
}


// returns the right y-value to center a popup-window
function getMidHeight(newWinHeight)	{
	var winHeight = getScreenHeight();
	var midHeight = ((winHeight + (screen.height - winHeight))/2) - (newWinHeight/2);
	return midHeight;
}


// opens a popupwindow with the given properties
function openPopWindow(url, width, height, scroll)	{
	if (scroll == "1")	{
		scroll = "yes";
	}
	else	{
		scroll = "no";
	}	
	var screenX = getMidWidth (width);
	var screenY = getMidHeight (height);
	var popupWin = window.open(url, "", "width=" + width + ",height=" + height + ",scrollbars=" + scroll + ",left=" + screenX + ",top=" + screenY);
}


function doSearch()	{
	var strWord = document.searchForm.search.value;
	if (strWord.length > 0)	{
		return true;
	}	
	else	{
		return false;
	}	
}

function gotoVersion()	{
	var lngVersionID = document.searchForm.Versions.options[document.searchForm.Versions.selectedIndex].value;
	self.location = "/index.asp?VersionID=" + lngVersionID;
}

function doVote()	{
	var lngAlternative = -1;
	var lngLength = document.answerQuestion.answer.length;
	for (var i = 0; i < lngLength; i++)	{
		if (document.answerQuestion.answer[i].checked)	{
			lngAlternative = document.answerQuestion.answer[i].value;
		}	
	}
	if (lngAlternative == -1)	{
		alert("Du måste välja något av svarsalternativen.");
	}
	else	{
		var lngVersionID = document.answerQuestion.VersionID.value;
		var lngQuestionID = document.answerQuestion.question.value;
		openPopWindow("/quickpoll/qpresult.asp?VersionID=" + lngVersionID + "&question=" + lngQuestionID + "&answer=" + lngAlternative,320,300,0);
	}	
}

function doOpenForum(lngVersionID)	{
	var forumWin = window.open("/forum/index.asp?VersionID=" + lngVersionID,"Forum","width=800,height=600,scrollbars=yes,left=10,top=10,resizable=yes");
	forumWin.focus();
}

function checkLogin()	{
	var objForm = document.login;
	var strError = "";

	if (objForm.username.value == "")	{
		strError = strError + "Du måste ange ditt användarnamn.\n";
	}

	if (objForm.password.value == "")	{
		strError = strError + "Du måste ange ditt lösenord.\n";
	}

	if (strError == "")	{
		return true;
	}
	else	{
		alert(strError);
		return false;
	}
}