function openWindow(u, w, h)
{
	return window.open(u,null,"toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width="+w+",height="+h+"");
}

function openWapWindow(u, w, h)
{
	window.open(u,null,"toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width="+w+",height="+h+"");
}

function centerWindow(win, w, h)
{
	win.moveTo((screen.availWidth/2)-(w/2),(screen.availHeight/2)-(h/2));
	
	return win;
}

function openCenteredWindow(u, w, h)
{
	centerWindow(openWindow(u,w,h),w,h);
	
	return win;
}

function swapImage(oldImage, newImage)
{
	self.document.images[oldImage].src = newImage;
}

function preloadImages()
{
	var imgArr = new Image(9);
	var imgNames = new Array("start_over", "information_over", "nyheter_over", "tavlingar_over", "resultat_over", "lankar_over", "bildarkiv_over", "forum_over","wap_over","snake_over");
	
	for(var i=0; i<imgNames.length; i++)
	{
		imgArr[i] = new Image();
		imgArr[i].src = "../../img/main/"+imgNames[i]+".gif";
	}
}

function random(min,max)
{
	return parseInt(((Math.random() * ((max - min) + 1)) + min).toString());
}

function getImgCount()
{
	return 32;
}

function replace(stack, needle, replace)
{
	var total = "";

	var index=0;
	var currentIndex=0;
	
	while((index=stack.indexOf(needle,currentIndex)) != (-1))
	{
		total+=stack.substring(currentIndex,index);
		total+=replace;
		currentIndex=index+needle.length;
	}
	
	total+=(stack.substring(currentIndex));

	return total;
}

function urlencode(strText) {                             

            var isObj;

            var trimReg;

            if( typeof(strText) == "string" ) {

                        if( strText != null ) {

                                    trimReg = /(^\s+)|(\s+$)/g;

                                    strText = strText.replace( trimReg, '');

                                    for(i=32;i<256;i++) {               

                                                strText = strText.replace(String.fromCharCode(i),escape(String.fromCharCode(i)));                                                                 

                                    }

                        }

            }          

            return strText;

}

