/* #### do not modify in this section #### */
//Array Format
//[0] - Field Text
//[1] - Answer ID
var arrFs = new Array();
var arrQs = new Array();
var quizName; 
var result;
/* ########  */

quizName = "Eragon: 'What creature are you?' Quiz.";
quizLoc = "http://www.surtugal.netne.net/eragon/whatcreatureareyou.html";


arrQs[0] = "A city guard watches you drop a stack of hay in the street by an accident, while you pick it up he yells at you and demand you to leave the city. Do you:"
arrFs[0] = new Array();
arrFs[0][0] = new Array();
arrFs[0][0][0] = "Do as he says.";
arrFs[0][0][1] = "B";
arrFs[0][1] = new Array();
arrFs[0][1][0] = "Find a higher authority to protest.";
arrFs[0][1][1] = "W";
arrFs[0][2] = new Array();
arrFs[0][2][0] = "Attack the guard.";
arrFs[0][2][1] = "R";
arrFs[0][3] = new Array();
arrFs[0][3][0] = "Pick up the hay and wander into the crowd.";
arrFs[0][3][1] = "U";
arrFs[0][4] = new Array();
arrFs[0][4][0] = "Pick up your hay, leave and use another gate into the city.";
arrFs[0][4][1] = "G";

arrQs[1] = "You found a beautiful woman/man you want to hook up with, but he/she don't seem to notice you.  Do you:";
arrFs[1] = new Array();
arrFs[1][0] = new Array();
arrFs[1][0][0] = "Let it go, because you can't get her anway.";
arrFs[1][0][1] = "B";
arrFs[1][1] = new Array();
arrFs[1][1][0] = "Walk in front of her, bow and say your name while you hold out your hand.";
arrFs[1][1][1] = "G";
arrFs[1][2] = new Array();
arrFs[1][2][0] = "Give her a gorgeous ring.";
arrFs[1][2][1] = "U";
arrFs[1][3] = new Array();
arrFs[1][3][0] = "You never fall in love.";
arrFs[1][3][1] = "R";
arrFs[1][4] = new Array();
arrFs[1][4][0] = "Give him/her the most beautiful flower you can find";
arrFs[1][4][1] = "W";

arrQs[2] = "You and your friend have been cornered by a group of coyotes. Do you:";
arrFs[2] = new Array();
arrFs[2][0] = new Array();
arrFs[2][0][0] = "Draw they're attenrion so your friend can escape";
arrFs[2][0][1] = "W";
arrFs[2][1] = new Array();
arrFs[2][1][0] = "Run away and leave your friend.";
arrFs[2][1][1] = "B";
arrFs[2][2] = new Array();
arrFs[2][2][0] = "There is no friend, you don't have friends, youre alone, so you draw your sword and prepare for batte.";
arrFs[2][2][1] = "R";
arrFs[2][3] = new Array();
arrFs[2][3][0] = "You draw your weapon, and along with your friend you attack the coyotes.";
arrFs[2][3][1] = "U";
arrFs[2][4] = new Array();
arrFs[2][4][0] = "Escape with your friend as fast as you can, cause you don't want to hurt the coyotes.";
arrFs[2][4][1] = "G";

arrQs[3] = "When fighting a mighty dragon rider you see that his dragon's got a wound on it's right back-leg.  Do you:";
arrFs[3] = new Array();
arrFs[3][0] = new Array();
arrFs[3][0][0] = "Finish the rider as fast as you can.";
arrFs[3][0][1] = "R";
arrFs[3][1] = new Array();
arrFs[3][1][0] = "You know that the rider feels pain the same place, so you cut after his right foot.";
arrFs[3][1][1] = "B";
arrFs[3][2] = new Array();
arrFs[3][2][0] = "I don't have a dragon, why would I care about his?";
arrFs[3][2][1] = "U";
arrFs[3][3] = new Array();
arrFs[3][3][0] = "Let him heal his dragon.";
arrFs[3][3][1] = "W";
arrFs[3][4] = new Array();
arrFs[3][4][0] = "Let him take a look at the wound before i attack him again.";
arrFs[3][4][1] = "G";

arrQs[4] = "You find yourself on an uknown iland with alot of unknown humans.  Do you:";
arrFs[4] = new Array();
arrFs[4][0] = new Array();
arrFs[4][0][0] = "Create a house from a tree and eat what you can find.";
arrFs[4][0][1] = "G";
arrFs[4][1] = new Array();
arrFs[4][1][0] = "Etablish order to prevent chaos, ofcource you are the leader.";
arrFs[4][1][1] = "W";
arrFs[4][2] = new Array();
arrFs[4][2][0] = "Slay them down for fast food.";
arrFs[4][2][1] = "B";
arrFs[4][3] = new Array();
arrFs[4][3][0] = "Eat all the remaining food, then start eating the others.";
arrFs[4][3][1] = "R";
arrFs[4][4] = new Array();
arrFs[4][4][0] = "Find yourself a cave, then start creating tools.";
arrFs[4][4][1] = "U";

arrQs[5] = "The kings soliders are demolishing your village looking for a rebel.  Do you:";
arrFs[5] = new Array();
arrFs[5][0] = new Array();
arrFs[5][0][0] = "Make sure the soliders&#8217;s pay for what they destroy.";
arrFs[5][0][1] = "W";
arrFs[5][1] = new Array();
arrFs[5][1][0] = "Make sure the soliders don't destory anything that belongs to you";
arrFs[5][1][1] = "U";
arrFs[5][2] = new Array();
arrFs[5][2][0] = "Silently make sure the soliders never bother anyone aganin";
arrFs[5][2][1] = "G";
arrFs[5][3] = new Array();
arrFs[5][3][0] = "Why bother, they wont dare to touch your house.";
arrFs[5][3][1] = "B";
arrFs[5][4] = new Array();
arrFs[5][4][0] = "Kill them for making noises outside your window.";
arrFs[5][4][1] = "R";

arrQs[6] = " One night at the shipping docks of a port town, you find the keys to a locked storage house.  Do you:";
arrFs[6] = new Array();
arrFs[6][0] = new Array();
arrFs[6][0][0] = "Open the house with great curiosity, hoping to learn the secrets of this mysterious cache.";
arrFs[6][0][1] = "U";
arrFs[6][1] = new Array();
arrFs[6][1][0] = "Open the house, take a look at the stuff inside then leave it unlocked.";
arrFs[6][1][1] = "R";
arrFs[6][2] = new Array();
arrFs[6][2][0] = "Leave the keys where you found them.";
arrFs[6][2][1] = "G";
arrFs[6][3] = new Array();
arrFs[6][3][0] = "Return the missing keys to theyre rightful owner";
arrFs[6][3][1] = "W";
arrFs[6][4] = new Array();
arrFs[6][4][0] = "Change the locks on your new storage house.";
arrFs[6][4][1] = "B";

arrQs[7] = "You are raising your firstborn son.  Do you:";
arrFs[7] = new Array();
arrFs[7][0] = new Array();
arrFs[7][0][0] = "You don't have a son... or a daughter.";
arrFs[7][0][1] = "R";
arrFs[7][1] = new Array();
arrFs[7][1][0] = "Send him off to teach advanced fighting, meditation and magic.";
arrFs[7][1][1] = "W";
arrFs[7][2] = new Array();
arrFs[7][2][0] = "Leave him with your beautiful wife.";
arrFs[7][2][1] = "U";
arrFs[7][3] = new Array();
arrFs[7][3][0] = "Let the kid raise himself&#8212;a couple of hard knocks are good for character.";
arrFs[7][3][1] = "B";
arrFs[7][4] = new Array();
arrFs[7][4][0] = "Teach him everything you know.";
arrFs[7][4][1] = "G";

arrQs[8] = "You&#8217;re an eyewitness to a murder.  Do you:";
arrFs[8] = new Array();
arrFs[8][0] = new Array();
arrFs[8][0][0] = "Have a good laugh over the dead guy.";
arrFs[8][0][1] = "B";
arrFs[8][1] = new Array();
arrFs[8][1][0] = "Hunt down the killer.";
arrFs[8][1][1] = "G";
arrFs[8][2] = new Array();
arrFs[8][2][0] = "Find the killer, then turn him in.";
arrFs[8][2][1] = "W";
arrFs[8][3] = new Array();
arrFs[8][3][0] = "Check if the person is alive, if he isn't, youre yeaving.";
arrFs[8][3][1] = "U";
arrFs[8][4] = new Array();
arrFs[8][4][0] = "Huh? A murder? Why would i care?";
arrFs[8][4][1] = "R";

arrQs[9] = "A man/woman that happens to love you, but you don't like wants to fund the building of your dream house.  Do you:";
arrFs[9] = new Array();
arrFs[9][0] = new Array();
arrFs[9][0][0] = "Provide the blueprints for your palace";
arrFs[9][0][1] = "U";
arrFs[9][1] = new Array();
arrFs[9][1][0] = "Ask him/her to build a church instead.";
arrFs[9][1][1] = "W";
arrFs[9][2] = new Array();
arrFs[9][2][0] = "Build a mountaintop tower, then kill the man/woman.";
arrFs[9][2][1] = "R";
arrFs[9][3] = new Array();
arrFs[9][3][0] = "Tell her that you can't accept his/her offer";
arrFs[9][3][1] = "G";
arrFs[9][4] = new Array();
arrFs[9][4][0] = "Create a stronghold.";
arrFs[9][4][1] = "B";

//Array Format
//[0] - Answer ID
//[1] - Name
//[2] - Icon image
//[3] - Description

var arrC = new Array();
arrC[0] = new Array();
arrC[0][0] = "R";
arrC[0][1] = "Shade";
arrC[0][2] = "/magic/images/whatcolor_red.jpg";
arrC[0][3] = "You are a Shade, you value freedom, impulse, emotion and fire  Your symbol is a fireball.";
arrC[0][4] = "http://www.surtugal.netne.net/eragon/shade.jpg";
arrC[1] = new Array();
arrC[1][0] = "G";
arrC[1][1] = "Elf";
arrC[1][2] = "whatcolor_green.jpg";
arrC[1][3] = "You are an Elf, you value growth, life, adaptation and nature. Your symbol is a tree.";
arrC[1][4] = "http://www.surtugal.netne.net/eragon/elf.jpg";
arrC[2] = new Array();
arrC[2][0] = "U";
arrC[2][1] = "Dwarf";
arrC[2][2] = "whatcolor_blue.jpg";
arrC[2][3] = "You are a Dwarf, you value knowledge, logic, and deceit.  Your symbol is a water droplet."; 
arrC[2][4] = "http://www.surtugal.netne.net/eragon/dwarf.jpg";
arrC[3] = new Array();
arrC[3][0] = "B";
arrC[3][1] = "Urgal";
arrC[3][2] = "whatcolor_black.jpg";
arrC[3][3] = "You are a Urgal, you value power, ambition, and darkness. Your symbol is a skull.";
arrC[3][4] = "http://www.surtugal.netne.net/eragon/urgal.jpg";
arrC[4] = new Array();
arrC[4][0] = "W";
arrC[4][1] = "Dragon rider";
arrC[4][2] = "whatcolor_white.jpg";
arrC[4][3] = "You are a true dragon rider, you value law, order, community and light.  Your symbol is a sunburst.";
arrC[4][4] = "http://www.surtugal.netne.net/eragon/rider.jpg";


/** Do not modify anything below this line **/
var arrV = new Array();
var i;
for (i = 0; i<arrC.length; i++)
    arrV[i] = 0;

function submitForm()
{
    var i;
    var radio;
    var value;
    for (i=1; i<6; i++) {
        radio = getElement("Radio" + i);
        if (radio.checked) 
        { 
            value = radio.value;
            break;
        }
    }
    if (value == null)
    {
        alert("Please select an answer.");
        return;
	}
    for (i=0; i<arrC.length; i++)
    { 
        if (arrC[i][0] == value)
        {         
            arrV[i] = arrV[i] + 1;
            break;
        }
    }
    var number = parseInt(getElement("spnNumber").innerHTML);
    if (number == arrQs.length)
    {
        finalSubmit();
    } 
    else
    { 
        radio.checked = false;
        showQuestion(number);
    }
}

function finalSubmit()
{
    getElement("tblQuiz").style.display = "none";
    getElement("tblResult").style.display = "";
    
    var max = 0;
    var i;
    for (i = 0; i < arrC.length; i++)
    {
        var current = arrV[i];
        if (current > max)
        {
            result = i;
            max = current;
        }
    }
    getElement("tdName").innerHTML = arrC[result][1];
    getElement("imgIcon").src = arrC[result][2];
    getElement("tdDescription").innerHTML = arrC[result][3];
    showBoard();
}

function showQuestion(qnumber)
{
    getElement("spnNumber").innerHTML = qnumber + 1;
    getElement("spnTotal").innerHTML = arrQs.length;
    getElement("tdQuestion").innerHTML = "<b>" + arrQs[qnumber] + "</b>";
    getElement("tdField1").innerHTML = arrFs[qnumber][0][0];
    getElement("Radio1").value = arrFs[qnumber][0][1]; 
    getElement("tdField2").innerHTML = arrFs[qnumber][1][0];
    getElement("Radio2").value = arrFs[qnumber][1][1];
    getElement("tdField3").innerHTML = arrFs[qnumber][2][0];
    getElement("Radio3").value = arrFs[qnumber][2][1];
    getElement("tdField4").innerHTML = arrFs[qnumber][3][0];
    getElement("Radio4").value = arrFs[qnumber][3][1];
    getElement("tdField5").innerHTML = arrFs[qnumber][4][0];
    getElement("Radio5").value = arrFs[qnumber][4][1];
}

function showBoard()
{
    getElement("txtCode").value = ''
    + '[URL=' + quizLoc + '][IMG]' + arrC[result][4] + '[/IMG][/URL]' 
    + '';
    
}

function showHtml()
{
    getElement("txtCode").value = '<p align="center" style="font-family: arial;">'
    + '<a href="' + quizLoc + '" target="_blank">'
    + '<img src="' + arrC[result][4] + '" border="0"><br/>' 
    + '<b>Take the ' + quizName + '</b></a></p>'
}

function showProps(obj,objName) {
    var result = ""
    for (var i in obj) {
        result += objName + "." + i + " = " + obj[i] + "<BR>"
    }
    w = window.open();
    w.document.write(result);
}

function getElement(id)
{
    if ( document.all )
        return document.all[id];
    else if ( document.getElementById )
        return document.getElementById(id);
    else if ( document[id] )
        return document[id];
    else if ( document.layers )
        return document.layers[id];
    else
        return document.id;
}