/*
function popup(url, width, height) {
        var w = window.open(url, "popup", "width="+width+",height="+height+",scrollbars=yes,resizable=no");
        w.focus();
}
*/
function popupCentered(url,name,w,h) {
	var xpos, ypos;

	if (window.document.body) {
		xpos = Math.round(window.screenLeft + (window.document.body.clientWidth / 2) - ((w + 5) / 2));
		ypos = Math.round(window.screenTop + (window.document.body.clientHeight / 2) - ((h + 25) / 2));
	}
	else {
		xpos = 150;
		ypos = 150;
	}

	xpos = xpos + Math.round(Math.random()*200-100);
	ypos = ypos + Math.round(Math.random()*200-100);



	var properties = 'width='+w+',height='+h+',left='+xpos+',top='+ypos;
	w = window.open(url, name, properties);
	w.focus();
}
function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e); 
}
function staticLoadScript(url)
{
   document.write('<script src="', url, '" type="text/JavaScript"><\/script>');
}
function keepAlive()
{
	dhtmlLoadScript("/_scripts/keepalive.php");
}

function keepMeOnline()
{
	dhtmlLoadScript("/_scripts/updateonline.php");
}

function updateUserIcons()
{
	dhtmlLoadScript("/_scripts/updateusericons.php");
	//staticLoadScript("/_scripts/updateusericons.php");
}
function updateUserIcons2()
{
	dhtmlLoadScript("/_scripts/updateusericons2.php");
}
var ns4 = document.layers;
var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) 
||(navigator.userAgent.indexOf("Opera/5")!=-1);
var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) 
||(navigator.userAgent.indexOf("Opera/6")!=-1);
var agt=navigator.userAgent.toLowerCase();
var mac = (agt.indexOf("mac")!=-1);
var ie = (agt.indexOf("msie") != -1); 
var mac_ie = mac && ie;


function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}

function getImageHeight(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.height;
	} else {
		return getElementHeight(myImage);
	}
	return -1;
}

function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
			foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function validateLogin()
{
	var username = document.forms['login'].username.value;
	var password = document.forms['login'].password.value;
	var valid = true;
	if(username.length < 3)
	{
		alert("Ange användarnamn först");
		valid = false;
	}
	else if(password.length < 3)
	{
		alert("Ange lösenord först");
		valid = false;
	}
	return valid;
}
function playMusic(nm) {
	obj = document.embeds[nm];
	if(obj.Play) obj.Play();
	return true;
}
function stopMusic(nm) {
	obj = document.embeds[nm];
	if(obj.Stop) obj.Stop();
	return true;
}
function rewMusic(nm) {
	obj = document.embeds[nm];
	if(obj.Rewind) obj.Rewind();
	return true;
}


/***********************************************
* Sticky Note script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
* Go to http://www.dynamicdrive.com/ for full source code
***********************************************/

//Specify display mode. 3 possible values are:
//1) "always"- This makes the fade-in box load each time the page is displayed
//2) "oncepersession"- This uses cookies to display the fade-in box only once per browser session
//3) integer (ie: 5)- Finally, you can specify an integer to display the box randomly via a frequency of 1/integer...
// For example, 2 would display the box about (1/2) 50% of the time the page loads.

var displaymode="always"

var enablefade="no" //("yes" to enable fade in effect, "no" to disable)
var autohidebox=["yes", 10] //Automatically hide box after x seconds? [yes/no, if_yes_hide_after_seconds]
var showonscroll="yes" //Should box remain visible even when user scrolls page? ("yes"/"no)
var IEfadelength=1 //fade in duration for IE, in seconds
var Mozfadedegree=0.05 //fade in degree for NS6+ (number between 0 and 1. Recommended max: 0.2)

////////No need to edit beyond here///////////

if (parseInt(displaymode)!=NaN)
var random_num=Math.floor(Math.random()*displaymode)

function displayfadeinbox(){
document.getElementById('divMessageBg').style.display='';
var ie=document.all && !window.opera
var dom=document.getElementById
iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
objref=(dom)? document.getElementById("fadeinbox") : document.all.fadeinbox
var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
var docwidth=(ie)? iebody.clientWidth : window.innerWidth
docheight=(ie)? iebody.clientHeight: window.innerHeight
var objwidth=objref.offsetWidth
objheight=objref.offsetHeight
objref.style.left=docwidth/2-objwidth/2+"px"
objref.style.top=scroll_top+docheight/2-objheight/2+"px"

if (showonscroll=="yes")
	showonscrollvar=setInterval("staticfadebox()", 50)

if (enablefade=="yes" && objref.filters){
	objref.filters[0].duration=IEfadelength
	objref.filters[0].Apply()
	objref.filters[0].Play()
}
objref.style.visibility="visible"
if (objref.style.MozOpacity){
	if (enablefade=="yes")
		mozfadevar=setInterval("mozfadefx()", 90)
	else{
		objref.style.MozOpacity=1
		controlledhidebox()
	}
}
else
	controlledhidebox()
}

function mozfadefx(){
	if (parseFloat(objref.style.MozOpacity)<1)
		objref.style.MozOpacity=parseFloat(objref.style.MozOpacity)+Mozfadedegree
	else{
		clearInterval(mozfadevar)
		controlledhidebox()
	}
}

function staticfadebox(){
var ie=document.all && !window.opera
var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
objref.style.top=scroll_top+docheight/2-objheight/2+"px"
}

function hidefadebox(){
document.getElementById('divMessageBg').style.display='none';
objref.style.visibility="hidden"
if (typeof showonscrollvar!="undefined")
clearInterval(showonscrollvar)
}

function controlledhidebox(){
	if (autohidebox[0]=="yes"){
		var delayvar=(enablefade=="yes" && objref.filters)? (autohidebox[1]+objref.filters[0].duration)*1000 : autohidebox[1]*1000
		setTimeout("hidefadebox()", delayvar)
	}
}

function initfunction(){
setTimeout("displayfadeinbox()", 100)
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = ""
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}


/*
* START COOKIE HANDLING
*/

function createCookie(name,value,seconds) {
	if (seconds) {
		var date = new Date();
		//date.setTime(date.getTime()+(days*24*60*60*1000));
		date.setTime(date.getTime()+(seconds*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/; domain=devote.se";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
/*
* END COOKIE HANDLING
*/

var messageUserIconsCookie = readCookie('message_user_icons');
if(document.getElementById('divMessageBg')) {
	//if (typeof initUserIcons != 'undefined') {
	if(! messageUserIconsCookie) {
		if (displaymode=="oncepersession" && get_cookie("fadedin")=="" || displaymode=="always" || parseInt(displaymode)!=NaN && random_num==0){
			if (window.addEventListener)
				window.addEventListener("load", initfunction, false)
			else if (window.attachEvent)
				window.attachEvent("onload", initfunction)
			else if (document.getElementById)
				window.onload=initfunction
			document.cookie="fadedin=yes"
	
			// Set cookie
			createCookie('message_user_icons', 1, (60*15));
		}
	}
}