var curQuestion = "question_1";
var ansState = 0;
var visArt = '';
var butikState = 0;
var curmod = 0;
var maillist = new Array();
var printlinktemplate='';
var printstate=0;
var checkvaroftheprintpage=0;

function $(e){if(typeof e=="string")e=document.getElementById(e);return e};

function previous_question(index)
{
  if (index > 1)
   {
    hide( $(curQuestion) );
    var obj1=$("swfbg_"+ index);
      if (obj1)
      {
        hide( obj1 );
      }
    index = index - 1;
      obj1=$("swfbg_"+ index);
      if (obj1)
      {
        show( obj1 );
      }
    curQuestion = 'question_'+ index;
    show( $(curQuestion) );
   }
}

function next_question(index, count)
{
    checkresult("questionanswers_"+index)
    if (ansState == 1)
    {
      if (index < count)
      {
          hide( $(curQuestion) );

          var obj=$("swfbg_"+ index);
          if (obj)
          {
            hide( obj );
          }
          index =parseInt(index) + 1;
          curQuestion = 'question_'+ index;
          obj=$("swfbg_"+ index);
          if (obj)
          {
            show( obj );
          }
          show( $(curQuestion) );
       }
    }
}

function show(id)
{
  $(id).style.display = "block";
}

function hide(id)
{
  $(id).style.display = "none";
}

function bookmark_show(id, bg1, bg2, color, nodeid, leftBorder, leftTopBorder, topBorder, rightTopBorder, rightBorder, bottomBorder)
{

  $("question_bookmark_"+nodeid+"_1").style.display = "none";
  $("question_bookmark_"+nodeid+"_2").style.display = "none";
  $("question_bookmark_"+nodeid+"_3").style.display = "none";
  $("fakta_info_"+nodeid).style.display= "none";

  $("question_"+id).style.display = "inline";
  $("contentTextBlockFakta_"+nodeid).style.display = "block";


  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
    {

//            $("bookmark_"+nodeid+"_1").runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg2 + "',sizingMethod='scale')";
//            $("bookmark_"+nodeid+"_2").runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg2 + "',sizingMethod='scale')";
//            $("bookmark_"+nodeid+"_3").runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg2 + "',sizingMethod='scale')";
//            $(id).runtimeStyle.backgroundImage="none";
//            $(id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg1 + "',sizingMethod='scale')";

    }
   var tmp= id.split( '_' );
   switch (tmp[2])
    {
   case "1":
//        $("textBlockFakta_"+nodeid).className = "text_block";
//        $("contentTextBlockFakta_"+nodeid).className = "";
//        $("fakta_info_"+nodeid).className = "";
        $("bookmark1_top_left_"+nodeid).style.backgroundImage = "url('"+leftTopBorder+"')";
        $("bookmark1_left_"+nodeid).style.backgroundImage = "url('"+leftBorder+"')";
        $("bookmark1_left_bottom_"+nodeid).style.backgroundImage = "none";
        $("bookmark1_top_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
        $("bookmark1_bottom_"+nodeid).style.backgroundImage = "none";
        $("bookmark1_2_top_border_"+nodeid).style.backgroundImage = "url('"+rightTopBorder+"')";
        $("bookmark1_2_border_"+nodeid).style.backgroundImage = "url('"+rightBorder+"')";
        $("bookmark2_top_"+nodeid).style.backgroundImage = "none";
        $("bookmark2_bottom_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
        $("bookmark2_3_top_border_"+nodeid).style.backgroundImage = "none";
        $("bookmark2_3_border_"+nodeid).style.backgroundImage = "none";
        $("bookmark3_bottom_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
        $("bookmark3_top_"+nodeid).style.backgroundImage = "none";
        $("bookmark3_top_right_"+nodeid).style.backgroundImage = "none";
        $("bookmark3_right_"+nodeid).style.backgroundImage = "none";
        break;
   case "2":
//        $("textBlockFakta_"+nodeid).className = "text_block_fakta";
//        $("contentTextBlockFakta_"+nodeid).className = "content_text_block";
//        $("fakta_info_"+nodeid).className = "content_text_block";
        $("bookmark1_top_left_"+nodeid).style.backgroundImage = "none";
        $("bookmark1_left_"+nodeid).style.backgroundImage = "none";
        $("bookmark1_left_bottom_"+nodeid).style.backgroundImage = "url('"+leftTopBorder+"')";
        $("bookmark1_top_"+nodeid).style.backgroundImage = "none";
        $("bookmark1_bottom_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
        $("bookmark1_2_top_border_"+nodeid).style.backgroundImage = "url('"+leftTopBorder+"')";
        $("bookmark1_2_border_"+nodeid).style.backgroundImage = "url('"+leftBorder+"')";
        $("bookmark2_top_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
        $("bookmark2_bottom_"+nodeid).style.backgroundImage = "none";
        $("bookmark2_3_top_border_"+nodeid).style.backgroundImage = "url('"+rightTopBorder+"')";
        $("bookmark2_3_border_"+nodeid).style.backgroundImage = "url('"+rightBorder+"')";
        $("bookmark3_bottom_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
        $("bookmark3_top_"+nodeid).style.backgroundImage = "none";
        $("bookmark3_top_right_"+nodeid).style.backgroundImage = "none";
        $("bookmark3_right_"+nodeid).style.backgroundImage = "none";
        break;
   case "3":
//        $("textBlockFakta_"+nodeid).className = "text_block";
//        $("contentTextBlockFakta_"+nodeid).className = "";
//        $("fakta_info_"+nodeid).className = "";
        if ($("bookmark_"+nodeid+"_2").style.display == "none")
        {
            $("bookmark1_top_left_"+nodeid).style.backgroundImage = "none";
            $("bookmark1_left_"+nodeid).style.backgroundImage = "none";
            $("bookmark1_left_bottom_"+nodeid).style.backgroundImage = "url('"+leftTopBorder+"')";
            $("bookmark1_top_"+nodeid).style.backgroundImage = "none";
            $("bookmark1_bottom_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
            $("bookmark1_2_top_border_"+nodeid).style.backgroundImage = "none";
            $("bookmark1_2_border_"+nodeid).style.backgroundImage = "none";
            $("bookmark2_top_"+nodeid).style.backgroundImage = "none";
            $("bookmark2_bottom_"+nodeid).style.backgroundImage = "none";
            $("bookmark2_3_top_border_"+nodeid).style.backgroundImage = "url('"+leftTopBorder+"')";
            $("bookmark2_3_border_"+nodeid).style.backgroundImage = "url('"+leftBorder+"')";
            $("bookmark3_bottom_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
            $("bookmark3_top_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
            $("bookmark3_top_right_"+nodeid).style.backgroundImage = "url('"+rightTopBorder+"')";
            $("bookmark3_right_"+nodeid).style.backgroundImage = "url('"+rightBorder+"')";
        }
        else
        {
            $("bookmark1_top_left_"+nodeid).style.backgroundImage = "none";
            $("bookmark1_left_"+nodeid).style.backgroundImage = "none";
            $("bookmark1_left_bottom_"+nodeid).style.backgroundImage = "url('"+leftTopBorder+"')";
            $("bookmark1_top_"+nodeid).style.backgroundImage = "none";
            $("bookmark1_bottom_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
            $("bookmark1_2_top_border_"+nodeid).style.backgroundImage = "none";
            $("bookmark1_2_border_"+nodeid).style.backgroundImage = "none";
            $("bookmark2_top_"+nodeid).style.backgroundImage = "none";
            $("bookmark2_bottom_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
            $("bookmark2_3_top_border_"+nodeid).style.backgroundImage = "url('"+leftTopBorder+"')";
            $("bookmark2_3_border_"+nodeid).style.backgroundImage = "url('"+leftBorder+"')";
            $("bookmark3_bottom_"+nodeid).style.backgroundImage = "none";
            $("bookmark3_top_"+nodeid).style.backgroundImage = "url('"+topBorder+"')";
            $("bookmark3_top_right_"+nodeid).style.backgroundImage = "url('"+rightTopBorder+"')";
            $("bookmark3_right_"+nodeid).style.backgroundImage = "url('"+rightBorder+"')";
        }
        break;
    }


   if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
     {
       switch (tmp[2])
       {
       case "1":
           $("bookmark1_top_left_"+nodeid).style.backgroundImage = "none";
           $("bookmark1_top_left_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftTopBorder + "',sizingMethod='scale')";
           $("bookmark1_left_"+nodeid).style.backgroundImage = "none";
           $("bookmark1_left_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftBorder + "',sizingMethod='scale')";
           $("bookmark1_left_bottom_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark1_bottom_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark2_bottom_"+nodeid).runtimeStyle.backgroundImage="none";
           $("bookmark3_bottom_"+nodeid).runtimeStyle.backgroundImage="none";
           $("bookmark2_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";
           $("bookmark3_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";
           $("bookmark2_top_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark3_top_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark1_top_"+nodeid).runtimeStyle.backgroundImage="none";
           $("bookmark1_top_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";
           $("bookmark3_right_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark1_2_border_"+nodeid).style.backgroundImage = "none";
           $("bookmark1_2_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightBorder + "',sizingMethod='scale')";
           $("bookmark2_3_border_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark3_top_right_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark2_3_top_border_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark1_2_top_border_"+nodeid).style.backgroundImage = "none";
           $("bookmark1_2_top_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightTopBorder + "',sizingMethod='scale')";

           break;
       case "2":
           $("bookmark1_top_left_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark1_left_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark1_left_bottom_"+nodeid).style.backgroundImage = "none";
           $("bookmark1_left_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftTopBorder + "',sizingMethod='scale')";
           $("bookmark2_bottom_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark1_bottom_"+nodeid).runtimeStyle.backgroundImage="none";
           $("bookmark3_bottom_"+nodeid).runtimeStyle.backgroundImage="none";
           $("bookmark1_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";
           $("bookmark3_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";

           $("bookmark1_top_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark3_top_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark2_top_"+nodeid).runtimeStyle.backgroundImage="none";
           $("bookmark2_top_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";

           $("bookmark3_right_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark1_2_border_"+nodeid).style.backgroundImage = "none";
           $("bookmark1_2_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftBorder + "',sizingMethod='scale')";
           $("bookmark2_3_border_"+nodeid).style.backgroundImage = "none";
           $("bookmark2_3_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightBorder + "',sizingMethod='scale')";
           $("bookmark3_top_right_"+nodeid).runtimeStyle.filter = "none";
           $("bookmark2_3_top_border_"+nodeid).style.backgroundImage = "none";
           $("bookmark2_3_top_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightTopBorder + "',sizingMethod='scale')";
           $("bookmark1_2_top_border_"+nodeid).style.backgroundImage = "none";
           $("bookmark1_2_top_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftTopBorder + "',sizingMethod='scale')";

           break;
       case "3":
           if ($("bookmark_"+nodeid+"_2").style.display == "none")
           {
               $("bookmark1_top_left_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark1_left_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark1_left_bottom_"+nodeid).style.backgroundImage = "none";
               $("bookmark1_left_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftTopBorder + "',sizingMethod='scale')";
               $("bookmark2_bottom_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark1_bottom_"+nodeid).runtimeStyle.backgroundImage="none";
               $("bookmark1_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";
               $("bookmark1_top_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark2_top_"+nodeid).runtimeStyle.backgroundImage="none";
               $("bookmark2_top_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark1_2_border_"+nodeid).style.backgroundImage = "none";
               $("bookmark1_2_border_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark2_3_top_border_"+nodeid).style.backgroundImage = "none";
               $("bookmark2_3_top_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightTopBorder + "',sizingMethod='scale')";
               $("bookmark1_2_top_border_"+nodeid).style.backgroundImage = "none";
               $("bookmark1_2_top_border_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark3_bottom_"+nodeid).runtimeStyle.backgroundImage="none";
               $("bookmark3_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";
               $("bookmark3_top_"+nodeid).runtimeStyle.backgroundImage="none";
               $("bookmark3_top_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";
               $("bookmark3_right_"+nodeid).style.backgroundImage = "none";
               $("bookmark3_right_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightBorder + "',sizingMethod='scale')";
               $("bookmark2_3_border_"+nodeid).style.backgroundImage = "none";
               $("bookmark2_3_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftBorder + "',sizingMethod='scale')";
               $("bookmark3_top_right_"+nodeid).style.backgroundImage = "none";
               $("bookmark3_top_right_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightTopBorder + "',sizingMethod='scale')";
               $("bookmark2_3_top_border_"+nodeid).style.backgroundImage = "none";
               $("bookmark2_3_top_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftTopBorder + "',sizingMethod='scale')";

           }
           else
           {
               $("bookmark1_top_left_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark1_left_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark1_left_bottom_"+nodeid).style.backgroundImage = "none";
               $("bookmark1_left_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftTopBorder + "',sizingMethod='scale')";
               $("bookmark3_bottom_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark1_bottom_"+nodeid).runtimeStyle.backgroundImage="none";
               $("bookmark2_bottom_"+nodeid).runtimeStyle.backgroundImage="none";
               $("bookmark1_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";
               $("bookmark2_bottom_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";

               $("bookmark2_top_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark1_top_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark3_top_"+nodeid).runtimeStyle.backgroundImage="none";
               $("bookmark3_top_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + topBorder + "',sizingMethod='scale')";

               $("bookmark3_right_"+nodeid).style.backgroundImage = "none";
               $("bookmark3_right_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightBorder + "',sizingMethod='scale')";
               $("bookmark1_2_border_"+nodeid).runtimeStyle.filter = "none";
               $("bookmark2_3_border_"+nodeid).style.backgroundImage = "none";
               $("bookmark2_3_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftBorder + "',sizingMethod='scale')";
               $("bookmark3_top_right_"+nodeid).style.backgroundImage = "none";
               $("bookmark3_top_right_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + rightTopBorder + "',sizingMethod='scale')";
               $("bookmark2_3_top_border_"+nodeid).style.backgroundImage = "none";
               $("bookmark2_3_top_border_"+nodeid).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + leftTopBorder + "',sizingMethod='scale')";
               $("bookmark1_2_top_border_"+nodeid).runtimeStyle.filter = "none";
           }
           break;
       }
     }


}

function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG')
    {
      if (/\.png$/.test(element.src))
      {
        src = element.src;
        element.src = "/blank.gif";
      }
    }
    else
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1];
        element.runtimeStyle.backgroundImage="none";
      }
    }
    if (src)
    element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";


  }

}

function checkresult(id)
{
    res = parseInt(document.getElementById(id+"_price").value);
    userres = 0;
    userball = 0;
    userwrong = 0;

    children_input = document.getElementById(id).getElementsByTagName("input");
    for ( i = 0; i < children_input.length; i++ )
    {
        if( children_input.item(i).checked)
        {
            id_answer = id+"_price_"+i;
            userball = parseInt(document.getElementById(id_answer).value);
            if ( userball > 0 ) {
              userres = userres + userball;
            }
            else
            {
              userwrong = userwrong + 1;
            }

        }

    }
    children_select = document.getElementById(id).getElementsByTagName("select");
    for ( i = 0; i < children_select.length; i++ )
    {
        id_answer = id+"_price_"+children_select.item(i).selectedIndex;
        userball = parseInt(document.getElementById(id_answer).value);
        if ( userball > 0 ) {
              userres = userres + userball;
        }
        else
        {
              userwrong = userwrong + 1;
        }

   }
    if ( (res == userres) && (userwrong==0) ) {

         document.getElementById(id+"_text_id").className= "right_answer";
         document.getElementById(id+"_text").innerHTML = "Riktig";
         ansState = 1;
             }
    else
    {
        document.getElementById(id+"_text_id").className= "wrong_answer";
        document.getElementById(id+"_text").innerHTML = "Galt svar, pr&oslash;v igjen";
        ansState = 0;
    }

}

function addcomment(url, currentUser)
{

      var method = "POST";
      var onload = getanswComment;
      var onerror = errorComment;
      var contentType = headers = false;
      var params = "ParentNodeID="+$('parent_node_id_comment').value;
           params = params+"&SubjectText="+$('subj_text_comment').value;
           params = params+"&BodyText="+$('text_id_comment').value;
      return setAjaxRequest(method, url, params, onload, onerror, contentType, headers);
}

function getanswComment()
{
    result = eval( '(' + this.req.responseText + ')' );
     if ( result.error_code == "0" )
     {
        $('set_comment').innerHTML =result.htmlComment +  $('set_comment').innerHTML;
     }
}

function errorComment()
{

}

function questionFakta(infoID,url,questionID)
{
      var method = "POST";
      var onload = getTextInfo;
      var onerror = errorComment;
      var contentType = headers = false;
      var params = "NodeID="+infoID;
      params = params+"&QuestionID="+questionID;
      return setAjaxRequest(method, url, params, onload, onerror, contentType, headers);
}

function getTextInfo()
{
    result = eval( '(' + this.req.responseText + ')' );
     if ( result.error_code == "0" )
     {
        var faktaID = 'fakta_info_' + result.questionID;
        $( faktaID ).innerHTML = result.html;
        show( $( faktaID) );
        var divID = 'contentTextBlockFakta_' + result.questionID;
        hide( $(divID ) );
//        var faktaID = 'contentTextBlockFakta_' + result.questionID;
//        $( faktaID ).innerHTML = result.html;          
     }
}


function customSub(index)
{
    checkresult("questionanswers_"+index)
    if (ansState == 1)
    {
      document.myform.submit();
    }
}

function getDepartmentsAns( res )
{
    var objSel = $('dep');
    cleanSelect( objSel );
       addOption( objSel, '', '' );

    for ( var dep in res )
    {
       addOption( objSel, res[dep]['name'], res[dep]['node_id'] );
    }
    if (depname != '')
    {
        var firm = $('firm');
        for (var i = 0; i < firm.options.length; i++)
        {
          if ($('firm_orig').value == firm.options[i].value)
          {
            firm.selectedIndex = i;
          }
        }
        $('firm').value = $('firm_orig').value;
        var dep = $('dep');
        for (var i = 0; i < dep.options.length; i++)
        {
          if ($('dep_orig').value == dep.options[i].value)
          {
            dep.selectedIndex = i;
          }
        }
    }
return;
}

function setCustomField()
{
    $('firm_orig').value = $('firm').value;
    $('dep_orig').value = $('dep').value;
    $('login').value = $('mail').value;
}

function showart(index)
{
  var obj=$('art_' + index);
  if (visArt!='')
  {
    hide( visArt );
  }
  if (obj)
  {
      show( obj );
      visArt = obj;
  }
}

function changeBg(activeBookm, bookm, bookm2, activeBg)
{
  $(bookm).style.backgroundImage = 'none';
  $(bookm2).style.backgroundImage = 'none';

  $(activeBookm).style.backgroundImage = "url('"+activeBg+"')";
  if(activeBookm == 'mine_kurs')
  {
    $("kurs_bottom_border").className = "active_bookm_bottom_border";
    $("profil_bottom_border").className = "";
    $("admin_bottom_border").className = "";
  }
  else if (activeBookm == 'profil')
  {
    $("kurs_bottom_border").className = "";
    $("profil_bottom_border").className = "active_bookm_bottom_border";
    $("admin_bottom_border").className = "";
  }
  else if (activeBookm == 'admin')
  {
    $("kurs_bottom_border").className = "";
    $("profil_bottom_border").className = "";
    $("admin_bottom_border").className = "active_bookm_bottom_border";
    xajax_getactivitycountusers( );
  }
}

function butikkvis()
{
    if (butikState == 0)
    {
      show('butik');
      butikState=1;
    }
    else
    {
      hide('butik');
      butikState=0;
    }
}


function kursUsergroup( publishDate, modulID, modulN, moduleName, userResult, totalResult, totalEnabledUsers, startedUsers, finishedUsers)
{
    hide('local_adm');
    show('local_admin_kurs_info_id');
    curmod = modulID;
//    $('chosen_module_info').innerHTML= modulN + ' ' + moduleName + ', gj.sn poeng: '+ userResult +' av ' + totalResult + ', antall brukere: ' + startedUsers + '/' + totalEnabledUsers + ', antall godkjent ' + finishedUsers + ' av ' + totalEnabledUsers;
    $('chosen_module_info').innerHTML= '<b>Kurs: ' + moduleName + '</b>';
    $('publish_date').innerHTML= publishDate;
   // $('new_questions').innerHTML= 'NY questions ? poeng publisert ?';
    groupID = 0;
    xajax_getmoduleUserListXajax(  modulID, groupID, 0, 5, 1, 50 );
    xajax_getactivitygraph( modulID );
    //xajax_getactivitycountusers( );


}

function tablesort( num )
{
    module = $('currentidformodule').value;
    gropid = $('currentgroupid').value;
    offset = $('currentgoffset').value;
    numpage = $('currentpagenum').value;
    xajax_getmoduleUserListXajax( module , gropid, offset, num, numpage, 50 );
}

function listcreate(param, countusers, moduleID, groupID, sortby, curpage, offsetcur, grouplist2, limit)
{
   if( checkvaroftheprintpage == 0)
   {
    $('currentidformodule').value = moduleID;
    $('currentpagenum').value = curpage;
    $('currentgroupid').value = groupID;
    $('currentgoffset').value = offsetcur;
    var filterlist = document.getElementById("filter_list_id");
    var notificationlisttable = document.getElementById("list_of_the_users_for_notification");
    var notificationlength = notificationlisttable.rows.length;
   }
   var table = document.getElementById("usergroup_list");
   var length = table.rows.length;
   var rowstate = 0;
   //------- Group list for filter
   if( checkvaroftheprintpage == 0)
   {
    filterlist.innerHTML='<a href="javascript:void(0)" onclick="fulllist()" title="All groups">Alle</a>';
    for (var k = 0; k < grouplist2.length; k++)
    {
      filterlist.innerHTML= filterlist.innerHTML + '<a href="javascript:void(0)" onclick="xajax_getmoduleUserListXajax('+moduleID+','+grouplist2[k]['node_id']+', 0, 5, 1, 50 );" title="You will see users only from this group">'+grouplist2[k]['name']+'</a>';
    }
   }
   //-----Group list end

   for (var i = 1; i < length; i++)
   {
     table.deleteRow(1);
   }
   for (var i = 0; i < param.length; i++)
   {
     newrow = table.insertRow(i+1);
     newrow.insertCell(0).innerHTML = '<span class="space_info">'+param[i]['username']+'</span>';
     newrow.insertCell(1).innerHTML = '<span class="space_info">'+param[i]['group_name']+'</span>';
     newrow.insertCell(2).innerHTML = '<span class="space_info">'+param[i]['status']+'</span>';
     newrow.insertCell(3).innerHTML = param[i]['points'];
     newrow.insertCell(4).innerHTML = param[i]['startdate'];
     newrow.insertCell(5).innerHTML = param[i]['finished'];
     table.rows[i+1].cells[0].className='grouplist_td1';
     table.rows[i+1].cells[1].className='grouplist_td2';
     table.rows[i+1].cells[2].className='grouplist_td3';
     table.rows[i+1].cells[3].className='center_text grouplist_td4';
     table.rows[i+1].cells[4].className='center_text grouplist_td5';
     table.rows[i+1].cells[5].className='center_text grouplist_td6';
     if ((i%2) && (i!=0))
     {
       table.rows[i+1].style.backgroundColor='#ededed';
     }
   }
   //---- Creation of the userlist for notifications
  if( checkvaroftheprintpage == 0)
  {
   for (var i = 1; i < notificationlength; i++)
   {
     notificationlisttable.deleteRow(1);
   }
   for (var i = 0; i < param.length; i++)
   {
     newrow = notificationlisttable.insertRow(i+1);
     var tempmail="'"+param[i]['email']+"'";
     newrow.insertCell(0).innerHTML = '<span class="space_info"><input id="check_' + param[i]['userid'] + '" onclick="emaillistcreation(this, ' + tempmail + ')" type="checkbox" name="checked_' + param[i]['userid'] + '"> ' + param[i]['username'] + '</span>';

     // place for checking if array for notification contain current email
     maillistlength = maillist.length;
     for (var t = 0; t< maillistlength; t++)
     {
       if (maillist[t] == param[i]['email'])
       {
          $('check_' + param[i]['userid']).checked = 'true';
       }
     }

     //-----------
     newrow.insertCell(1).innerHTML = '<span class="space_info">'+param[i]['email']+'</span>';
     newrow.insertCell(2).innerHTML = param[i]['points'];
     newrow.insertCell(3).innerHTML = param[i]['startdate'];
     newrow.insertCell(4).innerHTML = param[i]['finished'];
     notificationlisttable.rows[i+1].cells[0].className='notgrouplist_td1';
     notificationlisttable.rows[i+1].cells[1].className='notgrouplist_td2';
     notificationlisttable.rows[i+1].cells[2].className='center_text notgrouplist_td3';
     notificationlisttable.rows[i+1].cells[3].className='center_text notgrouplist_td4';
     notificationlisttable.rows[i+1].cells[4].className='center_text notgrouplist_td5';
     if ((i%2) && (i!=0))
     {
       notificationlisttable.rows[i+1].style.backgroundColor='#ededed';
     }
   }
  }
   //---- End of the creation userlist for notification


   //$("google_page").innerHTML =
  // for (var i = 1; i < length; i++)
  // {
  //   if (i%2)
  //   {
    //   table.rows[i+1].style.backgroundColor='#ededed';
    // }
   //}
  if( checkvaroftheprintpage == 0)
  {
   googlehtml = "";
   countpage = Math.ceil(parseInt(countusers)/limit);

   for (var j = 1; j <= countpage; j++ ) {
       countrow = limit*(j-1);
       funonclick = ' onclick="xajax_getmoduleUserListXajax('+moduleID+','+groupID+','+countrow+','+sortby+','+j+',50);"';
       if ( curpage == j ) {
           googlehtml = googlehtml + "<span class='current' >"+j+"</span>";
       }
       else
       {
           googlehtml = googlehtml + "<span class='other'><a href='javascript:void(0)' "+funonclick+">"+j+"</a></span>";
       }

   }

   $("google_page").innerHTML = googlehtml;
   $("notif_google_page").innerHTML = googlehtml;
  }

}

function emaillistcreation(element, email)
{
    maillistlength = maillist.length;

    if (element.checked)
    {
        maillist[maillistlength] = email;

    }
    else
    {
        for (var t = 0; t< maillistlength; t++)
        {
          if (maillist[t] == email)
          {
            maillist.splice(t, 1);
          }
        }
    }
}

function fulllist()
{
    $('currentgroupid').value = 0;
    xajax_getmoduleUserListXajax(  curmod, 0, 0, 5, 1, 50 );
}

function backToTheList()
{
    show('local_adm');
    hide('local_admin_kurs_info_id');
}

function changeAccess(obj, groupID, moduleUrl)
{
        $("message").innerHTML="";
        var method = "POST";
        var url = moduleUrl;

        var params = "objID="+groupID;
        parentobj = obj.parentNode;
        objdivs = parentobj.getElementsByTagName("div");
        if (obj.checked) {
           params = params+"&action=1";
           if ( objdivs ) {

              objInput = objdivs.item(0).getElementsByTagName("input");
              if ( objInput )
              {
                  for (var i = 0; i < objInput.length; i++ )
                  {
                       objInput.item(i).disabled = true;
                  }
              }
           }
        }
        else
        {
           params = params+"&action=0";
           if ( objdivs ) {
              objInput = objdivs.item(0).getElementsByTagName("input");
              if ( objInput )
              {
                  for (var i = 0; i < objInput.length; i++ )
                  {
                      objInput.item(i).disabled = false;
                  }
              }

              if ( objInput )
              {
                  for (var k = 0; k < objInput.length; k++ )
                  {
                      if ( objInput.item(k).checked ) {
                          parentobjitem = objInput.item(k).parentNode;
                          objdivsitem = parentobjitem.getElementsByTagName("div");

                           if ( objdivsitem ) {

                               objInputitemitem = objdivsitem.item(0).getElementsByTagName("input");
                               if ( objInputitemitem )
                               {
                                   for (var j = 0; j < objInputitemitem.length; j++ )
                                   {
                                       objInputitemitem.item(j).disabled = true;
                                   }
                               }
                           }


                      }
                  }
              }
           }



        }
        params = params+"&moduleID="+$('currentmoduleid').value;

        var onload = changeStatusResult;
        var onerror = errorChangeHandler;
        var contentType = headers = false;
        return setAjaxRequest(method, url, params, onload, onerror, contentType, headers);
}


function changeStatusResult(obj)
{
    result = eval( '(' + this.req.responseText + ')' );
    if (result.error_code == 0)
    {
        $("message").innerHTML="succes";
    }
    else
    {
       alert( 'error' );
    }
}

function errorChangeHandler()
{
    alert('error');
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}




function openGroupTreeajax( moduleUrl, moduleID )
{

    var method = "GET";
    var url = moduleUrl;
    url=url+"/moduleID="+moduleID;
    var params="";
    var onload = showLightBoxTree;
    var onerror = errorChangeHandler;
    var contentType = headers = false;
    return setAjaxRequest(method, url, params, onload, onerror, contentType, headers);
}


function showLightBoxTree()
{
    result = eval( '(' + this.req.responseText + ')' );
    if ( result.error_code == 0  ) {

         $('contentstructuregroup').innerHTML = result.result_tree;
         show($('show_group_tree'),false);




    /*    var objOverlay = document.getElementById('overlay');
        var arrayPageSize = getPageSize();
        var arrayPageScroll = getPageScroll();

	// set height of Overlay to take up whole page and show
        objOverlay.style.height = (arrayPageSize[1] + 'px');
        show($('overlay'),false);
        //objOverlay.style.display = 'block';
        var boxSizeWidth = 250;
        var boxSizeHeight = 150;
        var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - boxSizeHeight) / 2);
        var lightboxLeft = ((arrayPageSize[0] - 20 - boxSizeWidth) / 2);

        var objLightbox = document.getElementById('light-form-lbox');

        $('contentstructuregroup').innerHTML = result.result_tree;
        objLightbox.innerHTML = $('show_group_tree').innerHTML;

        objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
        objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
        objLightbox.style.width = boxSizeWidth + 'px' ;
        show($('light-form-lbox'),false);*/
    }
}

function disabledInput()
{

  parentobj = $('contentstructuregroup');


    if ( parentobj  ) {

          objInput = parentobj.getElementsByTagName("input");
          for (var k = 0; k < objInput.length; k++ )
              {
                      if ( objInput.item(k).checked ) {
                          parentobjitem = objInput.item(k).parentNode;
                          objdivsitem = parentobjitem.getElementsByTagName("div");

                           if ( objdivsitem ) {

                               objInputitemitem = objdivsitem.item(0).getElementsByTagName("input");
                               if ( objInputitemitem )
                               {
                                   for (var j = 0; j < objInputitemitem.length; j++ )
                                   {
                                       objInputitemitem.item(j).disabled = true;
                                   }
                               }
                           }


                      }
              }
    }


}
function openGroupTree( moduleID )
{
    parentobj = $('contentstructuregroup');


    if ( parentobj  ) {
          var inputArray = Array();
          objInput = parentobj.getElementsByTagName("input");
          if ( objInput )
          {
              for (var i = 0; i < objInput.length; i++ )
              {
                  inputArray[i] = objInput.item(i).id;
              }

              xajax_getaccessXajax( inputArray, moduleID );



          }




       }

    var objOverlay = document.getElementById('overlay');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
    $('currentmoduleid').value = moduleID;


    $("message").innerHTML="";
	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');

        show($('overlay'),false);
        //objOverlay.style.display = 'block';
        var boxSizeWidth = 250;
        var boxSizeHeight = 150;
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - boxSizeHeight) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - boxSizeWidth) / 2);

	var objLightbox = document.getElementById('light-form-lbox');
        //objLightbox.innerHTML = $(contentID).innerHTML;

	objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
	objLightbox.style.width = boxSizeWidth + 'px' ;
        show($('light-form-lbox'),false);

}



function hideLightBox( )
{
        hide($('overlay'));
        hide($('light-form-lbox'));
}




function addOption (oListbox, text, value)
{
  var oOption = document.createElement("option");
  oOption.appendChild(document.createTextNode(text));
  oOption.setAttribute("value", value);
  oListbox.appendChild(oOption);
}

function cleanSelect( objSelect )
{
   var ua = navigator.userAgent.toLowerCase();
   if ( ua.indexOf("opera") != -1 )
   {
      setTimeout( function(){objSelect.selectedIndex = -1;}, 1);
      objSelect.options.length = 0;
      setTimeout( function(){objSelect.selectedIndex = -1;}, 1);
   }
   else
   {
      objSelect.options.length = 0;
   }
}

function notificationlist(notType)
{
    hide('id_module_assigned_users_list');
    show('block_with_users_for_notification');
    $('title_of_the_users_for_notification').innerHTML = "E-post melding, velg fra liste";
}

function backtotheuserlist()
{
    hide('block_with_users_for_notification');
    show('id_module_assigned_users_list');
}

function sendemail(typeofemail)
{
    show('overlay');
    show('email_block');
    if ( typeofemail == 1 )
    {
      $('emailtype').innerHTML = "E-post til de som ikke er godkjent";
    }
    else if ( typeofemail == 2 )
    {
      $('emailtype').innerHTML = "E-post melding, velg fra liste";
    }
    else if ( typeofemail == 3 )
    {
      $('emailtype').innerHTML = "E-post melding til alle";
    }
    $('nomber_of_type').value = typeofemail;
}

function closeemail()
{
    hide('overlay');
    hide('email_block');
    $('mailsubject').value = "";
    $('mailtext').value = "";
}

function department(index)
{
  xajax_getDepartments( index );
  return;
  var curElem=0;
  $('dep').value='';
  for( var opt in $('dep').options )
   {
    if ($('dep').options[opt].tagName=='OPTION')
     {
       $('dep').options[opt].style.display='none';
     }
   }

  for( var opt in $('dep').options )
   {
    if ($('dep').options[opt].tagName=='OPTION')
     {
       curElem=$('dep').options[opt].id.split('_');
       if (curElem[1]==index)
       {
           $('dep').options[opt].style.display='block';
       }
     }
   }
}

function sendmailtoall()
{
   moduleID = $('currentidformodule').value;
   if ($('nomber_of_type').value == '1' ) {
       xajax_sendmailtoall( moduleID, $('mailsubject').value ,  $('mailtext').value , 1 );
   }
   if ($('nomber_of_type').value == '2' ) {
       xajax_sendmailtochecked( maillist, $('mailsubject').value ,  $('mailtext').value );

   }
   if ($('nomber_of_type').value == '3' ) {
       xajax_sendmailtoall( moduleID, $('mailsubject').value ,  $('mailtext').value, 0 );
   }

}

function sendmailtonotappoved()
{
   moduleID = $('currentidformodule').value;
   xajax_sendmailtoall( moduleID, $('mailsubject').value ,  $('mailtext').value ,true );
}

function sendmailtochecked()
{
    // array from user object id
    arraychekeduserlist = array();
//   xajax_sendmailtochecked( arraychekeduserlist, $('mailsubject').value ,  $('mailtext').value );
    xajax_sendmailtochecked( maillist, $('mailsubject').value ,  $('mailtext').value );
}

function setactivitygraph( graphpath )
{

    $('activitygraph').src=graphpath;

}

function setactivityusersgraph( graphpath )
{

    $('activityusersgraph').src=graphpath;

}



function showgraph()
{
    moduleID = $('currentidformodule').value;
    xajax_getactivitygraph( moduleID );
}

function printuserlist()
{
    modulID = $('currentidformodule').value;
    grID = $('currentgroupid').value;
    $('pdfcurrentmodule').value =  modulID;
    $('pdfcurrentgroupid').value = grID;
    document.printlist.submit();
}

function printuserlistsubm()
{
    document.printlist.submit();
}

function overritelink()
{
    grID = $('currentgroupid').value;
    modulID = $('currentidformodule').value;
    if (printstate !== 1)
    {
      printlinktemplate = $('print_list_link').href;
      printstate = 1;
    }
    $('print_list_link').href = printlinktemplate + '/' + grID + '/' + modulID;
}

function bookm1()
{
    hide("user_info");
    show("kurs_info");
    hide("admin_bookm");
    hide("users_activity");
}

function bookm2()
{
    hide("kurs_info");
    show("user_info");
    hide("admin_bookm");
    hide("users_activity");
}

function bookm3()
{
    hide("kurs_info");
    hide("user_info");
    show("admin_bookm");
}

function questionlist()
{
    show("overlay");
    show("questionlist_block");
}

function questionlistclose()
{
    hide("overlay");
    hide("questionlist_block");
}

function showcomments()
{
    hide('comment_text');
    $( 'text_id_comment' ).value = '';
    show('comment_form');
}