/*
 * JetDraft WebBook Core
 * http://www.jetdraft.com
 * Copyright (c) 2008 JetDraft Software
 */
 
    var NvConfig;
    var quizSrc;
    var treeSrc;
    var searchSrc ;
    var treeFrame;
    var mainFrame ;
    var bottomFrame;
    var activeId;

	var sAboutInfo = 'JetDraft Document Suite 2008 Web Help Core ver. 0.4';
	var sTxMainIndex = 'Content';
	var sTxNoEndTest = 'Do you have unfinished testing!';
	var sTxEndTest = 'Finish testing?';
	var sTxPleaseEndTest = 'Finished testing';
	var sTxNoFavAccess = 'Until testing is done, favorites not available';
	var sTxFavorites = 'Bookmarks';
	var sTxNoFav = 'Bookmarks no';
	var sTxNoPageFav = 'Page is not on the list of favorites';
	var sTxPageInFav = 'Page already on the list of favorites';
	var sTxGlbErr = 'Error!';
	var sTxAnswerQuiz = 'Answer';
	var sTxAssured = 'Are you sure?';
	var sTxNoDataAccess = 'Until testing is done, conversions are not available';
	var sTxInputStrSearch = 'Search';
	var sTxGoSearch = 'Find!';
	var sTxIndex = 'Content';
	var sTxDefault = 'No data';
	var sTxMrk = 'No good';
	var sTxMrk1 = 'Tolerably';
	var sTxMrk2 = 'Good';
	var sTxMrk3 = 'Excellent';
	var sTxNoQuiz = 'Testing is missing';
	var sTxQuizInfo = 'List of';
	var sTxQuizEndTest = 'Finish test';
	var sTxQuizEndTestExt = 'Finish testing?';
	var sTxClearQuizInfo = 'Clear history test?';
	var sTxQuizInfoClear = 'Clear history';
            
    delCookie("loading");
    initFrames();

    var NpQuizId = '';
    if (!getSettings("NpQuizOn") || getSettings("NpQuizOn") == 'false'){
          $("#button9",bottomFrame).hide()
          }
    $("span.div",treeFrame).attr("style","cursor:pointer");
    $("span.folder",treeFrame).attr("style","cursor:pointer");

function on_search()
   {
   var sTxt = document.getElementById("searchText").value;
   search(escape(sTxt.toLowerCase()));
}

function getNameBrouser() {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1) {
    return "msie"
  }
  if (ua.indexOf("opera") != -1) {
    return "opera"
  }
  if (ua.indexOf("gecko") != -1) {
    return "gecko";
  }
  if (ua.indexOf("safari") != -1) {
    return "safari";
  }
  if (ua.indexOf("konqueror") != -1) {
    return "konqueror";
  }
  return "unknown";
}

function stripDotHtml(s)
      {
        var ss = s.split(".");
        return ss[0];

      }
    function initFrames()
      {
        var browser = getNameBrouser()
        if (true)
          {
            try {NvConfig = (top.frames[1].document)}
            catch(err) {}

            try {quizSrc = (top.frames[2].document) }
            catch(err) {}

            try {treeSrc = (top.frames[3].document) }
            catch(err) {}

            try {searchSrc = (top.frames[4].document)}
            catch(err) {}

            try {treeFrame = (top.frames[5].document)}
            catch(err) {}

            try {mainFrame = (top.frames[6].document)}
            catch(err) {}

            try {bottomFrame = (top.frames[7].document)}
            catch(err) {}
            activeId = setTimeout("initFrames()", 1000);
          }
        if (mainFrame != '' && bottomFrame != '' && activeId != '' && NvConfig != '' && quizSrc != '' && treeSrc != null && searchSrc != null && treeFrame != null)
          {
            clearTimeout(activeId);
            delCookie("loading")
            if (getCookie("name") != null)
              {
              if(browser == "msie"){
					parent.mainFrame.document.location.replace("auth.html");
			   }
                selectQuiz(getCookie("current"))
              }
            else
              {
                if((mainFrame.location.href).match(/mainfrm.html/))
                  {
                    nextIndex(1)
                  }
              }
          }
      }

    function checkCookies()
      {
        var tmp = 't'+Math.round(Math.random()*100000);
        setCookie(tmp,1);
        var tmp2 = getCookie(tmp);
        delCookie(tmp);

        return tmp2
      }

    function setCookie(name,value) {
      top.document.cookie=escape(name)+"="+escape(value)+"; path=/; expires=Mon, 01-Jan-2029 00:00:00 GMT";
    }
    function delCookie(name) {
      top.document.cookie = escape(name) +'=;path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT;';
    }

function getCookie(name) {
	var cookie = " " + parent.document.cookie;
	var search = " " + escape(name) + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

    function about()
      {
        alert(sAboutInfo);
      }

    function insertLink(div)
      {
        var classs = '';
        if (getCookie("curIndex") == $(div).attr("name"))
          classs = 'color:#0000CC';
        if ($(div).attr("name"))
          return "style='cursor:pointer"+classs+"' onclick='parent.top.selectIndex(\""+$(div).attr("name")+"\")'";
      }

    function nextQuiz(div)
      {
        if (div == 1)
          var next = 1;
        else
          var next = 0;
        startQuiz()
        $("span",parent.quizSrc.document).each(function() {
          if (next == 2)
            {
              if (getCookie($(this).attr("file")) == null)
                next = 1;
            }
          if ($(this).attr("file") == div)
            {
              if (getCookie($(this).attr("file")) != null)
                next = 2;
              else
                next = 2;
            }
          if (next == 1)
            {
              selectQuiz($(this).attr("file"))
              next = 3;
            }
          if (next == 3)
            return;
        })
        if (next == 0 || next == 2)
          {
            nextQuiz(1)
          }
      }

    function answerQuiz(div)
      {
            try {mainFrame = (top.frames[6].document)}
            catch(err) {}

        var answer = $('input[name='+div+']:checked',mainFrame).val();
        if (answer == 'undefined' || !answer) return;
        setCookie(div, answer);

        var answered = 0;
        var notanswered = 0;
        $("span",parent.quizSrc.document).each(function() 
          {
            if (getCookie($(this).attr("file")) != null)
              answered ++
            else
              notanswered ++
          })
        if (notanswered == 0)
          {
            if (confirm(sTxEndTest))
              finishQuiz()
          }
        else
          {
            nextQuiz(div);
          }
      }

    function selectIndex(div)
      {
        if (getCookie("name"))
          {
            alert(sTxPleaseEndTest)
            return;
          }
        if (div == "undefined" || div == '') return;
        setCookie("curIndex",div)
        var code = $("div[name="+div+"]",treeSrc).attr("code")
        $("span.file",treeFrame).removeClass("select");
        $("#span"+code,treeFrame).addClass("select");
        top.document.getElementById('mainFrame').contentWindow.location  = ("docs/"+div);
		top.activePage = div;
      }

    function getSettings(name)
      {
        if (name == '') return;
        var res = $("[name="+name+"]",NvConfig).val();
        if (res == "on" || res == 'true') return true
        else return res
      }

    function showfav()
      {
        if (getCookie("name"))
          {
            alert(sTxNoFavAccess)
            return
          }

        var curFav = new Array;
        if (getCookie("fav") != null)
          curFav = getCookie("fav").split("|")

        var res = '<h2>' + sTxFavorites + '</h2><hr align="left" width="70%" noshade>';
        var parsed = new Array()
        var flag = 0;
        for (i=0;i<curFav.length;i++)
          {
           if (curFav[i] != null && curFav[i] != '')
             {
               res += "<li class='file' style=margin:3px 0 0 0;><span style='font:normal 12px Arial,Helvetica,sans-serif;cursor:pointer' onclick='parent.mainFrame.document.location.replace(\""+curFav[i]+"\")'>"+curFav[i]+"</span>   <span style='cursor:pointer;color:#660000' onclick='parent.frames[0].delFav(\""+curFav[i]+"\")'><img src='images/pic_del.gif'></span></li>";
               flag = 1;
             }
          }
        if (!flag)
          res = '<h2>' + sTxFavorites + '</h2><hr align="left" width="70%" noshade>';
        res += "</ul>"
        $("body",treeFrame).html(res)
      }

   function delFav(div)
      {
        if (div == null) return;
        var curFav = new Array;
        
        if (getCookie("fav") != null)
          curFav = getCookie("fav").split("|")
        if (jQuery.inArray(div, curFav) != -1)
          {
            curFav = delFromArray(curFav, div);
            setCookie("fav",curFav.join("|"));
          }
        else
          {
            alert(sTxNoPageFav);
          }
        showfav()
      }

   function tofav()
      {
        if (getCookie("name"))
        {
           return
         }
        var curIndex = parent.mainFrame.document.URL;
        if (curIndex == null) return;
        var curFav = new Array;
        if (getCookie("fav") != null)
          curFav = getCookie("fav").split("|")
        if (jQuery.inArray(curIndex, curFav) == -1)
          {
            curFav[curFav.length] = curIndex;
            setCookie("fav",curFav.join("|"));
            showfav()
          }
        else
          {
            alert(sTxPageInFav);
          }
      }

    function nextIndex(action)
      {
        if (getCookie("name") != null)
          {
            nextQuiz(getCookie("current"))
            return;
          }
        var next = 0;
        if (action == 'next' || action == 'prev')
          {
            var div = getCookie("curIndex")
          }
        if (action == 1)
          next = 1;
        var prev = '';
        $("div",parent.treeSrc.document).each(function() {
          if ($(this).attr("name") != null)
            {
              if (next == 2)
                {
                  next = 1;
                }
              if (next == 1)
                {
                  selectIndex($(this).attr("name"))
                  next = 3;
                }
              if ($(this).attr("name") == div)
                {
                  if (action == 'next')
                    next = 2;
                  if (action == 'prev')
                    selectIndex(prev)
                }
              if (next == 3)
                return;

              prev = $(this).attr("name");
            }
        })
      }

    function Loading(num,action)
      {
        var loading = new Array;
        if (getCookie("loading") != null)
          loading = getCookie("loading").split("|")

        if (action == 'check')
          {
            if (jQuery.inArray(num, loading) == -1)
              {
                loading[loading.length] = num;
                setCookie("loading",loading.join("|"));
                return 1;
              }
            else
              {
                return 0;
              }
          }
        if (action == 'remove')
          {
            var newLoading = new Array();
            for (i=0;i<loading.length;i++)
              {
                if (loading[i] != num)
                  newLoading[newLoading.length] = loading[i];
              }
            delCookie("loading");
            setCookie("loading",newLoading.join("|"));
          }
        if (action == 'add')
          {
            loading[loading.length] = num;
            setCookie("loading",loading.join("|"));
          }

      }

    function selectQuiz(div)
      {
        if (!getCookie("name")) return
        
        var sEmptyPage= '<body topMargin="0" marginwidth="4" marginheight="0" onload="index()">\n<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">\n<tr>\n<td align="center">\n<img src="images/loading.gif"/>\n</td>\n</tr>\n</table>\n</body>\n';

        try
          {top.document.getElementById('mainFrame').contentWindow.document.body.innerHTML = sEmptyPage;}
        catch(r)
          {
          }
        setCookie("current",div)
        if (getCookie("loading")) return;
        startQuiz()
        delCookie("loading")
        qCaption = ''
        qAnswers = ''
        qButton = ''
        $("span",parent.quizSrc.document).each(function() {
        //$("span",quizSrc).each(function() {
          if ($(this).attr("file") == div)
            {
              if (Loading(div,"check"))
                {
                  Loading(div,'add')
                  $.ajax({
                    type: "GET",
                    url: "docs/"+$(this).attr("file"),
                    error: function(msg){alert(sTxGlbErr); delCookie("loading")},
                    success: function(msg){
                      Loading(div,'remove')
		      msg = msg.replace(/src=\"/g, "src=\".\\docs\\");
                      qCaption = msg;
                    }
                  })
                }
              $("div",this).each(function(){
                var num = $(this).attr("file")
                if (Loading(num,"check"))
                  {
                    Loading(num,'add')
                    $.ajax({
                      type: "GET",
                      url: "docs/"+$(this).attr("file"),
                      error: function(msg){alert(sTxGlbErr);delCookie("loading")},
                      success: function(msg){
                        Loading(num,'remove')
                        checked = '';
                        if (getCookie(div) == num)
                          checked = 'checked'
                        if (getCookie("current") == div){
			   msg = msg.replace(/src=\"/g, "src=\".\\docs\\");
                           qAnswers += top.quiz_file_data_3 + msg + top.quiz_file_data_4 + "<input type='radio' name='" + div + "' value='" + num + "'>" + top.quiz_file_data_5;
			}
                      }
                    })
                  }
              })
              qButton = div;
              activeId = setTimeout("showQuiz()",500);
            }
        })

      }
    function showQuiz()
      {
        if (getCookie("loading") != null &&  getCookie("loading") != '')
          {
            activeId = setTimeout("showQuiz()",200);
            return
          }
        parent.mainFrame.document.body.innerHTML = top.quiz_file_top + top.quiz_file_data_1 + qCaption + top.quiz_file_data_2 + qAnswers + top.quiz_file_bottom + qButton + top.quiz_file_bottom_1;
        clearTimeout(activeId);
      }
    
    function delFromArrayI(array,num)
      {
         var newA = new Array();
         for (i=0;i<array.length;i++)
           {
             if (i != num)
               newA[newA.length] = array[i];
           }
         return newA;
      }

    function delFromArray(array,num )
      {
         var newA = new Array();
         for (i=0;i<array.length;i++)
           {
             if (array[i] && array[i] != num)
               {
                 newA[newA.length] = array[i];
               }
           }
         return newA;
      }

    Array.prototype.max = function()
      {
    	return Math.max.apply({},this)
      }

    function clearAllCookie()
      {
        if (!confirm(sTxAssured)) return;
        delCookie("name")
        delCookie("prof")
        delCookie("kurs")
        delCookie("grup")

        delCookie("current")
        delCookie("loading")

      }
    function search(searchText)
      {
        if (getCookie("name"))
          {
            alert(sTxNoDataAccess)
            return
          }
			
			var tmp = '';
            var weight = '';
            var i = 0;
            var res = "<ul>";

            tmp += '<h2>' + sTxInputStrSearch + '</h2><hr align="left" width="70%" noshade>';
            tmp += '<div style="margin:5px 0 0 0;">';
	    tmp += '<form id="form1" name="form1" method="post" action="javascript:on_search()">';
            tmp += '<input type="text" id="searchText" style="font:normal 12px Arial,Helvetica,sans-serif; border:1px #888888 solid; width:60%;" value="" /> &nbsp;&nbsp;';
            tmp += '<input type="button" value="';
            tmp += sTxGoSearch;
            tmp += '" style="font:normal 12px Arial,Helvetica,sans-serif;" onclick="on_search()" /></form>';
            tmp += '</div>'
            tmp += '<div id="searchResult"></div>';
            $("body",treeFrame).html(tmp)
			
			if(!searchText) return;
			tmp = '';
			$("#searchResult",parent.treeFrame.document).html("<img src='images/loading.gif'>")
            searchText = unescape(searchText)
            var weightA = new Array
            var divA = new Array
            $("div",searchSrc).each(function() {
              var div = $(this).attr("name");
              
              if(div.indexOf(searchText) != -1){
				weightA[weightA.length] = 1000;
				divA[divA.length] = div;
			   }
			   
              $("span",this).each(function() {
                tmp = $(this).attr("name");
                weight = $(this).attr("weight");
                if (tmp == searchText)
                  {
                    if (jQuery.inArray(div, divA) == -1)
                      {
                        weightA[weightA.length] = weight;
                        divA[divA.length] = div;
                      }
                  }
              })
            })
            if(weightA.length > 0){
            res +='<hr align="left" width="80%" noshade>';
            }
            while (weightA.length >= 1)
              {
                    var max = 0;
                    for (i=0;i<weightA.length;i++)
                      {
                        if (weightA.max() == weightA[i])
                          max = i;
                      }

                    res += "<li style='cursor:pointer; font: normal Arial; ' onclick='parent.frames[0].selectIndex(\""+divA[max]+"\")'>"+stripDotHtml(divA[max])+" </li>";

                    weightA = delFromArrayI(weightA,max)
                    divA = delFromArrayI(divA,max)
              }
            res += '</ul>';
            $("#searchResult",parent.treeFrame.document).html(res)
      }


    function parsediv(area,res,parsed,plain)
      {
        $("div",area).each(function()
          {
            if ($(this).attr("chapter") == 'True' && (jQuery.inArray($(this).attr("code"), parsed) == -1))
              {
                res += "<li><span class='folder' onclick='parent.frames[0].selectIndex(\""+$(this).attr("name")+"\")' style='cursor:pointer' id='span"+$(this).attr("code")+"'>"+$(this).attr("index")+"</span><ul>";
                res = parsediv(this,res,parsed,plain);
                res += "</ul></li>\n";
              }
            else
              {
                if (jQuery.inArray($(this).attr("code"), parsed) == -1)
                  {
                    res += "<li><span class='file' onclick='parent.frames[0].selectIndex(\""+$(this).attr("name")+"\")' class='div'  style='cursor:pointer'  id='span"+$(this).attr("code")+"'>"+$(this).attr("index")+"</span></li>";
                    parsed[parsed.length] = $(this).attr("code");
                  }
              }
          })
        return res;
      }

    function plain(forse)
      {
        if (checkCookies() == 0)
          parent.document.location.replace("no.html");
        if (getCookie("name")) return

        var res = '<h2>';
        res += sTxIndex;
        res += '</h2>';
        res += '<ul  style="font-size: 110%;list-style-type:none;" id="plain">';
        var parsed = new Array()
        $("div[root=True]",parent.treeSrc.document).each(function() {
           res += "<li class='closed expandable'><span class='folder' style='cursor:pointer' id='span"+$(this).attr("code")+"'><span onclick='parent.top.selectIndex(\""+$(this).attr("name")+"\")'>"+$(this).attr("index")+"</span></span><ul>";
           res = parsediv(this,res,parsed,1);
           res += "</ul>\n";
        })
        res += "</ul>"
        parent.treeFrame.document.body.innerHTML = res;
        $("#plain ul",parent.treeFrame.document).attr("style","list-style-type:none;font-size: 110%;");
        $("#browser span.div span",parent.treeFrame.document).attr("style","cursor:pointer");
      }

    function showHistory(forse)
      {
        var histName = new Array();
        var histProf = new Array();
        var histGrup = new Array();
        var histKurs = new Array();
        var histTime = new Array();
        var histMark = new Array();
        var histRes = new Array();
        
        if (getCookie("histName") != null)          histName = getCookie("histName").split("|")
        if (getCookie("histProf") != null)          histProf = getCookie("histProf").split("|")
        if (getCookie("histGrup") != null)          histGrup = getCookie("histGrup").split("|")
        if (getCookie("histKurs") != null)          histKurs = getCookie("histKurs").split("|")
        if (getCookie("histMark") != null)          histMark = getCookie("histMark").split("|")
        if (getCookie("histTime") != null)          histTime = getCookie("histTime").split("|")
        if (getCookie("histRes") != null)          histRes = getCookie("histRes").split("|")

		var sHistory = '';
        for(i=0; i < histName.length; i++)
          {
			sHistory += '<tr>'
          	sHistory += '<td class="date" width="74">' + histTime[i] + '</td>'
			sHistory += '<td class="user" width="278">' + histName[i] + '</td>'
			sHistory += '<td class="info" width="74">' + histGrup[i] + '</td>'
			sHistory += '<td class="info1" width="88">' + histProf[i] + '</td>'
			sHistory += '<td class="info2" width="137">' + histKurs[i] + '</td>'
			sHistory += '<td class="info3" width="129">' + histRes[i] + '</td>'
			sHistory += '<td class="info4" width="88">' + histMark[i] + '</td>'
			sHistory += '</tr>'
          }
          
        res = top.history_file_top + sHistory + top.history_file_bottom;
        if (forse == 1){
	        parent.mainFrame.document.body.innerHTML = res;
	    } else {
			return res;
		}
      }

    function clearHist()
      {
        if (!confirm(sTxClearQuizInfo)) return
        delCookie("histName")
        delCookie("histProf")
        delCookie("histGrup")
        delCookie("histKurs")
        delCookie("histMark")
        delCookie("histTime")
        delCookie("histRes")
        alert(sTxQuizInfoClear)
        nextIndex('1');
        reloadtree();
      }
    function toHistory(mark,percent)
      {
        var histName = new Array();
        var histProf = new Array();
        var histGrup = new Array();
        var histKurs = new Array();
        var histMark = new Array();
        var histRes = new Array();
        var histTime = new Array();
        
        if (getCookie("histName") != null)          histName = getCookie("histName").split("|")
        if (getCookie("histProf") != null)          histProf = getCookie("histProf").split("|")
        if (getCookie("histGrup") != null)          histGrup = getCookie("histGrup").split("|")
        if (getCookie("histKurs") != null)          histKurs = getCookie("histKurs").split("|")
        if (getCookie("histMark") != null)          histMark = getCookie("histMark").split("|")
        if (getCookie("histTime") != null)          histTime = getCookie("histTime").split("|")
        if (getCookie("histRes") != null)          histTime = getCookie("histRes").split("|")

        histName[histName.length] = getCookie("name");
        histProf[histProf.length] = getCookie("prof");
        histGrup[histGrup.length] = getCookie("grup");
        histKurs[histKurs.length] = getCookie("kurs");
        histMark[histMark.length] = mark;
        histTime[histTime.length] = getTimeDate();
        histRes[histRes.length] = percent + '%';
        
        setCookie("histName",histName.join("|"));
        setCookie("histProf",histProf.join("|"));
        setCookie("histGrup",histGrup.join("|"));
        setCookie("histKurs",histKurs.join("|"));
        setCookie("histMark",histMark.join("|"));
        setCookie("histTime",histTime.join("|"));
        setCookie("histRes",histRes.join("|"));
      }

    function reloadtree(){
      if (checkCookies() == 0)
        parent.document.location.replace("no.html");
      if (getCookie("name"))
          {
            alert(sTxNoDataAccess)
            return
          }
      
      if(getNameBrouser() == "msie"){
			parent.treeFrame.document.location.reload();
        } else {
			index();
		}
    }

    function index(forse){
		if (getCookie("name") != null)
             {
               selectQuiz(getCookie("current"))
               startQuiz(0)
             }
      if (checkCookies() == 0)
        parent.document.location.replace("no.html");
      if (getCookie("name")) return;
      
      var res = '<h2>' + sTxMainIndex + '</h2><hr align="left" width="70%" noshade><ul  style="font-size: 110%;" class="filetree" id="browser">';
      var parsed = new Array();
      $("div[root=True]",treeSrc).each(function() {
         res += "<li><span class='folder' id='span"+$(this).attr("code")+"' onclick='parent.frames[0].selectIndex(\""+$(this).attr("name")+"\")'>"+$(this).attr("index")+"</span><ul>";
         res = parsediv(this,res,parsed,0);
         res += "</ul>\n";
      })
      res += "</ul>"
      $("body", treeFrame).html(res)
      $("#browser", treeFrame).treeview({animated: "fast", control:"#sidetreecontrol", persist: "location"});
      $("#browser span.div span",treeFrame).attr("style","cursor:pointer");
      if(top.activePage){
		selectIndex(top.activePage);
		}
    }

  function getTimeDate()
  {
    current_date =  new Date();
    return current_date.getDate() + "." + current_date.getMonth() + "." + current_date.getFullYear() + ' '+current_date.getHours() + "." + current_date.getMinutes() + "." + current_date.getSeconds()
  }

   function finishQuiz()
      {
        var total = 0;
        var correct = 0;
        var incorrect = 0;

		top.hideFrame();
        $("span",parent.quizSrc.document).each(function() {
          total++;
          var question = $(this).attr("file");
          $("div",this).each(function() {
            if ($(this).attr("right") == 'TRUE')
              if (getCookie(question) == $(this).attr("file"))
                correct++;
              else
                incorrect++
            delCookie(question)
          })
        })
        
        var percent = (correct/total)*100;
        var sRes = ' ';
        var mark = ' '
        var name = getCookie("name");
        if(!name){
         name = sTxDefault;
        }
        var mark2 = sTxMrk;
        var mark3 = sTxMrk1
        var mark4 = sTxMrk2
        var mark5 = sTxMrk3

        var percent5 = getSettings("NpQuizAnswExlnt");
        var percent4 = getSettings("NpQuizAnswGood");
        var percent3 = getSettings("NpQuizAnswNorm");

        if (percent < percent3)
          mark = mark2;
        if (percent >= percent3 && percent < percent4)
          mark = mark3;
        if (percent >= percent4 && percent < percent5)
          mark = mark4;
        if (percent > percent5)
          mark = mark5;

        toHistory(mark, percent)

        delCookie("name")
        delCookie("prof")
        delCookie("kurs")
        delCookie("grup")

        delCookie("current")
        delCookie("loading")
        
        sRes = top.res_file_top + name + top.res_file_data1 + total + top.res_file_data2 + correct + top.res_file_data3 + mark + top.res_file_bottom;
        
        parent.mainFrame.document.body.innerHTML = sRes;
      }
      
    function startQuiz(start)
      {
	 //if (getSettings("NpQuizOn") == true || start == 0)
        if (true)
          {
            top.hideFrame();
            if (start)
              {
                if (getSettings("NpQuizUserChek") == true)
                  {
                    var name = "default"
                    var kurs = "default"
                    var prof = "default"
                    var grup = "default"
                  }
                else
                  {
                    var name = $("#name",parent.mainFrame.document).val();
                    var kurs = $("#kurs",parent.mainFrame.document).val();
                    var prof = $("#prof",parent.mainFrame.document).val();
                    var grup = $("#grup",parent.mainFrame.document).val();
                    if (!name)
					name = sTxDefault;
                    
                    if (!kurs)
                    kurs = sTxDefault;
                    
                    if (!prof)
                    prof = sTxDefault;
                    
                    if (!grup)
                    grup = sTxDefault;
                  }
              }
            if (name && kurs && prof && grup)
              {
                delCookie("loading")
                setCookie("name",name)
                setCookie("kurs",kurs)
                setCookie("prof",prof)
                setCookie("grup",grup)
                nextQuiz()
              }
            if (getCookie("name"))
              {
               var res = '<h2>' +  sTxQuizInfo + '</h2><hr align="left" width="70%" noshade>';
                var list = new Array()
                var parsed = new Array()
                $("span",parent.quizSrc.document).each(function()
                  {
                    var classs = '';
                    if (getCookie("current") == $(this).attr("file"))
                      classs = 'color:#0000CC';
                    else
                      {
                        if (getCookie($(this).attr("file")) != null)
                          {
                          classs = 'color:#CC0000';
                          }
                      }
                    list[list.length] = "<li class='file' style='cursor:pointer;margin:3px 0 0 0;"+classs+"'><span style='font:normal 12px Arial,Helvetica,sans-serif;'  onclick='parent.frames[0].selectQuiz(\""+$(this).attr("file")+"\")'>"+$(this).attr("name")+"</span></li>";
                  })
                while (list.length >= 1)
                  {
                    if (getSettings("NpQuizAnswRandom") == 'true' || getSettings("NpQuizAnswRandom") == '1')
                      var ran = randomNumber(0,list.length-1)
                    else
                      ran = 0;
                    res += list[ran];
                    list = delFromArrayI(list,ran)
                  }
                  
                res += '<hr align="left" width="70%" noshade>';
	            res += "<li class='file' style='margin:3px 0 0 0;cursor:pointer'>"
                res += "<span style='color:#FF0000; font:normal 12px Arial,Helvetica,sans-serif;'  "
                res += "onclick='if (!confirm(\""
                res += sTxQuizEndTestExt;
                res += "\")) return;parent.frames[0].finishQuiz()' style='cursor:pointer'>"
                res += sTxQuizEndTest;
                res += "</span>"
                res += "</li>";
                res += "</ul>"
                $("body",treeFrame).html(res)
                top.showFrame();
              }
              else
              {
                parent.mainFrame.document.location.replace("auth.html");
              }
      }
    else
      {
        alert(sTxNoQuiz)
      }
  }

  function randomNumber (m,n)
    {
      m = parseInt(m);
      n = parseInt(n);
      return Math.floor( Math.random() * (n - m + 1) ) + m;
    }  
