/* functions for mouseover */
 function m_over(element){
   element.style.backgroundColor = '#d2d2c6';
  }

  function m_out(element){
   element.style.backgroundColor = '#f2f2f2';
   }
/* functions for mouseover for tables*/

  function mt_over(element){
   element.style.border = '1px solid red';
  }

  function mt_out(element){
   element.style.border = '1px solid white';
   }
   
   function togglebox(obj) { 
    if (obj.style.display == 'none'){
        obj.style.display = ''; 
    }
    else{
        obj.style.display = 'none'; 
    } 
}; 

 function ChangeFontSize(element){
    var maxfont=18;
    var minfont=11;
    var s = 11;
	element = document.getElementById(element);
    if(element.style.fontSize) {
         s = parseInt(element.style.fontSize.replace("px",""));
    }
    if(s<maxfont) {
         s += 3;
    }
    else{
    	s = minfont; 
    }
	element.style.fontSize = s+"px";
 } 

  function deleteCookie(name) {
	  document.cookie = name + "=;expires=Thu, 01-Jan-70 00:00:01 GMT; path=/;domain=foto.no;";
	  document.cookie = name + "=;expires=Thu, 01-Jan-70 00:00:01 GMT; path=/;domain=.foto.no;";
	  document.cookie = name + "=;expires=Thu, 01-Jan-70 00:00:01 GMT; path=/;domain=www.foto.no;";
   }
	
  function Set_Cookieold(name,value,expires,path,domain,secure) { 
	var today = new Date(); 
	var zero_date = new Date(0,0,0); 
	today.setTime(today.getTime() - zero_date.getTime()); 
	var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000)); 
//	console.info('Setting cookie:' + name + ' to ' + value);
	path = '/';
	var cookieString = name + "=" +escape(value) + 
	   ( (cookie_expire_date) ? ";expires=" + cookie_expire_date.toGMTString() : "") + 
	   ( (path) ? ";path=" + path : "") + 
	   ( (domain) ? ";domain=" + domain : "") + 
	   ( (secure) ? ";secure" : ""); 
//	  alert(cookieString);
	document.cookie = cookieString; 
  }  
   

  function Set_Cookie(name,value,expires,path,domain,secure) { 
	var today = new Date(); 
	var zero_date = new Date(0,0,0); 
	today.setTime(today.getTime() - zero_date.getTime()); 
	var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000)); 
	var cookieString = name + "=" +escape(value) + 
	    ( (cookie_expire_date) ? ";expires=" + cookie_expire_date.toGMTString() : "") + ";path=/;domain=foto.no;"; 
	//        alert(cookieString);
	document.cookie = cookieString; 
  }  
   

			var isfullscreen = 0;
			
			function togglefdnfullscreen(){
				if(isfullscreen){
					fdnnofullscreen();
					isfullscreen = 0;
				}
				else{
					fdnfullscreen();
					isfullscreen = 1;
				}
			}
			
			function fdnfullscreen(){
				hideelement('topadbanner');
				hideelement('navigation');
				hideelement('navigationfullscreen');
				hideelement('rightmenu');
				hideelement('footer');
				removemargins('content');
				removemargins('contentnorightmenu');
				removemargins('contentnorightmenufullscreen');
				
			}
			function fdnnofullscreen(){
				showelement('topadbanner');
				showelement('navigation');
				showelement('navigationfullscreen');
				showelement('rightmenu');
				showelement('footer');
				addmargins('content', '180px', '180px');
				addmargins('contentnorightmenu', '180px', 0);
				addmargins('contentnorightmenufullscreen', '180px', 0);
				
			}			
			function hideelement(element){
				element = document.getElementById(element);
				if(element != null) {element.style.display='none';};
			}
			function showelement(element){
				element = document.getElementById(element);
				if(element != null) {element.style.display='block';};
			}			
			function showelementinline(element){
				element = document.getElementById(element);
				if(element != null) {element.style.display='inline';};
			}			
			function removemargins(element){
				element = document.getElementById(element);
				if(element != null) {element.style.margin='0';};
			}
			function addmargins(element, leftmargin, rightmargin){
				element = document.getElementById(element);
				if(element != null) {
					element.style.marginLeft=leftmargin;
					element.style.marginRight=rightmargin;
				};
			}

   
   
	var bkfullwin = self;
function openBildekritikkFullScreen(img, id, x, y) {
	        img="/cgi-bin/bilder/fullscreen.cgi?bilde="+img+"&x="+x+"&y="+y+"&id="+id;
	  if (bkfullwin == self || bkfullwin.closed) {
	    bkfullwin =window.open(img,'FOTOdotNO_fullscreen','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=yes,fullscreen=yes');
	        bkfullwin.focus();
	  }
	  else {
	        bkfullwin.location = img;
	        bkfullwin.focus();
	  }
	}
   
	var imgfullwin = self;
	
	function openImageFullScreen(img) {
	  img="/cgi-bin/fullscreen.cgi?bilde="+img;
	  if (imgfullwin == self || imgfullwin.closed) {
	    imgfullwin =window.open(img,'FOTOdotNO_fullscreen','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=yes,fullscreen=yes');
	        imgfullwin.focus();
	  }
	  else {
	        imgfullwin.location = img;
	        imgfullwin.focus();
	  }
	}

    var bkwin = self;

    function AapneBokmerke(theURL) {
	if (bkwin == self || bkwin.closed) {
	    bkwin =window.open(theURL,'FOTOdotNOBokmerke','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=yes,width=510,height=210');
        bkwin.moveTo(360,300);
        bkwin.focus();
  }
  else {
    bkwin.location = theURL;
        bkwin.focus();
  }  
}  

    var conwin = self;

    function AapneTips(theURL) {
	if (conwin == self || conwin.closed) {
	    conwin =window.open(theURL,'fotoNoTips','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=yes,width=600,height=350');
        conwin.moveTo(360,300);
        conwin.focus();
  }
  else {
    conwin.location = theURL;
        conwin.focus();
  }  
}  


var tickerwin = self;
function OpenTickerWindow(theURL) {
  if (tickerwin == self || tickerwin.closed) {

tickerwin=window.open(theURL,'FOTOdotNO_Ticker','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=no,status=no,width=350,height=200');
        tickerwin.moveTo(0,0);
        tickerwin.focus();
  }
  else {
    tickerwin.location = theURL;
        tickerwin.focus();
  }
}

var karusellswin = self;

function openKarusellWindow(theURL) {
  if (karusellswin == self || karusellswin.closed) {
    karusellswin 
=window.open(theURL,'FotoNoKarusell','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=yes,width=700,height=600');
        karusellswin.moveTo(100,100);
        karusellswin.focus();
  }
  else {
    karusellswin.location = theURL;
        karusellswin.focus();
  }
}

var tipswin = self;

function openTipsWindow(theURL) {
  if (tipswin == self || tipswin.closed) {
    tipswin 
=window.open(theURL,'FotoNoTips_en_bekjent','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=yes,width=600,height=350');
        tipswin.moveTo(200,100);
        tipswin.focus();
  }
  else {
    tipswin.location = theURL;
        tipswin.focus();
  }
}

var kontaktwin = self;

function openKontaktWindow(theURL) {
  if (kontaktwin == self || kontaktwin.closed) {
    kontaktwin 
=window.open(theURL,'FotoNoTips_kontakt','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=no,width=700,height=600');
        kontaktwin.moveTo(100,100);
        kontaktwin.focus();
  }
  else {
    kontaktwin.location = theURL;
        kontaktwin.focus();
  }
}

var kopiertilportfoliowin = self;

function openKopiertilportfoliowindow(theURL) {
  if (kopiertilportfoliowin == self || kopiertilportfoliowin.closed) {
    kopiertilportfoliowin 
=window.open(theURL,'FotoNo_kopierTilPortfolio','scrollbars=no,location=no,menubar=no,copyhistory=no,resizable=no,width=700,height=600');
        kopiertilportfoliowin.moveTo(100,100);
        kopiertilportfoliowin.focus();
  }
  else {
    kopiertilportfoliowin.location = theURL;
        kopiertilportfoliowin.focus();
  }
}

/* To avoid 'click to activate' in ie for flash objects etc */
function skrivEmbeddedKode(id, htmlKode){
   var elem = document.getElementById(id);
   if(elem){
	elem.innerHTML = htmlKode;
   }
}



/**
  *  Used from the html page with:
  * <a href="#" onMouseOver="showTicker('http://192.168.0.180/checkout/no.n24.www/webdesign/artikkel.html', event, this );">sit amet</a>
  */

/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * log function, used for debugging.
 */
function log( txt )
{
    var date = new Date();
    var obj = document.getElementById( 'ads-right' ); // shows the log information in the tag with id 'ads-right'
    var p = document.createElement("p");
    var t = document.createTextNode( "["+date.getTime() + "] " + txt );
    p.appendChild( t );
    obj.insertBefore( p, obj.firstChild );
}



/********************************************************************************************* */
/********************************************************************************************* */
/********************************************************************************************* */

/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * Show the ticket. Information show is gathered from 'url', position from 'event'
 */
function showInfoPanel( url, event, anchor  )
{
    event = event ? event : window.event;

    var ip = getInfoPanel();
    if( ip == null) return;
	ip.innerHTML = '<html><body><table width="640" height="480" cellpadding="5" cellspacing="0"><tr height="20"><td width="365" class="floatingpopuphead">Henter data....</td><td class="floatingpopuphead" width="15"><a href="#" onClick="hideInfoPanel();return false;"><b>X</b><\/a></td></tr><tr><td colspan="2" class="floatingpopupcontent"><img src="/images/loader_small.gif">&nbsp;Henter data fra foto.no</td></tr></table></body></html>';
        ip.style.display = 'block';
        ip.style.position = 'absolute';
        ip.style.height = '480px';
        ip.style.width = '640px';
	center(ip);
    getInfoPanelURL( url );
}


/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * Retrivies ticket information from the url given
 */
function getInfoPanelURL( url ) {
	var xmlhttp = getXmlHttp();
	var response = "";

	if (!xmlhttp) {
		alert("error");
	} else {
		xmlhttp.open("GET", url, true );
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				response = xmlhttp.responseText;
				displayInfoPanelInfo( response );
			}
		}
		xmlhttp.send(null);
	}
}

/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * Retrivies the ticket object, creates the object if it doesn't exsist
 */
function getInfoPanel()
{
    var o = document.getElementById( 'infoPanel' );
    if ( o != null ) return o;

    var div = document.createElement( 'div' );
    div.id = 'infoPanel';

    var tmp = document.getElementsByTagName("body");
    if( tmp == null ) return null;

    var b = tmp[0];
    if ( b == null ) return null;

    b.appendChild( div );
	
    return document.getElementById( 'infoPanel' );
}


/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * Sets the ip to display the text given in 'txt'
 */
function displayInfoPanelInfo( txt )
{
    var ip = getInfoPanel();
    if (ip == null ) return;
    ip.innerHTML = txt;
}


/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * Hides the ip
 */
function hideInfoPanel()
{
    var ip = getInfoPanel();
    if (ip == null ) return;

    ip.style.position = 'absolute';
    ip.style.top = '0px';
    ip.style.left = '0px';
    ip.style.display = 'none';
}


/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * Retrivies ticket information from the url given
 */
function getTickerURL( url ) {
	var xmlhttp = getXmlHttp();
	var response = "";

	if (!xmlhttp) {
		alert("error");
	} else {
		xmlhttp.open("GET", url, true );
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				response = xmlhttp.responseText;
				displayTickerInfo( response );
			}
		}
		xmlhttp.send(null);
	}
}

/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * Returns an array containing the mouse position; (pos_x, pos_y)
 */
function getMousePosition( e )
{
    var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
    var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

    var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
    else if (e.clientX || e.clientY)
	{
		posx = e.clientX;
		posy = e.clientY;
		if (isIE)
		{
            if ( document.documentElement )
            {
                posx += document.documentElement.scrollLeft;
                posy += document.documentElement.scrollTop;
            }
            else
            {
                posx += document.body.scrollLeft;
                posy += document.body.scrollTop;
            }
		}
	}

    return new Array(posx, posy);
}

/**
 * @author Michael A. Plikk <michael �tt aptoma dot com>
 *
 * Returns a xmlHttp object, or false
 */
function getXmlHttp() {
	var xmlhttp=false;

	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		xmlType = "msxml2";
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			xmlType = "msxml3";
		} catch (e) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof( XMLHttpRequest != 'undefined' ) ) {
		xmlhttp = new XMLHttpRequest();
		xmlType="w3c";
	}
	return xmlhttp;
}



function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}


/* For diskusjonsoverview page */
var contentIsHidden = false;
var answerIsHidden = false;

/* For diskusjonsoverview page */
function ViewMoreText(textId){
  document.getElementById('disk_' + textId).style.display='inline';
  document.getElementById('hidedisk_' + textId).style.display='none';
  document.getElementById('hidediskpunct_' + textId).style.display='none';
}

/* For diskusjonsoverview page */
function ToggleHideContent(){

var i = 1;
var oChild =  document.getElementById('diskusjonscontent_' + i);
while(oChild){
      if(contentIsHidden){
          oChild.style.display='inline';
      }
      else{
          oChild.style.display='none';
      }
      i++;
      oChild = document.getElementById('diskusjonscontent_' + i);
}
if(contentIsHidden){
 contentIsHidden = false;
}
else{
 contentIsHidden = true;
}
return false;
}

/* For diskusjonsoverview page */
function ToggleHideAnswers(){

var i = 1;
var oChild =  document.getElementById('diskusjonssvar_' + i);
while(oChild){
      if(answerIsHidden){
          oChild.style.display='inline';
      }
      else{
          oChild.style.display='none';
      }
      i++;
      oChild = document.getElementById('diskusjonssvar_' + i);
}
if(answerIsHidden){
 answerIsHidden = false;
}
else{
 answerIsHidden = true;
}
return false;
}


/* For valg menu */

// Copyright 2006-2007 javascript-array.com

var mTimeOut         = 300;
var currentLayer    = null;
var currentitem     = null;

var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;

// Open Hidden Layer
function mopen(n)
{
    var l  = document.getElementById("choicemenu"+n);
    var mm = document.getElementById("mmenu"+n);
    if(l)
    {
        mcancelclosetime();
        l.style.visibility='visible';
        if(currentLayer && (currentLayerNum != n))
            currentLayer.style.visibility='hidden';

        currentLayer = l;
        currentitem = mm;
        currentLayerNum = n;			
    }
    else if(currentLayer)
    {
        currentLayer.style.visibility='hidden';
        currentLayerNum = 0;
        currentitem = null;
        currentLayer = null;
	}
}

// Turn On Close Timer
function mclosetime()
{
    closeTimer = window.setTimeout(mclose, mTimeOut);
}

// Cancel Close Timer
function mcancelclosetime()
{
    if(closeTimer)
    {
        window.clearTimeout(closeTimer);
        closeTimer = null;
    }
}

// Close Showed Layer
function mclose()
{
    if(currentLayer && noClose!=1)
    {
        currentLayer.style.visibility='hidden';
        currentLayerNum = 0;
        currentLayer = null;
        currentitem = null;
    }
    else
    {
        noClose = 0;
    }

    currentLayer = null;
    currentitem = null;
}

// Close Layer Then Click-out
document.onclick = mclose; 


// for articleediting:
var seltext = null;
var repltext = null;
    

function formatText(el,tag){
	var selectedText = document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);
	if(selectedText!=''){
		var newText='<'+tag+'>'+selectedText+'</'+tag+'>';
		el.value=el.value.replace(selectedText,newText)
	}
}
