var patterns_array = new Array("brun_tapet.gif","blommor.gif","brun_gardin.jpg","gron_brun.gif", "gul.gif", "jeans.gif", "lila_tapet.gif", "ljus_bla.gif", "rander.gif","tapet_nyar_farger.gif","tapet_julsockor_farg.gif","tapet_pepparkakor.gif","tapet_julsockor.gif");
var currPattern = 0;
function setCookie(name, value, days)
{
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();

  	document.cookie = name+"="+value+expires+"; path=/";
}

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 changeBG(arg) {
	var pattern = "url(/Ung/Images/backgrounds/" + patterns_array[arg] + ")";
	if (document.body)
	{
	    document.body.style.backgroundImage = pattern;
    }
}
function bodyLoad() {
    // change bg
    var obj = parseInt(readCookie("ung_bg"));
    if(!isNaN(obj) && obj != null) {
        changeBG(obj);
        currPattern = obj;
    }
    else {
        changeBG(0);
    }
}

function emailPage(intPageID)
{
	var intLeft = (window.screen.width - 340) / 2;
	var intTop = (window.screen.height - 460) / 2;
	var features = "height=460,width=340,left=" + intLeft + ",top=" + intTop;
	window.open("/Ung/templates/EmailPage.aspx?id=" + intPageID, null, features);
}

var win = null;
function ChattWindow(url,name,w,h)
{
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes';
    win = window.open(url,name,settings);
}

var newWin = null;
function NewWindow(url,name,w,h,scroll)
{
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
    newWin = window.open(url,name,settings);
}


function printPage() 
{
	var da = (document.all) ? 1 : 0;
	
	var printArea = document.getElementById("PrintArea");
	
	if(printArea == null && da) 
		printArea = document.all.PrintArea;
	
	if(printArea) 
	{
		var sStart = "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"/Ung/styles/print.css\"></head><body onload=\"if(window.print)window.print();\">";
		sStop = "</body></html>";
		
		var s = sStart + printArea.innerHTML;

		var w = window.open('about:blank','printWin','width=650,height=440,scrollbars=yes,toolbar=yes');
		wdoc = w.document;
		wdoc.open();
		wdoc.write(s);
		wdoc.writeln( sStop );
		wdoc.close();
	}
}
// open external links in new window
function externalLinks() {
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 }
} 
function windowLoad() {
    externalLinks();
    bodyLoad();
}

window.onload = windowLoad;

function resize_iframe()
{

	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	//resize the iframe according to the size of the
	//window (all these should be on the same line)
	document.getElementById("ChatIframe").style.height=parseInt(height-
	document.getElementById("ChatIframe").offsetTop-8)+"px";
}
