
/* #### 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 = "Magic: The Gathering 'What Color Are You?' Quiz.";
quizLoc = "http://www.wizards.com/magic/playmagic/whatcolorareyou.asp";


arrQs[0] = "Your teacher or boss yells at you for something you didn’t do, and won’t hear your excuses.  Do you:"
arrFs[0] = new Array();
arrFs[0][0] = new Array();
arrFs[0][0][0] = "Vow the downfall and suffering of this simpleton.";
arrFs[0][0][1] = "B";
arrFs[0][1] = new Array();
arrFs[0][1][0] = "Protest the injustice of the situation to a higher authority.";
arrFs[0][1][1] = "W";
arrFs[0][2] = new Array();
arrFs[0][2][0] = "Throw a raging tantrum, probably destroying something of value in the process.";
arrFs[0][2][1] = "R";
arrFs[0][3] = new Array();
arrFs[0][3][0] = "Analyze the context of the situation until a suitable solution occurs to you.";
arrFs[0][3][1] = "U";
arrFs[0][4] = new Array();
arrFs[0][4][0] = "Go camping.";
arrFs[0][4][1] = "G";

arrQs[1] = "You take a date to an expensive dinner, but your date jabbers into the cell phone all night.  Do you:";
arrFs[1] = new Array();
arrFs[1][0] = new Array();
arrFs[1][0][0] = "Vow the downfall and suffering of this simpleton.";
arrFs[1][0][1] = "B";
arrFs[1][1] = new Array();
arrFs[1][1][0] = "Eat veggies until your stomach swells, and leave the technophile with the bill.";
arrFs[1][1][1] = "G";
arrFs[1][2] = new Array();
arrFs[1][2][0] = "Trick your date into getting off the phone, then use your knowledge of cell phone towers to prevent further calls.";
arrFs[1][2][1] = "U";
arrFs[1][3] = new Array();
arrFs[1][3][0] = "Spontaneously hook up with the host of the restaurant, and spare not another thought to the “date.”";
arrFs[1][3][1] = "R";
arrFs[1][4] = new Array();
arrFs[1][4][0] = "Politely pay for everything and make the best of it for the sake of a peaceful evening.";
arrFs[1][4][1] = "W";

arrQs[2] = "While hiking in the woods, your friend is trapped up a tree by an enormous bear.  Do you:";
arrFs[2] = new Array();
arrFs[2][0] = new Array();
arrFs[2][0][0] = "Valiantly draw the bear’s attention to yourself so your friend can escape.";
arrFs[2][0][1] = "W";
arrFs[2][1] = new Array();
arrFs[2][1][0] = "Quietly gather any nearby valuables before tiptoeing away.";
arrFs[2][1][1] = "B";
arrFs[2][2] = new Array();
arrFs[2][2][0] = "Throw caution to the wind, roll up your sleeves and wrassle that bear till he whines for his mommy.";
arrFs[2][2][1] = "R";
arrFs[2][3] = new Array();
arrFs[2][3][0] = "Break out your trail guide, check the index for the “bear” entry, flip to the “bear” section, read up on this particular species and its feeding habits, and concoct a plan to outwit the bear using your superior intellect.";
arrFs[2][3][1] = "U";
arrFs[2][4] = new Array();
arrFs[2][4][0] = "Puff yourself up as huge as you can, unleash a primal roar from deep within your guts, and show that beast that you’re the bigger bear in this territory.";
arrFs[2][4][1] = "G";

arrQs[3] = "You’re taking a final exam that you haven’t studied for. The paper of the top student in class is plainly visible.  Do you:";
arrFs[3] = new Array();
arrFs[3][0] = new Array();
arrFs[3][0][0] = "Do what I always do: fill in the answers at random and hope for the best.";
arrFs[3][0][1] = "R";
arrFs[3][1] = new Array();
arrFs[3][1][0] = "Take the short-cut to the top—copy down that sucker’s answers and cruise to an easy A.";
arrFs[3][1][1] = "B";
arrFs[3][2] = new Array();
arrFs[3][2][0] = "Um, hello, <i>I’m</i> the top student in class, and of <i>course</i> I studied.";
arrFs[3][2][1] = "U";
arrFs[3][3] = new Array();
arrFs[3][3][0] = "Do the right thing:  Do the best I can with what I know, and tell that top student to cover up her answers so others don’t cheat, either.";
arrFs[3][3][1] = "W";
arrFs[3][4] = new Array();
arrFs[3][4][0] = "Exam? What exam?  I’m listening to the birds singing outside the window.";
arrFs[3][4][1] = "G";

arrQs[4] = "You shipwreck on a uninhabited island with a dozen of your fellow passengers.  Do you:";
arrFs[4] = new Array();
arrFs[4][0] = new Array();
arrFs[4][0][0] = "Feel right at home without all the trappings of modern civilization, and work to minimize your impact on the native ecosystem here in your new home.";
arrFs[4][0][1] = "G";
arrFs[4][1] = new Array();
arrFs[4][1][0] = "Immediately establish a pecking order among the survivors, lest the infighting devolve into chaos.";
arrFs[4][1][1] = "W";
arrFs[4][2] = new Array();
arrFs[4][2][0] = "Immediately establish a pecking order among the survivors, so that you can play them against one another and reap the benefits.";
arrFs[4][2][1] = "B";
arrFs[4][3] = new Array();
arrFs[4][3][0] = "Go swimming, then eat all the remaining food, then go to sleep; these things always work themselves out.";
arrFs[4][3][1] = "R";
arrFs[4][4] = new Array();
arrFs[4][4][0] = "Begin drawing mathematical diagrams in the sand, calculating the probability that you’ll be rescued before your resources run out.";
arrFs[4][4][1] = "U";

arrQs[5] = "A real estate developer wants to demolish the local park to put up a strip mall.  Do you:";
arrFs[5] = new Array();
arrFs[5][0] = new Array();
arrFs[5][0][0] = "Make sure the developer’s permits check out and all his taxes are paid.";
arrFs[5][0][1] = "W";
arrFs[5][1] = new Array();
arrFs[5][1][0] = "Congratulate the developer on his forethought and celebrate the march of progress.";
arrFs[5][1][1] = "U";
arrFs[5][2] = new Array();
arrFs[5][2][0] = "Put on facepaint, hide in the bushes till the bulldozers come, then defend Nature’s lands to the death.";
arrFs[5][2][1] = "G";
arrFs[5][3] = new Array();
arrFs[5][3][0] = "Suggest to the developer that he could make even more money with a little deal on the side.";
arrFs[5][3][1] = "B";
arrFs[5][4] = new Array();
arrFs[5][4][0] = "Smack the dude across the face on principle, just ‘cause he’s an uptight guy in a monkey suit.";
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 container.  Do you:";
arrFs[6] = new Array();
arrFs[6][0] = new Array();
arrFs[6][0][0] = "Open the container 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 container on a whim, hoping to find some guy’s stash of illegal fireworks to shoot off.";
arrFs[6][1][1] = "R";
arrFs[6][2] = new Array();
arrFs[6][2][0] = "Fill the container with soil and turn it into a rustic planter for fast-growing fungi.";
arrFs[6][2][1] = "G";
arrFs[6][3] = new Array();
arrFs[6][3][0] = "Return the missing keys to the lost and found and alert the local constabulary.";
arrFs[6][3][1] = "W";
arrFs[6][4] = new Array();
arrFs[6][4][0] = "Change the locks on my new storage container.";
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] = "Let the kid raise himself—a couple of hard knocks are good for character.";
arrFs[7][0][1] = "R";
arrFs[7][1] = new Array();
arrFs[7][1][0] = "Send him off to the most prestigious military academy in the country, to learn the discipline needed to become a productive member of society.";
arrFs[7][1][1] = "W";
arrFs[7][2] = new Array();
arrFs[7][2][0] = "Home-school him, giving him access to all the multimedia educational resources available.";
arrFs[7][2][1] = "U";
arrFs[7][3] = new Array();
arrFs[7][3][0] = "Train your tiny-brained minion well, so when the time is right, he’ll be ready to rule the empire at your side.";
arrFs[7][3][1] = "B";
arrFs[7][4] = new Array();
arrFs[7][4][0] = "Grab the spouse and get to work on making the next kid.";
arrFs[7][4][1] = "G";

arrQs[8] = "You’re an eyewitness to arson at the university library.  Do you:";
arrFs[8] = new Array();
arrFs[8][0] = new Array();
arrFs[8][0][0] = "Blackmail the arsonist, then turn him in anyway to get in good with the campus police.";
arrFs[8][0][1] = "B";
arrFs[8][1] = new Array();
arrFs[8][1][0] = "Check to be sure the campus gardens aren’t in jeopardy, then empty my backpack of math textbooks onto the pyre.";
arrFs[8][1][1] = "G";
arrFs[8][2] = new Array();
arrFs[8][2][0] = "Chase down the suspect while dialing the authorities.";
arrFs[8][2][1] = "W";
arrFs[8][3] = new Array();
arrFs[8][3][0] = "Enter the burning building to save as much of the classics collection as I possibly can.";
arrFs[8][3][1] = "U";
arrFs[8][4] = new Array();
arrFs[8][4][0] = "Make sure to hide the accelerants before anyone catches me.";
arrFs[8][4][1] = "R";

arrQs[9] = "A reality show 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 engineering blueprints for the hovering mastermind’s tower you’ve worked on for so long.";
arrFs[9][0][1] = "U";
arrFs[9][1] = new Array();
arrFs[9][1][0] = "Honor your community by offering to help the show build an orphanage instead.";
arrFs[9][1][1] = "W";
arrFs[9][2] = new Array();
arrFs[9][2][0] = "Build a mountaintop coliseum and rename yourself Warlord of the Arena.";
arrFs[9][2][1] = "R";
arrFs[9][3] = new Array();
arrFs[9][3][0] = "Demand that your house be grown organically from the native plants of your neighborhood.";
arrFs[9][3][1] = "G";
arrFs[9][4] = new Array();
arrFs[9][4][0] = "Create a subterranean stronghold from which to build your power base, then confiscate all the footage of its construction.";
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] = "Red";
arrC[0][2] = "/magic/images/whatcolor_red.jpg";
arrC[0][3] = "You value freedom, impulse, emotion and fire.  You love instant gratification and acting on your gut feeling.  At your best, you are passionate and decisive.  At your worst, you are shortsighted and destructive.  Your symbol is a fireball.  Your enemies are white and blue.";
arrC[0][4] = "http://www.wizards.com/magic/images/whatcolor_isred.jpg";
arrC[1] = new Array();
arrC[1][0] = "G";
arrC[1][1] = "Green";
arrC[1][2] = "/magic/images/whatcolor_green.jpg";
arrC[1][3] = "You value growth, life, adaptation and nature.  You love to hunt, mate, kill, and eat—to you, that’s all there is.  At your best, you are instinctual and unpretentious.  At your worst, you are vicious and unthinking. Your symbol is a tree.  Your enemies are blue and black.";
arrC[1][4] = "http://www.wizards.com/magic/images/whatcolor_isgreen.jpg";
arrC[2] = new Array();
arrC[2][0] = "U";
arrC[2][1] = "Blue";
arrC[2][2] = "/magic/images/whatcolor_blue.jpg";
arrC[2][3] = "You value knowledge, logic, and deceit.  You love to pursue wisdom but also to manipulate and deceive.  At your best, you are brilliant and progressive.  At your worst, you are treacherous and cold.  Your symbol is a water droplet.  Your enemies are green and red."; 
arrC[2][4] = "http://www.wizards.com/magic/images/whatcolor_isblue.jpg";
arrC[3] = new Array();
arrC[3][0] = "B";
arrC[3][1] = "Black";
arrC[3][2] = "/magic/images/whatcolor_black.jpg";
arrC[3][3] = "You value power, ambition, and darkness.  You love power at any cost, and are a corrupting influence on those around you.  At your best, you are resourceful and unashamed.  At your worst, you are parasitic and amoral. Your symbol is a skull.  Your enemies are white and green.";
arrC[3][4] = "http://www.wizards.com/magic/images/whatcolor_isblack.jpg";
arrC[4] = new Array();
arrC[4][0] = "W";
arrC[4][1] = "White";
arrC[4][2] = "/magic/images/whatcolor_white.jpg";
arrC[4][3] = "You value law, order, community and light.  You love to protect the social order and the rule of law.  At your best, you are just and protective. At your worst, you are authoritarian and dogmatic.  Your symbol is a sunburst.  Your enemies are black and red.";
arrC[4][4] = "http://www.wizards.com/magic/images/whatcolor_iswhite.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 = '[CENTER]'
    + '[IMG]' + arrC[result][4] + '[/IMG]'
    + '[URL=' + quizLoc + '][B]Take the ' + quizName + '[/B][/URL]' 
    + '[/CENTER]';
    
}

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;
}
