var myemail = 'arcadynovosyolov@gmail.com';

// Scirus search engine code =================================
// call setSearchValue() from a link
var srch = new Array(
  'risk'
  ,'uncertainty'
  ,'decision making'
  ,'preference relation'
  ,'risk measure'
  ,'risk attitude'
  ,'risk aversion'
  ,'risk seeking'
  ,'risk neutral'
  ,'risk premium'
  ,'risk price'
  ,'expected utility'
  ,'distorted probability'
  ,'insurance'
  ,'portfolio selection'
  ,'portfolio optimization'
  ,'arbitrage opportunity'
  ,'fundamental theorem of asset pricing'
  ,'capital asset pricing model'
  ,'Markowitz problem'
  ,'Sharpe ratio'
);

function randEl(ar) {
  var nu = Math.round(ar.length*Math.random()-0.5);
  if (nu < 0) nu = 0;
  if (nu >= ar.length) nu = ar.length - 1;
  return ar[nu];
}

function setSearchValue() {
  if (document.all) {
    document.all.query.value = randEl(srch);
//    document.all.query.focus();
  }
}
// end of Scirus search engine code ======================

function RTcorrect() {
  var srchStr = 'www.';
  var le = srchStr.length;
  var s = document.location.href;
  s = s.toLowerCase();
  var ind = s.indexOf(srchStr);
  if (ind >= 0) {
    var ss = s.substring(0,ind)+s.substr(ind+le,s.length-le);
    document.location = ss;
  }
}

function geocorrect() {
  var srchStr = 'capecanaveral/launchpad/6016';
  var le = srchStr.length;
  var s = document.location.href;
  s = s.toLowerCase();
  var ind = s.indexOf(srchStr);
  if (ind >= 0) {
    var ss = s.substring(0,ind)+'novosyolov'+s.substr(ind+le,s.length-le);
    document.location = ss;
  }
}

RTcorrect();

names = new Array(
	new Array("whats.htm","Introduction","Introduction to risk theory")
	,new Array("lectures.htm","Lectures","Lectures in risk theory")
	,new Array("download.htm","Download","Downloadable materials")
	,new Array("publ.htm","Papers","Recent publications")
	,new Array("illustr.htm","Illustrations","Illustrations")
	,new Array("distr/handbook.htm","Distributions","Handbook of distributions")
	,new Array("glossary.htm","Glossary","Glossary of terms")
	,new Array("blackbrd.htm","Blackboard","News and announcements")
	,new Array("links.htm","Links","Useful links")
	,new Array("music.htm","Music","Some pieces and arrangements")
	,new Array("contact.htm","Contact","Contact information")
	,new Array("index.html","Home","Risk theory")
);

otherNames = new Array(
	new Array("riskdef.htm","Risk definition","Risk definition")
	,new Array("newpage.htm","More","More")
);

distrNames = new Array(
	new Array("params.htm","Distribution parameters","Distribution parameters")
	,new Array("uniform.htm","Uniform distribution","Uniform distribution")
	,new Array("normal.htm","Normal distribution","Normal distribution")
	,new Array("lognorm.htm","Lognormal distribution","Lognormal distribution")
	,new Array("expon.htm","Exponential distribution","Exponential distribution")
	,new Array("gamma.htm","Gamma distribution","Gamma distribution")
	,new Array("cauchy.htm","Cauchy distribution","Cauchy distribution")
	,new Array("degen.htm","Degenerate distribution","Degenerate distribution")
	,new Array("bern.htm","Bernoulli distribution","Bernoulli distribution")
	,new Array("binom.htm","Binomial distribution","Binomial distribution")
	,new Array("poisson.htm","Poisson distribution","Poisson distribution")
	,new Array("toappear.htm","To appear","To appear")
	,new Array("newpage.htm","More","More")
);

function header() {
  for (var i=0; i<names.length; i++) {
    if (document.location.href.indexOf(names[i][0]) >= 0) {
      return names[i][2];
    }
  }
  for (var i=0; i<otherNames.length; i++) {
    if (document.location.href.indexOf(otherNames[i][0]) >= 0) {
      return otherNames[i][2];
    }
  }
  for (var i=0; i<distrNames.length; i++) {
    if (document.location.href.indexOf(distrNames[i][0]) >= 0) {
      return distrNames[i][2];
    }
  }
  return 'Home';
}

function goHome(level) {
  var s = '';
  for (var i=0; i<level; i++) {
    s += '../';
  }
  var w = window.open(s+'index.html',rtWinName,'');
  w.focus();
}

function popBotMenu(level) {
  if (window == parent) {
    var s = '<a href="#" onClick="javascript:goHome('+level+');"> Home</a>';
    document.write(s);
    s = '<a href="#" onClick="javascript:window.close();"> Close this window</a>';
    document.write(' | '+s);
  }
}

function botMenu() {
  var n = names.length;
  var s = ' | ';
  for (var i=0; i<n; i++) {
    s += '<a href="'+names[i][0]+'"> '+names[i][1]+'</a> | ';
    if (i == 5) { s += '<br>|';}
  }
  document.write(s);
}

rtWinName = 'risktheory';
distrWinName = 'distr';
paramsWinName = 'params';

function opParamsWindow(wh) {
  var s = 'distr/params.htm#'+wh;
  var w = window.open(s,paramsWinName,'width=530,height=550,scrollbars=yes');
  w.focus();
}

function opDistrWindow(wh) {
  var s = 'distr/'+wh+'.htm';
  var w = window.open(s,distrWinName,'width=530,height=550,scrollbars=yes');
  w.focus();
}

function writeMiscHeader() {
  document.write('<title> Risk theory: ');
  document.write(header());
  document.write('</title>');
}

function writeHeader() {
  window.name = rtWinName;
  writeMiscHeader();
}

function writeDistrHeader() {
//  window.name = distrWinName;
  writeMiscHeader();
}

lobgCol = "#336699";
hibgCol = "#2222ff";
lmLinkColor = "#00ffff";
lmJustColor = "#ffff00";

// left menu block ======================
function ColorHigh(ob) {
	ob.bgColor=hibgCol;
}
function ColorLow(ob) {
	ob.bgColor=lobgCol;
}

function leftMenuItem(i) {
  var s = document.location.href;
  var ll = s.length;
  var ss = s.substring(ll-1,ll);
  var whn = s.indexOf(names[i][0]);
  if ((names[i][0] == 'index.html') && (ss == '/')) {
    whn = 0;
  }
  var s = '<tr><td bgcolor='+lobgCol+' onmouseover="javascript:ColorHigh(this);"';
  s += ' onmouseout="javascript:ColorLow(this);">';
  s += '<img src="images/bull.gif" width=12 height=12>';
  var lm = (whn < 0) ? lmLinkColor : lmJustColor;
  if (whn < 0) {
    s += '<a href="'+names[i][0]+'" title="'+names[i][2]+'">';
  }
  s += '<font color="'+lm+'"> '
  s += '<b>'+names[i][1]+'</b></font>';
  if (whn < 0) {
    s += '</a>';
  }
  s += '</td></tr>';
  return s;
}

function leftMenu() {
  document.write('<table cellpadding=4 width=130 border=0>');
  for (var i=0; i<names.length; i++) {
    document.write(leftMenuItem(i));
  }
  document.write('</table>');
}

function lastModStr(lastMod){
  if (document.all) {
    var m = lastMod.substring(0,2)
    var d = lastMod.substring(3,5)
    return m+"/"+d+"/"+lastMod.substring(6,10)
  } else {
    return lastMod
  }
}

function copyModTable() {
  document.write('<table bgcolor="'+lobgCol+'" width="100%"><tr>');
  document.write('<td align="left">');
  document.write('<font face = "Times" size = "-1" color = "white">');
  document.write('Copyright &copy 1998-2009, ');
  document.write('<a href="mailto:'+myemail+'" title="Send e-mail to the author"> ');
  document.write('<font color = "white">');
  document.write('A.Novosyolov');
  document.write('</font></a>');
  document.write('</font></td>');

  document.write('<td align="right">');
  document.write('<font face = "Times" size="-1" color = "white">');
  document.write('Last updated: ');
  document.write(lastModStr(document.lastModified))
  document.write('</font></td>');

  document.write('</tr></table>');
}

