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 expandcollapse (postid) {
	whichpost = document.getElementById(postid);
	if (whichpost.className=="postshown") { 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"
	}
}
function printarticle() {
	window.print();
}

// 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)';
	}
}
//<a href="#" onMouseOver="toggleImageTools('div1',1)" onMouseOut="toggleImageTools('div1',0)">Link 1</a>
//<div id="div1">...</div>


// 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.toUpperCase() ==  "EDEDED" || colorValue.toUpperCase() == "C6C2B3" || colorValue.toUpperCase() == "34749A" || colorValue.toUpperCase() == "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.toUpperCase() != "EDEDED" && colorToSet.toUpperCase() != "C6C2B3" && colorToSet.toUpperCase() != "34749A" && colorToSet.toUpperCase() != "777777") {
		colorToSet = "EDEDED";
	}
	changeBG(colorToSet);
}

// 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 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");
        }
}

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);       
 }