function rn(rni1,rni2) {
  rni2++;
  var trnitemp = parseInt(Math.random()*(rni2-rni1)+rni1);
  return trnitemp;
}

function al(a,extra) {
  temp = "";
  aln = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+extra;
  for (b=0;b<a.length;b++) {
    temp2 = a.charAt(b);
    if (aln.indexOf(temp2) != -1) {
      temp += temp2;
    }
  }
  return temp;
}

function sn(innum,chr) {
  if (isNaN(innum)) return innum;
  uc = ",";
  if (chr) uc = String(chr).substring(0,1);
  var i = 0;
  var b = "";
  var c = String(innum);
  var temp = 0;
  start = ((c.length)-1);
  if (c.indexOf(".") != -1) {
    start = (c.indexOf(".")-1);
    b = c.substring(c.indexOf("."),c.length);
  }
  for (i=start;i>=0;i--) {
    temp2 = c.charAt(i)+b;
    temp++;
    if (temp >= 3) {
      temp = 0;
      if (i <= 0) b = temp2;
      else b = uc+temp2;
    }
    else b = temp2;
  }
  return b;
}

function limitto(a,b) {
  var ab = a.value;
  if (ab.length > b) {
    a.value = ab.substring(0,b);
  }
}

function expand_list(a) {
  v = document.getElementById(a);
  if (v) {
    b = false;
    if (v.style.display == "none") b = true;
    if (b) {
      v.style.display = "inline";
    }
    else {
      v.style.display = "none";
    }
  }
}

function updown(a,off,def,min,max,cls) {
  if (off != 0) {
    v = document.getElementById(a+'o');
    c = Number(v.value);
    if (isNaN(c)) return;
    if ((c+off) <= max && (c+off) >= min && (classes[cls][7]+off) <= classes[cls][5]) {
      c = (c+off);
      v.value = c;
      classes[cls][7] = (classes[cls][7]+off);
      if (cls != "S") {
        classes["S"][7] = (classes["S"][7]+off);
      }
      else {
        cnt = 0;
        for (i in classes) {
          if (i != "S" && cnt != off && ((off > 0 && (classes[i][5]-off) >= classes[i][7]) || (off < 0 && (classes[i][5]-off) <= classes[i][3]))) {
            cnt = off;
            classes[i][5] = (classes[i][5]-off);
          }
        }
      }
    }
  }
  if (def != 0) {
    v = document.getElementById(a+'d');
    c = Number(v.value);
    if (isNaN(c)) return;
    if ((c+def) <= max && (c+def) >= min && (classes[cls][8]+def) <= classes[cls][6]) {
      c = (c+def);
      v.value = c;
      classes[cls][8] = (classes[cls][8]+def);
      if (cls != "S") {
        classes["S"][8] = (classes["S"][8]+def);
      }
      else {
        cnt = 0;
        for (i in classes) {
          if (i != "S" && cnt != def && ((def > 0 && (classes[i][6]-def) >= classes[i][8]) || (def < 0 && (classes[i][6]-def) <= classes[i][4]))) {
            cnt = def;
            classes[i][6] = (classes[i][6]-def);
          }
        }
      }
    }
  }

  for (i in classes) {
    temp = (classes[i][5]-classes[i][7]);
    temp2 = (classes[i][6]-classes[i][8]);
    document.getElementById('_'+i+'_off').innerHTML = temp;
    document.getElementById('_'+i+'_def').innerHTML = temp2;
  }
}

function submit_change(a,b) {
  notfine = new Array();
  notname = new Array();
  for (i in classes) {
    if (i != "S" && (classes[i][5] != classes[i][7] || classes[i][6] != classes[i][8])) notfine[notfine.length] = classes[i][0];
  }
  for (i in unit_maxes) {
    v = document.getElementById('name'+i);
    uv = (unit_maxes[i][5] == "" || unit_maxes[i][4] == "") ? "": " ";
    uu = (unit_maxes[i][4] == "") ? "": " Unit";
    if (String(v.value) == "") notname[notname.length] = unit_maxes[i][4]+uv+unit_maxes[i][5]+uu;
  }

  if (notfine.length != 0) {
    result = "You must use up all of the Offense and Defense points.\n\nProblem areas:\n\n";
    for (i in notfine) {
      result += " - "+notfine[i]+" Units\n";
    }
    alert(result);
    return false;
  }
  else if (notname.length != 0) {
    result = "You have not specified a Name for some Units.\n\nProblem areas:\n\n";
    for (i in notname) {
      result += " - "+notname[i]+"\n";
    }
    alert(result);
    return false;
  }
  else {
    return confirm("Are you sure you want to update your military?\n\nYou will not be able to update them again for another "+b+", so make sure they are as you intend.");
  }
}

function dosub(a) {
  if (a.ald) return false;
  else {
    for (b=0;b<document.forms.length;b++) {
      document.forms[b].ald = true;
    }
    return a.ald;
  }
}

function picktheme(a) {
  if (a == "" || typeof(themes[a]) == "undefined") return;
  for (i in themes[a]) {
    v = document.getElementById('name'+i);
    if (v) v.value = themes[a][i];
  }
}

function openccwindow(a) {
  v = window.open('http://www.fantasiankingdoms.com/game/nationalcontrol.php?action=pick_color&tid='+a,'_choosecolor','width=520,height=150,left='+Math.floor((screen.availWidth/2)-260)+',top='+Math.floor((screen.availHeight/2)-75)+',screenX='+Math.floor((screen.availWidth/2)-260)+',screenY='+Math.floor((screen.availHeight/2)-75)+'');
  v.focus();
}

function openffwindow(a) {
  v = window.open('http://www.fantasiankingdoms.com/game/nationalcontrol.php?action=pick_flag&tid='+a,'_chooseflag','width=150,height=150,left='+Math.floor((screen.availWidth/2)-75)+',top='+Math.floor((screen.availHeight/2)-75)+',screenX='+Math.floor((screen.availWidth/2)-75)+',screenY='+Math.floor((screen.availHeight/2)-75)+'');
  v.focus();
}

function colorcut(a,c,d) {
  b = a.value;
  var res = a.value;
  res = res.toUpperCase();
  b = b.toLowerCase();
  if (b.charAt(0) != "#") b = "#"+b;
  var accept = "abcdef0123456789";
  var redone = "#";
  for (i=1;i<b.length;i++) {
    if (accept.indexOf(b.charAt(i)) != -1) {
      redone += b.charAt(i);
    }
  }
  b = redone.toUpperCase();
  if (b.length > 7) {
    b = b.substring(0,7);
  }
  if (res != b) a.value = b;
  while (b.length < 7) {
    b += "0";
  }
  document.getElementById(c).style.background = b;
  document.getElementById(d).style.color = b;
}

function fillin(a,c,d) {
  b = a.value;
  while (b.length < 7) {
    b += "0";
  }
  a.value = b.toUpperCase();
  if (c) document.getElementById(c).style.background = b;
  if (d) document.getElementById(d).style.color = b;
}

function numcut(a) {
  b = a.value;
  if (b.indexOf(".") == -1) {
    b = b+".0";
  }
  num = b.substring(0,b.indexOf("."));
  flat = b.substring((b.indexOf(".")+1),b.length);
  var accept = "0123456789";
  var redone = "";
  var redone2 = "";
  for (i=0;i<num.length;i++) {
    if (accept.indexOf(num.charAt(i)) != -1) {
      redone += num.charAt(i);
    }
  }
  for (i=0;i<flat.length;i++) {
    if (accept.indexOf(flat.charAt(i)) != -1) {
      redone2 += flat.charAt(i);
    }
  }
  num = redone;
  flat = redone2;
  if (num == "") num = 0;
  if (flat == "") flat = 0;
  num = Math.floor(Math.abs(Number(num)));
  flat = Math.floor(Math.abs(Number(flat)));
  if (flat > 9) {
    temp = Math.floor(flat/10);
    num = (num+temp);
    flat = (flat-(temp*10));
  }
  if (num > 10) num = 10;
  if (num == 10) flat = 0;
  a.value = num+"."+flat;
}


function snumcut(a,min,max) {
  b = a.value;
  var accept = "-0123456789";
  var redone = "";
  for (i=0;i<b.length;i++) {
    if (accept.indexOf(b.charAt(i)) != -1) {
      redone += b.charAt(i);
    }
  }
  b = redone;
  if (b == "" || isNaN(b)) {
    b = min;
    if (min <= 0 && max >= 0) b = 0;
  }
  b = Number(b);
  if (b > max) b = max;
  if (b < min) b = min;
  a.value = b;
}

function check_all(a) {
  v = document.getElementsByTagName('input');
  for (i in v) {
    if (v[i] && v[i].type == "checkbox") {
      v[i].checked = a;
    }
  }
}

function popup_help(a) {
  v = window.open('http://www.fantasiankingdoms.com/gamemanual/'+a,'_popuphelp','width=630,height=410,top='+Math.floor((screen.availHeight/2)-205)+',left='+Math.floor((screen.availWidth/2)-315)+',screenX='+Math.floor((screen.availHeight/2)-205)+',screenY='+Math.floor((screen.availWidth/2)-315)+',scrollbars=yes,resizable=yes');
  v.focus();
}

function popup_calc(det) {
  ex = (det) ? det: "";
  v = window.open('http://www.fantasiankingdoms.com/game/attack.php?calc'+ex,'_popupcalc','width=540,height=560,top='+Math.floor((screen.availHeight/2)-260)+',left='+Math.floor((screen.availWidth/2)-270)+',screenX='+Math.floor((screen.availHeight/2)-260)+',screenY='+Math.floor((screen.availWidth/2)-270)+',scrollbars=yes,resizable=yes');
  v.focus();
}

function getprop(dname,ieprop,prop) {
  __vv = document.getElementById(dname);
  if (__vv.currentStyle) return __vv.currentStyle[ieprop];
  else if (window.getComputedStyle) {
    __gg = window.getComputedStyle(__vv,"");
    return __gg.getPropertyValue(prop);
  }
}

vldd = "";

function shownameops(a,w,id,onoff) {
  clearTimeout(vldd);
  bldy = document.getElementsByTagName('body').item(0);
  v = document.getElementById('ppd');
  if (v) bldy.removeChild(v);
  if (a != '') {
    a.style.position = "relative";
    if (a.id == "") a.id = "aaa"+Math.floor(Math.random()*1000000);
    aid = a.id;
    ns = document.createElement('div');
    ns.id = "ppd";
    ns.className = "popup2";
    ns.onmouseover = new Function("keeponops();");
    ns.onmouseout = new Function("killnameops('"+aid+"');");
    ns.onclick = new Function("killnameops('"+aid+"');");
    ns.style.zIndex = 1000;
    ns.style.position = "absolute";
    a.onmouseout = new Function("killnameops('"+aid+"');");
    ns.style.left = (a.offsetLeft-2);
    ns.style.top = (a.offsetTop-2);
    res =	'<div class="popup2i"><a href="http://www.fantasiankingdoms.com/game/viewprovinces.php?action=view_exact&preset='+id+'"><span title="'+a.title+'" class="hpn" style="font-size:'+getprop(aid,"fontSize","font-size")+';font-weight:'+getprop(aid,"fontWeight","font-weight")+';border-width:0 0 1px 0;border-style:solid;border-color:#FF0000;">'+String(a.innerHTML)+'</span></a><br>\n'+
		'<img src="http://www.fantasiankingdoms.com/images/spacer.gif" width=1 height=3 alt=""><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/messages.php?preset='+id+'">Send&nbsp;Message</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/showmap.php?o='+id+'">View&nbsp;on&nbsp;World&nbsp;Map</a><br>\n';
    if (id != 0) {
      res +=	'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/attack.php?preset='+id+'">Attack</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/spyops.php?preset='+id+'">Spy&nbsp;Operations</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/missiles.php?preset='+id+'">Launch&nbsp;Missile</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/aid.php?preset='+id+'">Send&nbsp;Aid</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/encampments.php?preset='+id+'">Send&nbsp;Encampment</a><br>\n';
    }
    res +=	'&nbsp;-&#155;&nbsp;<a class="b" target="_newRIprofile" href="http://richinnovations.net/profile.php?profile='+id+'&remote=">View&nbsp;RI&nbsp;Profile</a><br>\n'+
		'&nbsp;&nbsp;&nbsp;&nbsp;('+w+')\n</div>';
    ns.innerHTML = res;
  }
  if (onoff) void(bldy.appendChild(ns));
}


function showfake(a,w,onoff) {
  clearTimeout(vldd);
  bldy = document.getElementsByTagName('body').item(0);
  v = document.getElementById('ppd');
  if (v) bldy.removeChild(v);
  if (a != '') {
    a.style.position = "relative";
    if (a.id == "") a.id = "aaa"+Math.floor(Math.random()*1000000);
    aid = a.id;
    ns = document.createElement('div');
    ns.id = "ppd";
    ns.className = "popup2";
    ns.onmouseover = new Function("keeponops();");
    ns.onmouseout = new Function("killnameops('"+aid+"');");
    ns.onclick = new Function("killnameops('"+aid+"');");
    ns.style.zIndex = 1000;
    ns.style.position = "absolute";
    a.onmouseout = new Function("killnameops('"+aid+"');");
    ns.style.left = (a.offsetLeft);
    ns.style.top = (a.offsetTop);
    res =	'<div class="popup2i"><span class="hpn" style="font-size:'+getprop(aid,"fontSize","font-size")+';font-weight:'+getprop(aid,"fontWeight","font-weight")+';border-width:0 0 1px 0;border-style:solid;border-color:#FF0000;">'+String(a.innerHTML)+'</span><br>\n'+
		'<img src="http://www.fantasiankingdoms.com/images/spacer.gif" width=1 height=3 alt=""><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="#" onclick="alert(\'>.o\\n\\nOw..\');return false;">Poke&nbsp;with&nbsp;Stick</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="#" onclick="alert(\'...\');return false;">Stare&nbsp;Blankly&nbsp;At</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="#" onclick="alert(\':-(\');return false;">Laugh&nbsp;At</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="#" onclick="alert(\':-O\\n\\nMeanie head!\');return false;">Kill</a><br>\n</div>';
    ns.innerHTML = res;
  }
  if (onoff) void(bldy.appendChild(ns));
}


function shownationops(a,w,id) {
  clearTimeout(vldd);
  bldy = document.getElementsByTagName('body').item(0);
  v = document.getElementById('ppd');
  if (v) bldy.removeChild(v);
  if (a != '') {
    if (a.id == "") a.id = "aaa"+Math.floor(Math.random()*1000000);
    aid = a.id;
    ns = document.createElement('div');
    ns.id = "ppd";
    ns.className = "popup2";
    ns.onmouseover = new Function("keeponops();");
    ns.onmouseout = new Function("killnameops('"+aid+"');");
    ns.onclick = new Function("killnameops('"+aid+"');");
    ns.style.zIndex = 1000;
    ns.style.position = "absolute";
    a.onmouseout = new Function("killnameops('"+aid+"');");
    ns.style.left = (a.offsetLeft-2);
    ns.style.top = (a.offsetTop-2);
    res =	'<div class="popup2i"><a href="http://www.fantasiankingdoms.com/game/international.php?unation='+id+'"><span class="hpn" style="font-size:'+getprop(aid,"fontSize","font-size")+';font-weight:'+getprop(aid,"fontWeight","font-weight")+';border-width:0 0 1px 0;border-style:solid;border-color:#FF0000;">'+String(a.innerHTML)+'</span></a><br>\n'+
		'<img src="http://www.fantasiankingdoms.com/images/spacer.gif" width=1 height=3 alt=""><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/viewprovinces.php?action=view_nation&unation='+id+'">Show&nbsp;All&nbsp;Members</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/international.php?unation='+id+'">View&nbsp;Information</a><br>\n'+
		'&nbsp;-&#155;&nbsp;<a class="b" href="http://www.fantasiankingdoms.com/game/international.php?action=browse">Browse&nbsp;All&nbsp;Nations</a><br>\n';
    ns.innerHTML = res;
  }
  void(bldy.appendChild(ns));
}

function keeponops() {
  clearTimeout(vldd);
}

function killnameops(a) {
  vldd = setTimeout("shownameops('',0,0,false);",50);
}

function expandmarket(a) {
  v = document.getElementsByTagName('div');
  for (i in v) {
    if (v[i].id && String(v[i].id).indexOf('xmar'+a+'_') != -1) {
      cc = getprop(v[i].id,"display","display");
      if (cc == "block") {
        v[i].style.display = "inline";
        v[i].style.display = "none";
      }
      else {
        v[i].style.display = "inline";
        v[i].style.display = "block";
      }
    }
  }
}

function showdiv(txt,onoff,w) {
  dsoc_x = (document.all) ? (document.body.clientWidth-4): (window.innerWidth-24);
  bldy = document.getElementsByTagName('body').item(0);
  v = document.getElementById('ppd');
  if (v) bldy.removeChild(v);
  ns = document.createElement('div');
  ns.id = "ppd";
  ns.className = "popup";
  ns.onmouseover = new Function("showdiv('',false,0);");
  ns.style.zIndex = 1000;
  ns.style.position = "absolute";
  if (w != 0) {
    ns.style.width = w+"px";
  }
  gw = Math.floor(w/2);
  gw = (mx-gw);
  abs_x = (gw+w);
  if (abs_x > dsoc_x) gw = (gw-(abs_x-dsoc_x));
  if (gw < 0) gw = 0;
  ns.style.left = gw;
  ns.style.top = (my+20);
  ns.innerHTML = txt;
  if (onoff) void(bldy.appendChild(ns));
}

function showspyresults(results) {
  w = window.open('about:blank','_spyreswin','width=600,height=400,top='+Math.floor((screen.availHeight/2)-200)+',left='+Math.floor((screen.availWidth/2)-300)+',screenX='+Math.floor((screen.availHeight/2)-200)+',screenY='+Math.floor((screen.availWidth/2)-300)+',scrollbars=yes,resizable=yes');
  w.document.open();
  results = results.replace(/\&lt\;/gi,"<").replace(/\&gt\;/gi,">").replace(/\&quot\;/gi,"\"").replace(/\&#039\;/gi,"'").replace(/\&amp\;/gi,"&");
  results = results.replace(/<a[^<>]*>/gi,"");
  results = results.replace(/<([a-z]*) [^<>]*onmouse[^<>]*>/gi,"<$1>");

  w.document.write(
	'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n\n'+
	'<html>\n\n'+
	'<head>\n\n'+
	'<title>Fantasian Kingdoms - Spy Results</title>\n'+
	'<link rel="stylesheet" id="_xskin" type="text/css" href="http://www.fantasiankingdoms.com/skins/base.php">\n'+
	'<link rel="shortcut icon" href="http://www.fantasiankingdoms.com/favicon.ico">\n'+
	'<script src="http://www.fantasiankingdoms.com/js.php" type="text/javascript"></script>\n'+
	'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n'+
	'</head>\n\n'+
	'<body>\n'+
	'<center>\n'+
	'<table class="top" cellpadding=1 cellspacing=0>\n'+
	'<tr><td class="title" align=center>Mission Results</td></tr>\n'+
	'<tr><td class="blank4" align=center>\n'+
	'<br>\n'+
	results+
	'\n<br><br>\n'+
	'</td></tr>\n'+
	'</table>\n'+
	'<br><br><br>\n'+
	'</center>\n'+
	'</body>\n\n'+
	'</html>\n\n\n'
  );
  w.document.close();
  w.focus();
}

function opentextformat(frmt) {
  w = window.open('about:blank','_txtformat','width=600,height=400,top='+Math.floor((screen.availHeight/2)-200)+',left='+Math.floor((screen.availWidth/2)-300)+',screenX='+Math.floor((screen.availHeight/2)-200)+',screenY='+Math.floor((screen.availWidth/2)-300)+',scrollbars=yes,resizable=yes');
  w.document.open();
  frmt = String(frmt);
  frmt = frmt.replace(/\@/gi,'\n');

  w.document.write(
	'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n\n'+
	'<html>\n\n'+
	'<head>\n\n'+
	'<title>Fantasian Kingdoms - Text Format</title>\n'+
	'<link rel="stylesheet" id="_xskin" type="text/css" href="http://www.fantasiankingdoms.com/skins/base.php">\n'+
	'<link rel="shortcut icon" href="http://www.fantasiankingdoms.com/favicon.ico">\n'+
	'<script src="http://www.fantasiankingdoms.com/js.php" type="text/javascript"></script>\n'+
	'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n'+
	'</head>\n\n'+
	'<body>\n'+
	'<center>\n'+
	'<table class="top" cellpadding=1 cellspacing=0>\n'+
	'<tr><td class="title" align=center>Text Format</td></tr>\n'+
	'<tr><td class="blank4" align=center>\n'+
	'<textarea class="text" style="width:500px;height:300px;" onfocus="this.select();" readonly>'+
	frmt+
	'</textarea><br>\n'+
	'</td></tr>\n'+
	'</table>\n'+
	'<br><br><br>\n'+
	'</center>\n'+
	'</body>\n\n'+
	'</html>\n\n\n'
  );
  w.document.close();
  w.focus();
}

function scar(a) {
  if (a.createTextRange) a.pos = document.selection.createRange().duplicate();
}

function art_ins(a,s) {
  s = document.getElementById(s);
  gen = ".b.i.u.s.";
  if (document.all) {
    if (s.createTextRange && s.pos) {
      var cp = s.pos;
      if (cp.text != "") {
        rp = a.replace(/\[/,"").replace(/\//,"").replace(/\]/,"");
        if (gen.indexOf("."+rp+".") != -1) a = "["+rp+"]"+cp.text+"[/"+rp+"]";
        else if (rp.substring(0,6) == "color=") a = "["+rp+"]"+cp.text+"[/color]";
        else if (rp.substring(0,5) == "size=") a = "["+rp+"]"+cp.text+"[/size]";
      }
      cp.text = a;
    }
    else s.value = a;
  }
  else {
    b = s.value;
    l = s.selectionStart;
    e = s.selectionEnd;
    if (l != e) {
      rp = a.replace(/\[/,"").replace(/\//,"").replace(/\]/,"");
      if (gen.indexOf("."+rp+".") != -1) a = "["+rp+"]"+b.substring(l,e)+"[/"+rp+"]";
      else if (rp.substring(0,6) == "color=") a = "["+rp+"]"+b.substring(l,e)+"[/color]";
      else if (rp.substring(0,5) == "size=") a = "["+rp+"]"+b.substring(l,e)+"[/size]";
    }
    s.value = b.substring(0,l)+a+b.substring(e,b.length);
  }
}

function font_generic(a,b) {
  ab = document.getElementById(a);
  var sp=-1,sa=-1,temp=" "+ab.value;
  for (i=0;i!=-1;i=temp.indexOf("["+b+"]",(i+1))) sp++;
  for (i=0;i!=-1;i=temp.indexOf("[/"+b+"]",(i+1))) sa++;
  if (sp>sa) art_ins("[/"+b+"]",a);
  else art_ins("["+b+"]",a);
  ab.focus();
  ab.blur();
  ab.focus();
}

function dir_insert(a) {
  ab = document.getElementById(a);
  art_ins("[list]\n[*]\n[*]\n[*]\n[/list]",a);
  ab.focus();
  ab.blur();
  ab.focus();
}

function setcol(a) {
  document.getElementById('ssel_cc').style.background = a;
}

function pick_color(a,b) {
  closeda();
  art_ins(a,b);
  ab = document.getElementById(b);
  ab.focus();
  ab.blur();
  ab.focus();
}

function closeda() {
  bldy = document.getElementsByTagName('body').item(0);
  v = document.getElementById('ssel_cc');
  if (v) bldy.removeChild(v);
}

function openda(alv) {
  closeda();
  ns = document.createElement('div');
  ns.id = "ssel_cc";
  ns.style.display = "block";
  ns.style.position = "absolute";
  ns.className = "popup";
  ns.style.zIndex = 1001;

  var col = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];

  res = '<table cellpadding=0 cellspacing=0><tr><td align=right><a href="#" onclick="closeda();return false;"><img src="http://www.fantasiankingdoms.com/images/x.gif" width=16 height=16 title="Close"></a></td></tr><tr><td align=center valign=middle><table style="background:#FFFFFF;font-size:0px;border:solid 1px #000000;margin:0 16px 16px 16px;" cellpadding=0 cellspacing=1>';
  for (i=15;i>=0;i=(i-3)) {
    res += '<tr>';
    for (a=15;a>=0;a=(a-3)) {
      for (b=15;b>=0;b=(b-3)) {
        temp = "#"+col[i]+col[i]+col[a]+col[a]+col[b]+col[b];
        res += '<td style="cursor:pointer;" onclick="pick_color(\'[color='+temp+']\',\''+alv+'\');" bgcolor="'+temp+'" title="'+temp+'" width=7 height=7 onmouseover="setcol(\''+temp+'\');">&nbsp;</td>';
      }
    }
    temp = "#"+col[i]+col[i]+col[i]+col[i]+col[i]+col[i];
    res += '<td style="cursor:pointer;" onclick="pick_color(\'[color='+temp+']\',\''+alv+'\');" bgcolor="'+temp+'" title="'+temp+'" onmouseover="setcol(\''+temp+'\');" width=7 height=7>&nbsp;</td>';
    res += '</tr>';
  }
  res += '</table></td></tr></table>';

  ns.innerHTML = res;
  v = document.getElementById(alv);
  ns.style.left = (v.offsetLeft+2)+"px";
  ns.style.top = (v.offsetTop-100)+"px";
  void(bldy.appendChild(ns));
}

function art_colstart(a) {
  ab = document.getElementById(a);
  var sp=-1,sa=-1,temp=" "+ab.value;
  for (i=0;i!=-1;i=temp.indexOf("[color=",(i+1))) sp++;
  for (i=0;i!=-1;i=temp.indexOf("[/color]",(i+1))) sa++;
  cncl = false;
  if (document.all) {
    var cp = ab.pos;
    if (cp && cp.text != "") cncl = true;
  }
  else {
    if (ab.selectionStart != ab.selectionEnd) cncl = true;
  }
  if (sp>sa && !cncl) {
    art_ins("[/color]",a);
    ab.focus();
    ab.blur();
    ab.focus();
  }
  else openda(a);
}

function size_change(a) {
  ab = document.getElementById(a);
  var sp=-1,sa=-1,temp=" "+ab.value;
  for (i=0;i!=-1;i=temp.indexOf("[size=",(i+1))) sp++;
  for (i=0;i!=-1;i=temp.indexOf("[/size]",(i+1))) sa++;
  cncl = false;
  if (document.all) {
    var cp = ab.pos;
    if (cp && cp.text != "") cncl = true;
  }
  else {
    if (ab.selectionStart != ab.selectionEnd) cncl = true;
  }
  if (sp > sa && !cncl) {
    art_ins("[/size]",a);
  }
  else {
    var temp = prompt("Which font size do you want to use?\nSelect from 6 to 32","10");
    if (temp == null) return;
    if (isNaN(temp) || Number(temp) < 6 || Number(temp) > 32) temp = 10;
    temp = Math.floor(temp);
    art_ins("[size="+temp+"]",a);
  }
  ab.focus();
  ab.blur();
  ab.focus();
}

function setquote(a,b) {
  v = document.getElementById(b);
  x = String(v.value);
  if (x.indexOf(a) == -1) {
    v.value = a+"\n\n"+x;
    v.focus();
    v.blur();
    v.focus();
  }
}

var mx,my;

function gxy(e) {
  mx = (document.all) ? (document.body.scrollLeft + event.clientX) : e.pageX;
  my = (document.all) ? (document.body.scrollTop + event.clientY) : e.pageY;
}

document.onmousemove = gxy;






