// Copyright 2006 Baerana
// Version 1.0

function ctform(nameform) {
 var Form=document.forms[nameform]
 var ranct=Math.random()
 if(Math.round(Math.random())) {
  Form.resct.value="Heads: " +  Form.heads.value
 } else {
  Form.resct.value="Tails: " + Form.tails.value
 }
}


function ynform(nameform) {
 var Form=document.forms[nameform]
 var ranyn=Math.random()
 if(Math.round(Math.random())) {
  Form.resyn.value="Yes"
 } else {
  Form.resyn.value="No"
 }
}

function randform(nameform) {
 var Form=document.forms[nameform]
 var ranum=Math.random()
 var max=Math.floor(Form.max.value)
 var min=Math.floor(Form.min.value)
 Form.result.value = Math.floor(ranum*(max-min+1)+min)
}


function makecointossform() {
document.write('\
<form name="cointoss" id="cointoss">\
<fieldset>\
 <legend>Flip a coin</legend>\
Heads: <input name="heads" id="heads" type="text"> <br>\
or<br>\
Tails: <input name="tails" id="tails" type="text"><br>\
  <br>\
  <input onclick="ctform(\'cointoss\')" value="Flip the coin"\
 type="button"> <input type="reset"> <br>\
  <br>\
Result: <input name="resct" id="resct" size="20" type="text">\
</fieldset>\
</form>\
')
}

function makeyesnoform() {
document.write('\
<form name="yesno" id="yesno">\
<fieldset>\
<legend>Ask a yes/no question</legend>\
Question: <input name="ques" id="ques" type="text"><br>\
  <br>\
  <input onclick="ynform(\'yesno\')" value="Yes or No?" type="button"> \
  <input type="reset"><br>\
  <br>\
Result: <input name="resyn" id="resyn" size="4" type="text">\
</fieldset>\
</form>\
')
}

function makerandintform() {
document.write('\
<form name="randint" id="randint">\
<fieldset>\
<legend>Pick a number</legend>\
Min: <input name="min" id="min" size="5" value="1" type="text">\
Max: <input name="max" id="max" size="5" value="10" type="text"> \
<input\
 onclick="randform(\'randint\')" value="Pick a number for me"\
 type="button"> \
<input type="reset"> \
Result: <input name="result" id="result" size="5" type="text">\
</fieldset>\
</form>\
')
}
