/* wildsurg.js
   by Robert J Becraft
   aka castlewrks@aol.com

  (c) 2003, 2006 All Rights Reserved.  Use of this code is acceptable with this notice intact.
*/


function aan(v){
  switch (v.charAt(0)){
    case "a":
    case "e":
    case "i":
    case "o":
    case "u":
                   return "an "+v
                   break;
    default:
                   return "a "+v
   } /* switch */
}

Surgepre=new Array(
"The first four notes of Beethoven's Fifth Symphony echo through the air. All creatures within hearing range hostile to the caster must make a morale check",
"plunking and plinking of Dueling Banjos (Deliverance) echo through the air. All creatures within hearing range hostile to the caster must make a morale check",
"loud bang",
"loud boing",
"loud vibrating bo-oi-oi-ing",
"loud chittering",
"loud clang",
"loud crash",
"loud bong",
"loud pop",
"loud whistle",
"loud whoosh",
"loud chime",
"loud 'bzzzzt'",
"loud 'burp'",
"soft chime",
"chimes ringing flatly",
"chimes tinkling flatly",
"soft gurble",
"clap of thunder",
"hollow 'plunk'",
"hollow 'plough'",
"howling of wolves",
"yeowling of cats",
"crash of an avalanche",
"sound of chains dragging",
"sound of musical notes",
"sound of untuned musical notes",
"incomplete song",
"clashing musical noise",
"trumpet sounding charge",
"flute trilling",
"cord of a guitar strings being strummed",
"plunk of a banjo string being plucked",
"harp being stroked strongly",
"harp being played quietly",
"harp string snapping loudly",
"violin being badly played",
"soprano voice singing",
"bass voice mumbling",
"voice saying 'this day will live in infamy'",
"voice saying 'but I don't want to die'",
"voice saying 'I'll be baack'",
"high pitched voice saying 'mommy!'",
"high squeaky voice saying 'moma!'",
"voice saying 'go ahead punk... make my day!",
"incoherant echo of voices",
"drum building to a crescendo",
"drums beating off in the distance",
"quiet breeze",
"fragrant breeze",
"smell of salty air",
"smell of a pine forest",
"smell of lavendar",
"smell of oranges",
"smell of ozone",
"smell of a fart",
"smell of a pig fart",
"smell of BO",
"smell of skunk",
"hot breeze",
"cold breeze",
"foul smelling breeze",
"icy wind",
"hot wind",
"hot dry wind",
"strong wind",
"gust of wind",
"swirling wind",
"wind blowing dry tumbleweeds",
"bright flash",
"bright flash of lightening",
"bright orange flash",
"bright crimson flash",
"bright pink flash",
"bright yellow flash",
"blinding flash",
"flash of a meteor",
"bright meteor overhead",
"shower of sparkles",
"shower of dirt",
"shower of sand",
"shower of small stones",
"shower of oyster shells",
"shower of shells",
"shower of broken glass",
"shower of manure",
"shower of large stones (Dexterity roll to avoid, 2D6 damage if failed)",
"flurry of snowflakes",
"downpour of hail",
"downpour of rain",
"drenching waterfall",
"ankle-deep cloud of fog",
"waist-deep cloud of fog",
"blizzard of snowflakes",
"flurry of dry leaves",
"flurry of soap bubbles",
"flurry of white chicken feathers",
"flurry of pink chicken feather",
"flurry of small ripped parchment fragments",
"flurry of large parchment pages",
"flurry of multi-colored magic lights",
"smoke ring radiating out from the caster",
"smoke ring moving vertical from the caster",
"smoke ring radiating out from the target",
"smoke ring moving vertical from the target",
"smoke ring moving from caster to target",
"cloud of smoke",
"cloud of pink smoke",
"cloud of black smoke",
"cloud of white smoke",
"cloud of choking black smoke",
"hissing column of smoke",
"roman-candle shower of sparks",
"firework explosion overhead",
"dust-devil swirl" 
);

Surgescope=new Array (
"All",
"All metal",
"All non-metal",
"All magical",
"All non-magical",
"All non-protected"
);
Surgeitem= new Array (
"armor",
"shields",
"weapons",
"gauntlets",
"vambraces",
"gloves",
"clothing",
"gems",
"hats",
"shoes",
"staffs",
"belts",
"buckles",
"buttons",
"jewelry items",
"satchels, pouches, purses, or packs",
"satchels, pouches, or packs",
"satchels or packs",
"satchels",
"pouches",
"purses",
"packs",
"pouches",
"sacks or bags",
"cloaks or capes",
"underwear or undergarments",
"trousers or shorts"
);
Surgenitem=new Array(
"Nearby (<20 meters of caster) stones or rocks (>10 cms diameter)",
"Nearby (<20 meters of target) stones or rocks (>10 cms diameter)",
"Nearby (<20 meters of caster) stones or rocks (>50 cms diameter)",
"Nearby (<20 meters of target) stones or rocks (>50 cms diameter)",
"Nearby (<20 meters of caster) plants",
"Nearby (<20 meters of target) plants",
"Trees within 20 meters of caster",
"Trees within 20 meters of target",
"Nearby (<20 meters of caster) furniture",
"Nearby (<20 meters of target) furniture",
"Nearby (<20 meters of caster) wooden objects or sticks",
"Nearby (<20 meters of target) wooden objects or sticks",
"Nearby (<20 meters of caster) creatures (not humanoid or monsters)",
"Nearby (<20 meters of target) creatures (not humanoid or monsters)",
"Nearby (<1/2 km of caster) monsters",
"Nearby (<1/2 km of target) monsters",
"Nearby (<1/2 km of caster) snakes",
"Nearby (<1/2 km of target) snakes",
"Fish in the nearest water source",
"Creatures in the nearest water source",
"Skeletons in the nearest graveyard or burial place",
"Nearby (<20 meters of target) rodents",
"Nearby (<20 meters of caster) rodents",
"Horses or other mounts within 20 meters of caster",
"Farm animals within 20 meters of caster",
"Wild forest animals (like squirrels)",
"Birds of all varieties flock together and",
"The nearest dragon",
"The oldest nearby dragon",
"Nearest man-made structure",
"Nearest man-made conveyance"
);

Surgetab = new Array (
"glow",
"glow brightly",
"glow softly",
"glow with fairy light",
"glow phosphorously",
"shimmer",
"sparkle",
"glisten",
"pulse brightly",
"pulse softly",
"pulse rapidly",
"flash brightly at random intervals",
"flash brightly at a fixed interval",
"emit light (aka continual light spell)",
"whistle shrilly",
"whistle loudly",
"whistle softly",
"crackle loudly",
"crackle softly",
"crackle and pop",
"chirp loudly",
"scream",
"scream loudly",
"squeal",
"squeal loudly",
"shreak",
"shreak loudly",
"squeak",
"squeak loudly",
"squawk",
"squawk loudly",
"squawk loudly when touched",
"cry continuously",
"cry piteously, nonstop",
"whimper continuously",
"whimper piteously",
"jabber nonsense",
"moan loudly",
"moan",
"moan when touched",
"giggle randomly",
"giggle when touched",
"giggle nonstop",
"cough randomly",
"cough on a regular interval",
"begin telling bad jokes nonstop",
"begin telling bad jokes randomly",
"loudly harrangue those nearby for his/her faults",
"critique every action of those nearby",
"loudly advise contrary actions to every action taken by those near them",
"cheer everyone on with boisterous positive commentary",
"sing bawdy tavern songs continuously",
"sing bawdy tavern songs randomly",
"recite bad poetry continuously",
"recite bad poetry randomly",
"loudly yell 'thief' whenever touched",
"loudly yell 'rape' whenever touched",
"loudly yell 'pervert' whenever touched",
"loudly yell 'thief' randomly",
"loudly yell 'rape' randomly",
"loudly yell 'pervert' randomly",
"loudly yell 'thief' continuously",
"loudly yell 'rape' continuously",
"loudly yell 'pervert' continuously",
"loudly yell 'jerk' randomly",
"loudly yell profanities whenever touched",
"loudly yell profanities randomly",
"loudly yell profanities continuously",
"repeat loudly everything spoken by those nearby",
"repeat loudly everything spoken or whispered by those nearby",
"rattle with every movement",
"rattle loudly with every movement",
"get slightly warm",
"get warm to the touch",
"get hot",
"get untouchably hot",
"get burning hot (1D6 damage)",
"burst into flames",
"magically melt into a formless blob",
"get cold",
"get freezing cold",
"magically freeze in place (for the duration of the surge)",
"grow hair [3 cms per round, for duration]",
"grow hair [18 cms per round, for duration]",
"grow hair [40 cms per round, for duration]",
"grow mushrooms",
"grow mold",
"grow fungus",
"grow algae",
"sprout fast growing vines (regrow when pulled for duration)",
"sprout fast growing poison ivy (regrow when pulled for duration)",
"sprout carrots",
"sprout green beans",
"sprout cabbages",
"sprout brussel sprouts",
"sprout fast growing grass (regrow when pulled for duration)",
"sprout fast growing weeds (regrow when pulled for duration)",
"sprout 1D6 tenacles that lash about doing 1D3 points of damage on hits to anyone in reach",
"ooze wet paint (DM picks color)",
"ooze puss",
"ooze oil",
"ooze green blood",
"ooze blood",
"ooze geletan",
"ooze ale",
"ooze beer",
"ooze wine",
"ooze whiskey",
"ooze brandy",
"ooze milk",
"ooze sour milk",
"ooze water",
"ooze snot from nose-like arpetures (aka runny-nose)",
"sneeze wetly from nose-like arpetures",
"drip wetly",
"leak profusely with water",
"leak profusely with blood",
"leak profusely with ale",
"leak profusely with wine",
"leak profusely with beer",
"get dusty",
"get dirty",
"get 'Pigpen' dirty",
"get muddy",
"smell horrible",
"smell rotten",
"smell sweetly",
"smell purfumed",
"smell tasty enough to eat",
"emit strong pheromes for a random creature (DM roll)",
"stink",
"reak with the smell of dead fish",
"reaks with burnt smell",
"turn invisible (regular <i>Invisibility</i>)",
"turn invisible (<i>Improved Invisibility</i>)",
"turn opaque",
"turn putrid green",
"turn bright red",
"turn bright yellow",
"turn black",
"turn white",
"turn orange",
"turn yellow",
"turn bright blue",
"turn dark blue",
"turn bright fuschia",
"turn bright pink",
"turn gold color (but are not real gold)",
"turn silver color (but are not real silver)",
"turn into gold",
"turn into silver",
"turn into platinum",
"turn to dust and fall to bits [save vs spell]",
"turn strongly magnetic",
"turn strongly anti-magnetic (repulsing all metal)",
"turn strongly magnetic for objects of like material and composition",
"turn strongly anti-magnetic for objects of like material and composition",
"turn rubbery and useless",
"turn stiff and unmoving",
"become statically charged, discharging when touched",
"become electrically charged, discharging when touched for 1D6 of damage",
"become allergic to current owner (sneezing and coughing when in their possesion, but not when given to someone else)",
"cause alergic reaction to owner (sneezing/coughing/swelling, etc.) when touched or handled",
"cause any skin touched by object to itch",
"become flypaper sticky",
"become sticky",
"grow catus barbs",
"grow hawthorn barbs",
"grow porcupine quills (that shoot when touched (1D3 for hit))",
"sway",
"rock",
"bounce",
"bauble-bounce",
"wiggle",
"wiggle when touched",
"jiggle violently",
"vibrate and hum",
"animate and try to hide",
"animate and move sinuously",
"animate and jiggle",
"animate and take flight",
"animate with pirana-like teeth that nip for 1-hp per successful bite",
"animate and attack owner",
"animate and hides",
"magically drop to the floor",
"magically float off into the air",
"magically teleport somewhere within 100 foot diameter of their previous location",
"magically teleport to the nearest creature's home",
"magically teleport somewhere unknown",
"magically teleport to the highest tree in sight and must make a dexterity roll to keep from falling out of the tree",
"magically teleport to the hightest point visible from the point of origination",
"magically teleport to the highest mountain in sight",
"magically teleport and dumped into the nearest water source [lake, pond, ocean]",
"sprout large petaled flowers that emit a sleep inducing scent [save vs spell]",
"sprout large petaled flowers that emit a poisonious gas [save vs gas]",
"become <i>magic</i>, and will glow if 'Detect Magic' is used (if magic, become non-detectable by 'Detect Magic' spell)"
);

// These effects are for caster or target specifically and may apply to others within range (case 3 below)

SurgeCT = new Array (
"The caster",
"The target",
"Both the caster and target",
"Only those within 5 meters of the target, but not the target",
"Only those within 5 meters of the caster, but not the caster",
"Only those within 5 meters of the target, including the target",
"Only those within 5 meters of the caster, including the caster",
"Only those within 5 meters of the target, but not the target, who are friendly to caster",
"Only those within 5 meters of the caster, but not the caster, who are friendly to caster",
"Only those within 5 meters of the target, including the target, who are friendly to target",
"Only those within 5 meters of the caster, including the caster, who are friendly to target",

"All of those within 10 meters of the target, but not the target",
"All of those within 10 meters of the caster, but not the caster",
"All of those within 10 meters of the target, including the target",
"All of those within 10 meters of the caster, including the caster",
"Only those within 10 meters of the target, but not the target, who are friendly to caster",
"Only those within 10 meters of the caster, but not the caster, who are friendly to caster",
"Only those within 10 meters of the target, including the target, who are friendly to target",
"Only those within 10 meters of the caster, including the caster, who are friendly to target",

"Only those with no magical abilities",
"Only those with magical abilities",
"Only those with magical protections",
"Only those with no magical protections",
"Everyone further than 5 meters from the caster",
"Everyone further than 5 meters from the target",
"Everyone further than 10 meters from the caster",
"Everyone further than 10 meters from the target"
);

SurgeCTtab = new Array (
"glows",
"glows brightly",
"glows softly",
"glows with fairy light",
"glows phosphorously",
"shimmers",
"sparkles",
"pulses brightly",
"pulses softly",
"flashes brightly at random intervals",
"flashes brightly at a fixed interval",
"emits light (aka continual light spell)",
"whistles shrilly",
"whistles loudly",
"whistles softly",
"crackles loudly",
"crackles softly",
"crackles and pops",
"chirps loudly",
"screams",
"screams loudly",
"shreaks",
"shreaks loudly",
"squeaks",
"squeaks loudly",
"squawks",
"squawks loudly",
"squawks loudly when touched",
"cries continuously",
"cries piteously, nonstop",
"jabbers nonsense",
"moans loudly",
"moans",
"moans when touched",
"giggles randomly",
"giggles when touched",
"giggles nonstop",
"coughs randomly",
"coughs on a regular interval",
"tells bad jokes nonstop",
"tells bad jokes randomly",
"tells good jokes nonstop",
"tells good jokes randomly",
"laughs maniacally",
"laughs jovially",
"laughs with a twittering",
"laughs with a gut wreching 'guffah'",
"laughs with gasping breaths between each chuckle",
"laughs, giggles, then laughs again",
"finds everything laughable around him",
"loudly harrangues those nearby for his/her faults",
"critiques every action of those nearby",
"loudly advises contrary actions to every action taken by those near them",
"cheers everyone on with boisterous positive commentary",
"sings bawdy tavern songs continuously",
"sings bawdy tavern songs randomly",
"recites bad poetry continuously",
"recites bad poetry randomly",
"loudly yells whenever touched",
"loudly yells randomly",
"loudly yells continuously",
"loudly yells 'thief' whenever touched",
"loudly yells 'rape' whenever touched",
"loudly yells 'pervert' whenever touched",
"loudly yells 'thief' randomly",
"loudly yells 'rape' randomly",
"loudly yells 'pervert' randomly",
"loudly yells 'thief' continuously",
"loudly yells 'rape' continuously",
"loudly yells 'pervert' continuously",
"loudly yells 'jerk' randomly",
"repeats loudly everything spoken by those nearby",
"argues incessantly with himself",
"is unable to speak",
"rattles with every movement",
"rattles loudly with every movement",
"gets slightly warm",
"gets warm to the touch",
"gets hot",
"gets untouchably hot",
"gets burning hot (1D6 damage to anyone who touches them)",
"bursts into flames",
"magically melts into a formless blob",
"gets cold",
"gets freezing cold",
"grow hair [1 inch per round, for duration]",
"grow hair [6 inch per round, for duration]",
"grow hair [1 foot per round, for duration]",
"has all hair/feathers/fur fall off",
"grows mushrooms",
"grows mold",
"grows algae",
"sprouts fast growing vines (regrow when pulled for duration)",
"sprouts fast growing poison ivy (regrow when pulled for duration)",
"sprouts carrots",
"sprouts green beans",
"sprouts cabbages",
"sprouts brussel sprouts",
"sprouts fast growing grass (regrow when pulled for duration)",
"sprouts fast growing weeds (regrow when pulled for duration)",
"sprouts 1D6 tenacles that lash about doing 1D3 points of damage on hits to anyone in reach",
"oozes wet paint (DM picks color)",
"oozes puss",
"oozes oil",
"oozes green blood",
"oozes blood",
"oozes ale",
"oozes beer",
"oozes wine",
"oozes whiskey",
"oozes brandy",
"oozes milk",
"oozes sour milk",
"oozes water",
"oozes snot from nose-like arpetures (aka runny-nose)",
"sneezes wetly from nose-like arpetures",
"drips wetly",
"leaks profusely with water",
"leaks profusely with blood",
"leaks profusely with ale",
"leaks profusely with wine",
"leaks profusely with beer",
"gets dusty",
"gets dirty",
"gets muddy",
"smells horrible",
"smells rotten",
"smells sweetly",
"smells purfumed",
"smells tasty enough to eat",
"emits strong pheromes for a random creature (DM roll)",
"stinks",
"is afflicted with a nasty desease",
"reaks with the smell of dead fish",
"reaks with burnt smell",
"turn invisible (regular <i>Invisibility</i>)",
"turn invisible (<i>Improved Invisibility</i>)",
"turns opaque",
"turns putrid green",
"turns bright red",
"turns bright yellow",
"turns black",
"turns white",
"turns bright blue",
"turns dark blue",
"turns bright fuschia",
"turns bright pink",
"turns gold color (but is not real gold)",
"turns silver color (but is not real silver)",
"turns into gold",
"turns into silver",
"turns into platinum",
"turns to dust and falls to bits",
"turns strongly magnetic",
"turns strongly anti-magnetic (repulsing all metal)",
"turns strongly magnetic for objects of like material and composition",
"turns strongly anti-magnetic for objects of like material and composition",
"becomes statically charged, discharging when touched",
"becomes electrically charged, discharging when touched for 1D6 of damage",
"becomes flypaper sticky",
"becomes sticky",
"fumbles and drops any weapons",
"is slowed (per the spell)",
"is hasted (per the spell)",
"becomes delusional",
"shrinks to 1/2 his/her normal size",
"shrinks to 1/4 his/her normal size",
"shrinks to 1/8 his/her normal size",
"shrinks to 1/12 his/her normal size",
"doubles in size",
"head enlarges to twice normal size",
"head shrinks to half normal size",
"head blows up like a balloon, stretching and smoothing facial features",
"hands enlarge to twice normal size",
"hands shrink to half normal size",
"grows horse's tail",
"grows lion's tail",
"grows rat's tail",
"grows peacock's tail",
"grows crocodile's tail",
"grows lizard's tail",
"grows pegasus wings (working set)",
"grows angel wings (working set)",
"grows ostrige wings (non-working)",
"grows catus barbs",
"grows hawthorn barbs",
"grows porcupine quills (that shoot when touched (1D3 for hit))",
"sways",
"rocks",
"bounces",
"bauble-bounces",
"wiggles",
"confused",
"wiggles when touched",
"is covered in liquid chocolate",
"is the base of a double force gust of wind",
"is the center of an 18 foot diameter deluge of rain",
"magically teleports somewhere within 100 foot diameter of his/her previous location",
"is the center of an 18 foot diameter <i>Reverse Gravity</i> area.  All those in range are affected as well",
"becomes the center of a vortex of rapidly expanding soap suds that quickly cover an area 40 meters in diameter",
"becomes the center of a vortex of rapidly expanding beer suds that quickly cover an area 40 meters in diameter",
"spins rapidly for 1D4 rounds.  Once they stop spinning, they must make dexterity rolls each round for 1D4 rounds thereafter",
"are healed for 1D8 hps (if wounded, otherwise no effect)",
"affected by irritating rash (Dexterity reduced to 3 for duration)",
"are affected by <i>Mirror Image</i>",
"are affected as if by a <i>Philter of Stammering & Stuttering</i>",
"tongue grows long enough to lick eyebrows.  If tongue is already that long, some other body part is affected",
"tongue splits (snakelike), and becomes smell organ",
"tongue is long and prone to sudden explosions after bugs (froglike)",
"fingernails grow to 40 cms in length instantly",
"fingernails replaced with razor sharp claws (rip any gloves worn, make it impossible to hold normal weapons, but do 2D8 damage)",
"hair grows [3 cms per round, for duration]",
"hair grows [18 cms per round, for duration]",
"hair grows [40 cms per round, for duration]",
"hair grows 40 cms in length instantly",
"all body hair all falls out",
"all body hair falls out, (grows back naturally eventually, itching uncontrollably when it does)",
"all head hair falls out",
"suddenly has two left feet (movement rate is half for duration)",
"are suddenly chained to the ground with heavy chains",
"are suddenly bound with iron bands (will require locksmith to remove)",
"are tied and gagged with a more than generous volume of rope (aka Smedley Duright)",
"are locked into stocks that hold their hands and feet",
"is locked into a cage just large enough to hold them standing upright",
"become suspended from crosses that spring from the ground",
"voice is high pitched and squeaky",
"voice is low pitched and deep",
"voice is a cackle",
"face is blackened by small explosion.  Disorientation lasts for duration of spell",
"face is blackened and hair stands straight up from a small explosion.  Disorientation lasts for duration of spell",
"believes their sex has changed",
"experiences a sex change",
"turns ethereal",
"nose doubles in size",
"nose disappears",
"nose grows to huge size",
"nose glows rosy red",
"nose glows lime green",
"nose grows huge wart",
"nose grows huge black wart",
"nose grows several ugly warts (charisma -4 for duration)",
"ears grow furry and long (bunny-like)",
"ears grow furry and pointy (donkey-like)",
"ears double in size",
"ears disappear",
"ears grow to huge size",
"ears grow furry and pointy like a rabbit",
"ears grow round and petite like a mouse",
"ears glow rosy red",
"ears glow lime green",
"ears glow pink",
"ears become mouths that echo every thought of the affected creature",
"teeth chatter uncontrollably",
"teeth chatter loudly",
"voice goes up 2 octives, higher and squeakier",
"voice drops 2 octives, lower and deeper",
"entire body shudders uncontrollably",
"entire body shivers violently",
"entire body spasms",
"drop to the ground in epileptic fit",
"experience reoccuring epileptic fits every few minutes",
"looses all teeth",
"has front teeth enlarged (rabbit-like)",
"has teeth sharpened (shark-like)",
"has teeth dulled (cow-like)",
"has lips turned into duck bill",
"has lips turned into chicken beak",
"has feathers sprout on their face",
"has gills and immediately needs water to breath",
"has gills, but normal breathing is unaffected",
"has 1D6 ugly warts spring up on their face (Charisma-1 per wart)",
"arms lengthen and character moves about ape-like",
"arms lengthen and character moves about on all four appendages like four-legged creatures",
"hands stiffen with arthritis (gripping of anything becomes impossible)",
"joints stiffen with arthritis (movement/agility/dexterity impacted)",
"suffers from repeated asthmatic attacks triggered by any increase in physical exhertion",
"hears contrary voices that originate inside their head [no one else can hear them]",
"leeches pour from ears [1 every 5 seconds]",
"leeches pour from ears and nose [2 every 5 seconds]",
"mouth closed bound by lockjaw (character is unable to speak)",
"handedness changes (left-handers become right-handers and vice-versa)",
"mouth puckers so tightly that speach is impossible (may impact eating and drinking if duration excessive)",
"toes grow to enormous size (ruining shoes, if worn, and causing 1D4 points of damage)",
"belly expands like a balloon (ruins tunics, armor, belts or anything worn over that area)",
"goes completely insane (save vs spell)",
"is forced to speak in rhyme",
"becomes extremely drunk",
"is unable to get drunk (no matter how many drinks they have)",
"becomes stoned and only interested in 'pretty colors'",
"has an argumentative second head sprout on their shoulders",
"belly button becomes argumentative mouth",
"forgets the last 24 hours events",
"forgets who he/she is",
"forgets why he/she is here",
"becomes covered with tar and feathers",
"is hit by a lemon-mirangue pie and finds another one in their hand [pies will keep appearing for duration of spell]",
"is teleported to the highest tree in sight and must make a dexterity roll to keep from falling out of the tree",
"is teleported to the hightest point visible from the point of origination",
"is teleported to the highest mountain in sight",
"is teleported and dumped into the nearest water source [lake, pond, ocean]",
"finds themselves ravenously hungry.  Primary objective becomes eating to satisfy hunger",
"finds themselves unable to eat for the duration of the spell.  Anything eaten comes back up again",
"finds themselves wide awake.  Lasts for duration of spell",
"finds themselves unable to keep their eyes open.  Tiredness lasts for duration of spell",
"becomes extremely anti-religious",
"becomes extremely pious, and acts accordingly",
"becomes religiously extreme",
"becomes fanatic about their religion",
"goes color blind.  They can only see black and white, with shades of grey",
"is replicated with an exact clone, one of which is good, one of which is evil [killing one kills both]",
"is replicated with a simulcrum under the caster's control",
"is overwelmed with dispair and falls to the ground crying",
"is overwelmed with urge to find something lost on the ground at his feet.  Focused on effort for duration of spell",
"runs off to find something lost 'over there', will not return till duration runs out on spell",
"ages 2D10 years in age",
"ages to maximum age according to race",
"reverts to infancy",
"is shoved upwards by a column of earth just large enough to stand on.  It stops after rising 10 feet",
"is shoved upwards by a column of earth just large enough to stand on.  It stops after rising 20 feet",
"is shoved upwards by a column of earth just large enough to stand on.  It stops after rising 50 feet",
"is shoved upwards by a column of earth just large enough to stand on.  It stops after rising 100 feet"
);

SurgeGT=new Array(
"A web springs from the caster's fingertips and the caster becomes one anchor point",
"There is a sudden drastic weather change in the immediate area (<1/2 KM).  It begins to snow",
"There is a sudden drastic weather change in the immediate area (<1/2 KM).  It begins to sleet",
"There is a sudden drastic weather change in the immediate area (<1/2 KM).  It begins to hail",
"There is a sudden drastic weather change in the immediate area (<1/2 KM).  Fog obliterates all visibility greater than 5 meters",
"There is a sudden drastic weather change in the immediate area (<1/2 KM).  It clouds up and begins to thunder and lightening",
"There is a sudden drastic weather change in the immediate area (<1/2 KM).  It begins to rain",
"Clouds roll in",
"Large dark clouds roll in",
"Caster and target find themselves locked in a must win card game, both committed to being the winner.  Concentration broken upon expiration of the spell",
"Caster and target find themselves locked in a must win chess game, both committed to being the winner.  Concentration broken upon expiration of the spell",
"Caster and target fall immediately and totally in love with one another for the duration of the spell",
"Caster and target are vicious, beserk with hate for one another and will do everything in their power to destroy one another",
"Caster and target become oblivious of each other and will avoid any contact, combat or conversation with each other",
"A sudden and unexpected solar eclipse darkens the sky",
"The ground shakes and crakes open (Dexterity rolls to avoid falling in)"
);

SurgeND=new Array( /* effects w/ duration implied or specified */
"Caster summons a rhino",
"Caster summons an elephant",
"Caster summons a large mouse",
"Caster summons a large dove",
"Caster summons a large iguana",
"Caster summons a large rabbit",
"Caster summons a buzzard",
"Caster summons a giraffe",
"Caster summons a large kitten",
"Caster summons an ugly painting",
"Caster summons a storm giant's boot",
"Caster summons a set of bellows",
"Caster summons a watermelon, which appears in his hands",
"Caster summons a hungry lion",
"Caster summons a noisy monkey",
"Caster summons an upset orangatang",
"Caster summons 1D6 chickens who appear at his feet and take off sqwaking at top speed",
"Caster has a cloud of fluttering butterflies spring from his fingers.  They blind everyone within 20 meters",
"Caster is the source of angry hornets (as if exiting a hive), that attack everyone within 20 meters",
"Caster falls prone on the ground.  It will take 1 round to resume standing",
"Target falls prone on the ground.  It will take 1 round to resume standing",
"Other enemies fall prone on the ground.  It will take 1 round to resume standing",
"Party members fall prone on the ground.  It will take 1 round to resume standing",
"10D4 gems spray from caster's fingertips and do 1hp of damage each to anything within 18 meters of caster",
"800 rubber balls (1 inch diameter) rain down for 1D4 rounds in area 18 meters diameter around caster, causing all in affected area to make dexterity rolls",
"Target affected by 'Disintegrate' spell",
"Target inflates like a balloon for 1D4 rounds, then deflates in 1D4 rounds",
"Caster inflates like a balloon for 1D4 rounds, then deflates in 1D4 rounds",
"Everyone except the caster inflate like a balloon for 1D4 rounds, then deflates in 1D4 rounds",
"Target affected by 'Scare' spell",
"Darkness affects the target every other round for 3-10 rounds",
"Fumble affects the target at twice normal duration",
"Caster and target exchange places, clothing, possessions, etc",
"A chromatic orb affects the target",
"A ray of enfeeblement affects the target",
"2-6 cream puffs fly from caster's hands toward target",
"A <i>Cone of Cold</i> affects the target area at double damage",
"A lightening bolt jumps from the caster's fingers (per <i>Lightening Bolt</i> spell)",
"A fireball leaps from the caster's fingers (per <i>Fireball</i> spell)",
"All magical weapons within 30' of caster loose their magic powers for 2 rounds",
"All moving creatures within 60' of the caster must save vs. spell or trip and fall",
"All glass or crystal within 30' of the caster shatters.  Magic items or glass containers holding magic items get a saving throw",
"No one (except the caster) can hear the caster for 1d6 rounds. Spells with verbal components may still be cast.  Caster can hear normally",
"A forest suddenly sprouts and grows up around the party.  If already in a forest, it thickens and becomes impassable without some work to clear a path",
"An unexpected earthquake shakes the ground and quickly disapates",
"A violent earthquake knocks everyone to the ground",
"A violent wave that surges through the earth erupts at the caster and races outward from that point, knocking everyone encountered down.  Will weaken at 1km.",
"A violent wind blows outward from caster and prevents anyone from approaching him.  It stops when he moves.",
"Steam vents open up in the ground around the party and targets.  Dexterity checks to avoid being scalded by hot steam (2D6)",
"Steam vents open up in the ground and hot lava bubbles out.  Dexterity checks to avoid being scalded by hot steam (2D6) or burned by lava (2D6)",
"An empty log cabin appears",
"A stone barn appears",
"A stone well appears",
"A stone fountain appears",
"A large crack opens up in the ground",
"A ring of mushrooms appear surrounding the party",
"A ring of mushrooms appear surrounding the target",
"Spell functions as normal",
"Spell functions at half its normal effect",
"Spell functions at one quarter its normal effect",
"Spell functions at twice its normal effect",
"Spell functions at four times its normal effect",
"Spell functions at its maximum documented effect",
"Spell functions at twice its maximum documented effect",
"A sparkling ball of flame erupts from the top of the caster's head and flies skyward to burst into a fantastic flaming display. (If inside, treat as a 3D6 fireball instead.)",
"A rainbow appears"
);

Surgerange= new Array(
"on caster",
"on target",
"on targets antagonistic to caster",
"on targets friendly to caster",
"within xx meters of caster",
"within xx meters of target"
);

EffectDur= new Array(
"one round",
"two rounds",
"three rounds",
"four rounds",
"five rounds",
"six rounds",
"seven rounds",
"eight rounds",
"nine rounds",
"one turn",
"two turns",
"three turns",
"four turns",
"five turns",
"one hour",
"two hours",
"three hours",
"four hours",
"five hours",
"six hours",
"seven hours",
"eight hours",
"nine hours",
"ten hours",
"eleven hours",
"twelve hours",
"thirteen hours",
"fourteen hours",
"fifteen hours",
"sixteen hours",
"seventeen hours",
"eighteen hours",
"nineteen hours",
"twenty hours",
"twenty one hours",
"twenty two hours",
"twenty three hours",
"one day",
"two days (or until dispeled)",
"three days (or until dispeled)",
"four days (or until dispeled)",
"five days (or until dispeled)",
"six days (or until dispeled)",
"one week (or until dispeled)",
"two weeks (or until dispeled)",
"three weeks (or until dispeled)",
"one month (or until dispeled)",
"two months (or until dispeled)",
"three months (or until dispeled)",
"four months (or until dispeled)",
"five months (or until dispeled)",
"six months (or until dispeled)",
"one year (or until dispeled)",
"two years (or until dispeled)",
"three years (or until dispeled)",
"four years (or until dispeled)",
"five years (or until dispeled)",
"six years (or until dispeled)",
"seven years (or until dispeled)",
"eight years (or until dispeled)",
"nine years (or until dispeled)",
"ten years (or until dispeled)",
"forever (it is permanent)"
);

TextNum=new Array(
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty"
);

SurgeMessage=new Array(
"Your inexperience with magic has created a magic surge.",
"And another one...",
"You like playing with fire...",
"Really, you were warned.",
"You are messing with fire.",
"Aiey, I can't believe you're contiuing to mess with this stuff!",
"Well, keep it up, you might get the hang of it.",
"Again!",
"and again!",
"Wow!",
"Look at that!",
"Amazing!",
"Simply amazing.",
"How do you do that?",
"What else can you do?",
"How about a pizza?",
"One day you'll conjure a deamon and he'll have you as a pizza!",
"Your day is coming.",
"Sooner than you think!",
"Really really amazing!",
"Well, I'll leave you to this madness.",
"I did warn you right?!",
"Well, I know I warned you!",
"I'm leaving now!",
"Good luck!",
"You'll need it, you know!",
"Did I tell you the pixies might show up?",
"Well, keep it up, and they will.",
"But at least you know.",
"I'll be going now really.",
"You just keep doing what you are doing.",
"Bye now.",
"I see you are pretty focused.",
"Later.",
"I'm amazed.",
"It was nice knowing you.",
"You have a will?",
"You will need it if you keep it up.",
"A real glutton for punishment!",
"Look out now.",
"The giants are coming... just kidding.",
"You never know though.  If you keep it up, you'll never see them coming.",
"Well... there was a dwarf who had that problem.",
"You on the other hand are hopeless.",
"Stubborn even.",
"Definite fool if I ever saw one.",
"Well, persistent for sure.",
"I've known gnomes who were worse.",
"On and on...",
"and on...",
"Kinda like you.",
"Can't stop can you?",
"I bet you are paying more attention to me than what you are doing aren't you?",
"I can leave.",
"REALLY, I'll leave you to your madness.",
"Madness.  That's where you are.",
"I can't watch this anymore.",
"Don't worry.",
"There might be something to bury.",
"I did tell you you were messing with raw magic?",
"You never know what will happen when you aren't trained.",
"The really good wizards do it without the surges.",
"You're not that good are you.",
"Well...",
"Perhaps you'll survive.",
"It's possible.",
"Highly unlikely, but...",
"Perhaps it is possible.",
"You however, there is some doubt.",
"Hang on, my crystal is humming.",
" ",
" ",
" ",
" ",
" ",
"Still at it I see.",
"It was my mom.",
"On my crystal ball that is.",
"She's having me over for dinner this weekend.",
"I told her I was watching a fool mess with wild magic.",
"She told me to keep back.",
"Remember Uncle Hargua, she said",
"He was zapped by a wild surge.",
"The pink hair was really tough on the eyes.",
"The pig nose... nobody ever got used to that.",
" ",
" ",
" ",
"I'm getting bored.",
"Grilling dango steaks is more fun.",
"Well... I gotta go now.",
"Mom's making dinner... remember.",
"Takes me a while to get there.",
"Later.",
"O.K.",
" "
);


function Statistics()
{
if (statson==0) {
    S1=(Surgetab.length)*(Surgetab.length+1)*(Surgeitem.length)*(Surgescope.length+1)*(Surgerange.length+1);
    S2=(Surgetab.length)*(Surgetab.length+1)*(Surgenitem.length);
    S3=(SurgeCTtab.length)*(SurgeCTtab.length+1)*(SurgeCT.length+1);
    S4=(SurgeGT.length+1);
    S5=(SurgeND.length+1);
    
    S0=(Surgepre.length+2)*(Surgepre.length)*(Surgepre.length-1) /* Number of pre-condition combos, includes null case */
    
    SS="<font face='Trebuchet MS' size=1>";
    SS+="<br>There are "+S0+" combinations of pre-surge conditions that can be generated.";
    
    SS+="<br>Item Combinations = "+S1+" made up of "+(Surgetab.length+1)+" surges applied against "+(Surgeitem.length+Surgenitem.length+2)+" items with a scope of "+(Surgescope.length+1)+" and range of "+(Surgerange.length+1)+".  ";    
    SS+="<br>Nearby item Combinations = "+S2+" made up of "+(Surgetab.length+1)+" surges applied against "+(Surgenitem.length+1)+".  ";
    SS+="<br>Individual Surges = "+S3+" made up of "+(SurgeCTtab.length+1)+" applied against "+(SurgeCT.length+1)+" individuals.  ";
    SS+="<br>Specific Surges = "+S4+" from combinations against "+(SurgeGT.length+1)+" surges.  ";
    SS+="<br>All item/individual/specific surges can further combo against "+(EffectDur.length+1)+" possible time durations.  ";
    SS+="<br>Other Surges = "+(SurgeND.length+1)+" additional surges.  ";
    
    SS+="<br><br><b><font size=3>This program can generate "+(S0*(S1+S2+S3+S4)*EffectDur.length+S5)+" unique WILD SURGES.</b></font></font><br>";
    stats.innerHTML=SS
    statson=1;
    Sbutton.innerHTML="<button onclick='Statistics()'>Statistics On</button>";
   }
else {
    stats.innerHTML="";
    statson=0;
    Sbutton.innerHTML="<button onclick='Statistics()'>Statistics Off</button>";
  }
}

function Create_Surge()
{

  ST=rand(5)+1;
  SS=""
  ST1=rand(Surgepre.length);
  ST2=rand(Surgepre.length);
  while (ST2==ST1) ST2=rand(Surgepre.length);
  ST3=rand(Surgepre.length);
  ND=1 /* if still 1 below, generates duration */

  
  while ((ST3==ST1) & (ST3==ST2)) ST3=rand(Surgepre.length);

  if (ST1==0) SS+=Surgepre[0]+".  ";
  else if (ST2==0) SS+=Surgepre[0]+".  ";
  else if (ST3==0) SS+=Surgepre[0]+".  ";
  else
  {
  if (rand(10)>3)  /* surge precursor */
         SS+="The magic surge erupts with "+aan(Surgepre[ST1])+".  ";
  else
     if (rand(10)>7) /* double precursor */
         SS+="There is "+aan(Surgepre[ST1])+" followed by "+aan(Surgepre[ST2])+".  ";
     else
        if (rand(10)>7) /* double precursor */
            SS+="A magic surge starts with "+aan(Surgepre[ST1])+" followed by "+aan(Surgepre[ST2])+".  ";
        else
           if (rand(10)>5) /* triple precursor */
               SS+="There is "+aan(Surgepre[ST1])+" which is accompanied by "+aan(Surgepre[ST2])+", both of which are followed by a "+Surgepre[ST3]+".  ";
   }            
//  if (rand(10)>8)  /* repeat effects for every occurance */
//    SS+="This is repeated for everything affected by the surge.  ";
       
  switch (ST)
  {
   // --------------------------------------------------------------------------------------
    case 1:
  
      Surge=RandAttr(Surgetab);
      SurgeS=RandAttr(Surgescope);
      SurgeI=RandAttr(Surgeitem);
      SurgeR=RandAttr(Surgerange);
  
      switch (SurgeR)
      {
         case "on caster": break;
         case "on target": break;
         case "within xx meters of caster": SurgeR="within "+(rand(10)+1)*10+" meters of caster"; break;
         case "within xx meters of target": SurgeR="within "+(rand(10)+1)*10+" meters of caster"; break;
      }
     
        
      if (rand(10)>5)  /* double effects */
       {
         Surge2=RandAttr(Surgetab);
         while (Surge2==Surge)
           Surge2=RandAttr(Surgetab);
         Surge2=" and "+Surge2;
       }
      else
         Surge2="";
     
      SS+=SurgeS+" "+SurgeI+" "+SurgeR+" "+Surge+Surge2+".  ";
     break;
   // --------------------------------------------------------------------------------------
     case 2:  /* What happens to nearby objects */
        
      Surge=RandAttr(Surgetab);
      SurgeI=RandAttr(Surgenitem);

      if (rand(10)>5)  /* double effects */
       {
         Surge2=RandAttr(Surgetab);
         while (Surge2==Surge)
           Surge2=RandAttr(Surgetab);
         Surge2=" and "+Surge2;
       }
      else
         Surge2="";
     
      SS+=SurgeI+" "+Surge+Surge2+".  ";
            
     break;
   // --------------------------------------------------------------------------------------
     case 3:  /* what happens to caster or target */
        
      Surge=RandAttr(SurgeCTtab);
      SurgeI=RandAttr(SurgeCT);

      if (rand(10)>5)  /* double effects */
       {
         Surge2=RandAttr(SurgeCTtab);
         while (Surge2==Surge)
           Surge2=RandAttr(SurgeCTtab);
         Surge2=" and "+Surge2;
       }
      else
         Surge2="";
     
      SS+=SurgeI+" "+Surge+Surge2+".  ";
            
     break;
   // --------------------------------------------------------------------------------------
     case 4:  /* Specific table */
        
      SS=RandAttr(SurgeGT)+".  ";
            
     break;
   // --------------------------------------------------------------------------------------
     case 5:  /* Specific table */
        
      SS=RandAttr(SurgeND)+".  ";
      ND=0;
            
     break;
     
   // --------------------------------------------------------------------------------------

   } // end switch
 
   if (ND==1)
   {
      DUR=Math.round(rand(EffectDur.length/4));
      if (rand(10)>5) DUR+=Math.round(rand(EffectDur.length/2));
      if (rand(10)>7) DUR+=Math.round(rand(EffectDur.length/2));
      if (rand(10)>8) DUR=Math.round(EffectDur.length/2+rand(EffectDur.length/2));
 
      SS+="  This will last for "+EffectDur[DUR]+".  ";
    }        
  return SS
}
      
function New_Surge()
{
   SS=Create_Surge();
   selectins.innerHTML=SS;
  
}


// The random number generator.
function rand(n) {
seed = (0x015a4e35 * seed) % 0x7fffffff;
return (seed >> 16) % n;
}

function RandAttr(Tbl)
{
   TE=rand(Tbl.length);
   return Tbl[TE]
/*   return Tbl[Math.Round(Math.Random()*Tbl.length+1)];*/
}

function LoadReady()
{
selectins.innerHTML="Ready!";
Cbutton.innerHTML="";
SHbutton.innerHTML="";
}


function Magic_Mess()
{
DD1="";
i=rand(125)+50;
j=rand(125)+50;
wp=rand(15);

 if(Magic_Mess_Flag==0)
  {
   Magic_Mess_Alert1();
   Magic_Mess_Flag=1;
  }
 else
 if(Magic_Mess_Flag==1)
  {
   Magic_Mess_Alert2();
   Magic_Mess_Flag=2;
  }
 else
 if(Magic_Mess_Flag==2)
  {
   Magic_Mess_Alert3();
   Magic_Mess_Flag=3;
  }
 else
  {
   DD1+="<span style=\'position: absolute; left: "+(i+25)+"; top: "+(j+75)+"\'";
   DD1+="onclick=\'Magic_Mess_Clear()\' ";
   DD1+=">";
   DD1+="<table border=\'0\' cellpadding=\'15\' cellspacing=\'0\' width=\'"+(50+wp)+"%\' bgcolor=\'#FF8F99\' style=\'border-collapse: collapse\'><tr><td>";
   DD1+=SurgeMessage[MMF]+" ["+seed+"]<p>";
   DD1+=Create_Surge();
   DD1+="</p></td></tr></table>";
   DD1+="</span>";   

   selectins.innerHTML=DD1;
   MMF=MMF+1;
   if(MMF>=SurgeMessage.length) MMF=SurgeMessage.length-1;
  }
}

function Magic_Mess_Alert1()
{
 alert("Warning: You are messing with magic!");
}
function Magic_Mess_Alert2()
{
 alert("Really! Those things are magic you're messing with!");
}
function Magic_Mess_Alert3()
{
 alert("Well, you've been warned...!");
}
function Magic_Mess_Clear()
{
      selectins.innerHTML="";  
}

statson=0;
var now = new Date()
var seed = now.getTime() % 0xffffffff
var DD1=""; // empty global
var Magic_Mess_Flag=0;
var MMF=0;




