var BG=null;
var NV=null;

// GET COOKIE
function getCookie(Name) {
  var search=Name+"=";
  if(document.cookie.length > 0) {
    offset=document.cookie.indexOf(search);
    if(offset!=-1){
      offset+=search.length;
      end=document.cookie.indexOf(";",offset);
      if(end==-1) end=document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    }
  }
  return null;
}

//Initialise pages
function init(){
  loaded=true
  //if(loading) loading.close();

  //get Background Cookie
  BG=getCookie("BG");
  if(!BG) BG=1;
  document.body.background="../backgrounds/"+BG+".gif";

  if(document.images("deviceL")) {
    //get Navigator Cookie
    NV=getCookie("NV");
    if(!NV) NV="1";
    if(parseInt(NV)<10) NV="0"+NV;
    
    document.images("deviceL").src="../navigator/"+NV+"/l.gif";
    document.images("deviceT").src="../navigator/"+NV+"/t.gif";
    document.images("deviceR").src="../navigator/"+NV+"/r.gif";
    document.images("deviceB").src="../navigator/"+NV+"/b.gif";
  }
}

function popPara(num){
  popwin=window.open("/popParagraph.jsp?P="+num,"popwin","width=400,height=300,scrollbars")
}

var BG=null;
var NV=null;

// GET COOKIE
function getCookie(Name) {
  var search=Name+"=";
  if(document.cookie.length > 0) {
    offset=document.cookie.indexOf(search);
    if(offset!=-1){
      offset+=search.length;
      end=document.cookie.indexOf(";",offset);
      if(end==-1) end=document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    }
  }
  return null;
}

//Initialise pages
function init(){
  loaded=true
  //if(loading) loading.close();

  //get Background Cookie
  BG=getCookie("BG");
  if(!BG) BG=1;
  document.body.background="../backgrounds/"+BG+".gif";

  if(document.images("deviceL")) {
    //get Navigator Cookie
    NV=getCookie("NV");
    if(!NV) NV="1";
    if(parseInt(NV)<10) NV="0"+NV;
    
    document.images("deviceL").src="../navigator/"+NV+"/l.gif";
    document.images("deviceT").src="../navigator/"+NV+"/t.gif";
    document.images("deviceR").src="../navigator/"+NV+"/r.gif";
    document.images("deviceB").src="../navigator/"+NV+"/b.gif";
  }
}

function popPara(num){
  popwin=window.open("/popParagraph.jsp?P="+num,"popwin","width=400,height=300,scrollbars")
}


function replace(s,one,another){
  if (s=="") return "";
  res = "";
  i = s.indexOf(one,0);
  lastpos = 0;
  while (i != -1) {
    res += s.substring(lastpos,i) + another;
    lastpos = i + one.length;
    i = s.indexOf(one,lastpos);
  }
  res += s.substring(lastpos);
  return res;  
}
