var mail1;
var mail2;
function writemail(mail1, mail2){
  document.open();
  document.writeln('<a href=mailto:' + mail1 + '@' + mail2 + '>');
  document.close();
}
function writesafemail(mail1, mail2){
  document.open();
  document.writeln(mail1 + '@' + mail2);
  document.close();
}

function printarticle() {
	window.print();
}
function expandcollapse (postid) {
	whichpost = document.getElementById(postid);
	if (whichpost.className=="postshown") { whichpost.className="posthidden"; }
	else if (whichpost.className=="postshown-block") { whichpost.className="posthidden"; }
	else { whichpost.className="postshown"; }
}
function expandcollapseMove (postid) {
	whichpost = document.getElementById(postid);
	if (whichpost.className=="postshown") { whichpost.className="posthidden"; }
	else { whichpost.className="postshown"; }
	window.location.href = window.location.href + ("#"+postid);
}
function toggle(o, cls) { //viser/skjuler programbeskrivelsen på forsidens tv-guide
	var disp = o.checked ? 'block' : 'none';
	var lis = document.getElementsByTagName('p');
	for(var i=0; i<lis.length; i++) {
		if(lis[i].className == cls) { lis[i].style.display = disp; }
	}
}

function toggleImageTools(id,flagit) {
	if (flagit=="1"){
			if (document.layers) document.layers[''+id+''].visibility = "show"
			else if (document.all) document.all[''+id+''].style.visibility = "visible"
			else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
		}
		else
			if (flagit=="0"){
			if (document.layers) document.layers[''+id+''].visibility = "hide"
			else if (document.all) document.all[''+id+''].style.visibility = "hidden"
			else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
	}
}
//<a href="#" onMouseOver="toggleImageTools('div1',1)" onMouseOut="toggleImageTools('div1',0)">Link 1</a>
//<div id="div1">...</div>


function fbs_click() {
	u=location.href;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent('http://go.dagbladet.no/ego.cgi/facebook/'+u),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function changeTextSize(mode) {

        if (mode == "increase") {
            textSize = YAHOO.util.Dom.getStyle("article-text", "font-size");
            textSize = Number(textSize.substring(0,2));
            if (textSize < 18) {
                textSize = textSize+1;
                YAHOO.util.Dom.setStyle("article-text", "font-size", String(textSize) + "px");
            }
        }
        else if (mode == "decrease") {
            textSize = YAHOO.util.Dom.getStyle("article-text", "font-size");
            textSize = Number(textSize.substring(0,2));
            if (textSize > 10) {
                textSize = textSize-1;
                YAHOO.util.Dom.setStyle("article-text", "font-size", String(textSize) + "px");
            }
        }
        else {
            YAHOO.util.Dom.setStyle("article-text", "font-size", "12px");
        }
}

// Endrer bodys bakgrunnsfarge
function changeBG(color) {
	var chng_body = document.getElementsByTagName("body")[0];
	chng_body.style.background = "#"+color;
}
//function setBG(cookieName,cookieValue,nDays) {
function setBG(colorValue) {
	var today = new Date();
	var expire = new Date();
	nDays=400;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	if (colorValue ==  "EDEDED" || colorValue == "C6C2B3" || colorValue == "34749A" || colorValue == "777777") {
		document.cookie = "bgfarge="+escape(colorValue) + ";expires="+expire.toGMTString()+";path=/";
	}
	changeBG(colorValue);
}

function ReadBG() {
	var cookieName = "bgfarge"
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
		var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	var colorToSet = theCookie.substring(ind+cookieName.length+1,ind1);
	if (colorToSet != "EDEDED" && colorToSet != "C6C2B3" && colorToSet != "34749A" && colorToSet != "777777") {
		colorToSet = "EDEDED";
	}
	changeBG(colorToSet);
}

// Setter vannmerke på inputboksen ved klikk på Google-radio-button
function googleBackground(active) {
	if (active == '1') {
		document.getElementById("search_main").style.backgroundImage = 'url(http://gfx.dagbladet.no/g3/google-vannmerke.jpg)';
	}
	else {
		document.getElementById("search_main").style.backgroundImage = 'url(http://gfx.dagbladet.no/g3/input-bg.gif)';
	}
}

// START-POLLS
var pollAltSelected = 0; 

 function pollAltSelect( id ) 
 {   
 if ( pollAltSelected != 0 ) 
 {     
 document.getElementById( "pollAltRadio_" + pollAltSelected ).checked = false;   
 }  
 
 pollAltSelected = id;   
 document.getElementById( "pollAltRadio_" + id ).checked = true; 
 
 } 
 function pollSubmit( pollid ) 
 {  
  pollPopup = window.open("http://stem.start.no/vote.php?id=" + pollid + "&alt=" + pollAltSelected,"","width=560,height=700");   
  pollPopup.focus();  
  } 
  
  function pollResult( pollid ) 
  {   
  pollPopup = window.open("http://stem.start.no/result.php?id=" + pollid,"","width=560,height=700");   
  pollPopup.focus();  
  }
  
  function showTv2Video(progId) {
var url = "http://webtv.tv2.no/multimedia/webtv/sl_player/?progId=" + progId + "&autoplay=true&panelMode=disabled&referrer=dagbladet";
var viewportwidth = 1024;
var viewportheight = 768;
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth,
viewportheight = document.documentElement.clientHeight
}
else
{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
viewportheight = document.getElementsByTagName('body')[0].clientHeight
}
var popW = 968, popH = 651;
var leftPos = (viewportwidth-popW)/2;
var topPos = (viewportheight-popH)/2;
window.open(url,'tv2player','channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}