/*
 * Common functions used in http://www.kreditguiden.se.
 * Copyright (C) 2003 Mats Bergsten
 * http://www.bergsten.net/mats
 */

function addFavorite()
{ 
	if (window.external) // if the browser is IE open the add favorite window
	{
		external.AddFavorite(location.href, document.title)
		// Add the document location and title to the AddFavorite window
	}
  	else // Display and alert box for any other browser.
  	{
		alert("Dinn webbläsare tillåter inte detta." + 
		"\nVar god använd din webbläsares normala sätt att lägga till ett bokmärke.");
	}
}

function setHomepage()
{
    homepage.style.behavior='url(#default#homepage)';
	homepage.setHomePage('http://www.kreditguiden.se/');
}

function openPopupWindow(url, name, width, height) 
{
//window.open(url, name, 'resizable=0, scrollbars=0, width=200, height=210');
	window.open(url, name, 'resizable=0, scrollbars=0, width=' + width + ', height=' + height + '');
} 

function winPrint()
{
	if (window.print) 
	{
		window.print();
	}
	else
	{
		alert("Din webbläsare stödjer inte denna utskriftmetod. Stäng det här fönstret och välj Arkiv -> Skriv Ut från menyn.");
	}
}

function statusBar(text)
{
	window.status = text;
	setTimeout("erase()",1000);
}

function eraseStatusBar() 
{
   window.status="";
}

function calculateBandwidth()
{
	var imgfile="bandtest.gif" // Location of the image file (use " on either side of value)
	var imgsize=102403 // Size of the image file in bytes

	var st,et,tt,bw,bwd,pr,c1="<font size=2>Downloading test image, please wait...<br><b>"+imgsize+" bytes ("+Math.round(imgsize/1024)+
	"KB)</b></font><br><br><img name='bwti' border=0 src="+imgfile+"?",c5=" width=300 height=100 onload=EndTest()>",c2="<font size=2>Test "+
	"complete!<br><br>Your ",c6=" connection took <b>",c3=" second(s) </b>to download <b>"+Math.round(imgsize/1024)+"KB</b>.</font><br>"+
	"<br><font size=2>Your bandwidth is: </font><b><font size=4>",c4="bps</font><br><br><b><font size=2><a href='javascript:Repeat()'>"+
	"Repeat Test</a></font></b>"
}

function StartTest()
{
	if(document.location.search!="")
	{
		tt=document.location.search+"";
		if(tt=="?h")
		{
			document.write("<meta http-equiv='refresh' content='0; URL=http://www.darren-c.co.uk/'>Please wait...");
		}
		else ShowResult()
	}
	else
	{
		st=new Date(); document.write(c1+st.getTime()+c5)
	}
}

function EndTest()
{
	et=new Date();
	document.location=document.location+"?"+(et.getTime()-st.getTime())/1000
}

function VisitHome()
{
	window.open("bandtest.htm?h")
}

function Repeat()
{
	document.location="bandtest.htm"
}

function ShowResult()
{
	tt=tt.substring(1,tt.length);
	bw=(imgsize*8/tt)*100;
	bwd=Math.round(bw/1024)/100;
	if(bwd>1024)
	{
		bwd=Math.round(bw/1048576)/100+" M";
	}
	else
	{
		bwd+=" K";
	}
	if(imgfile.indexOf(":/")>0)
	{
		pr=imgfile.substring(0,5);
	}
	else
	{
		pr=document.location.protocol; pr=pr.toUpperCase(); document.write(c2+pr+c6+tt+c3+bwd+c4)
	}
}
