/*---------------------------------------------------------

   FILE:  JavaScript/tests/fruit.js	
   AUTH:  Thuy Le			
   DATE:  October 27, 2003
   LMD :  February 2, 2009

   Your Favorite Fruit

0	apple
1	banana
2	black grapes
3	cherry
4	coconut
5	custard apple
6	mango
7	orange
8	papaya
9	peach
10	pear
11	pineapple

----------------------------------------------------------*/

fruit_picked = 0;			// Number of fruit(s) selected.
last_pick = 0;

/*
 *   Process selection of fruit.
 */
function fruitResult( form ) 
{
	person_text = "";
	picked = 0;			// Number of
	total = 12;			// Total number of fruits
	i=0;				// Counter

	while ( i<total && !picked )
	{
		if (form.fruit[i].checked)
		{
			picked++;
			fruit_picked++;
		}
		i++;
	}

	if ( picked && fruit_picked == 1 )
	{
		i--;
		last_picked = i;
		person_text  = "You have selected ";
		person_text += getFruit( i ) + ".\n\n";
		person_text += getResult( i );
	}
	else if ( fruit_picked > 1 )
	{
		person_text  = "You already picked a fruit; it was "
		person_text += getFruit( last_picked );
		person_text += ". Please press 'Reset' to select another fruit.\n\n";
		person_text += getResult( last_picked );
		form.fruit[last_picked].checked = true
	}
	else
		person_text = "You did not pick any fruit!";

	document.forms[0].displayFruit.value = person_text;

} 

/*
 *   Returns name of selected fruit.
 */
function getFruit ( sel )
{
	switch ( sel )
	{
		case 0: return "apple"; break;
		case 1: return "banana"; break;
		case 2: return "black grapes"; break;
		case 3: return "cherry"; break;
		case 4: return "coconut"; break;
		case 5: return "custard apple"; break;
		case 6: return "mango"; break;
		case 7: return "orange"; break;
		case 8: return "papaya"; break;
		case 9: return "peach"; break;
		case 10: return "pear"; break;
		case 11: return "pineapple"; break;
	}
}

/*
 *   Returns result.
 */
function getResult ( sel )
{
	result = "";

	switch ( sel )
	{
		case 0:	// apple
			result = "You are an extravagant, impulsive and outspoken person; "
			+ "often with a bit of a temper. While you may not be the best "
			+ "orangizer yourself, you make a good team leader; and are good "
			+ "at taking things forward. You can take quick action in most "
			+ "situations. You enjoy travel immensely. You ooze with charm "
			+ "when you are with your partner. You have an enthusiasm for "
			+ "life, unmatched by most.";
			break;
		case 1: // banana
			result = "You are a softie! Loving, gentle, warm and sympathetic by nature "
			+ "is the banana lover. You often lack in self-confidence and are "
			+ "quite timid by nature. People often take advantage of your sweet "
			+ "temperedness, and sheer vulnerability to a situation. You adore "
			+ "your partner in every which way, both for their mental and physical "
			+ "beauty! Because of the way you are, your relationship is always, "
			+ "very much in harmony!";
			break;
		case 2: // black grapes
			result = "You are a polite person in general, but do have quick flare-ups "
			+ "of temper that cool down just as quickly. You enjoy beauty in all forms, "
			+ "including beautiful people. You are very popular because of your warm, "
			+ "gregarious nature. You have a zest for life; you enjoy every thing you "
			+ "do, right from the way you dress, to your style and in your day-to-day "
			+ "life. Your partner must share your zeal and zing for life to enjoy all "
			+ "you have to offer!";
			break;
		case 3: // cherry
			result = "If cherry is your favorite fruit, life isn't always as sweet "
			+ "for you. You often face ups and downs, particularly professionally; "
			+ "and find that you make small sums of $$$, instead of a lump sum. You "
			+ "have a fertile imagination and are often involved in creative pursuits. "
			+ "You are a very sincere and loyal partner; but find that expressing your "
			+ "feelings is not very easy. Your home is your haven, and you love nothing "
			+ "more than being surrounded by close family and your beloved partner.";
			break;
		case 4: // coconut
			result = "The coconut lover is a serious, very thoughtful and contemplative "
			+ "person. Though you enjoy socializing, you are particular about the "
			+ "company you keep. You tend to be stubborn but not necessarily foolhardy. "
			+ "Shrewd, quick-witted and alert, you ensure that you are right on top of "
			+ "any given scenario, especially at work. You need a partner with brains, "
			+ "and while passion is important it certainly isn't everything for you.";
			break;
		case 5: // custard apple
			result = "You are a modest and conservative person; who can be quite sensitive "
			+ "at times. You tend to be thoughtful and contemplative, and therefore are "
			+ "rarely rash in doing things. You are quite ambitious; and are good at "
			+ "anything that requires much detailing or working with numbers. You are "
			+ "quick at finding fault with others. While looking for a partner, you "
			+ "value a person's intellect far above their looks or good old passion. "
			+ "You're quite shy and not comfortable demonstrating affection.";
			break;
		case 6: // mango
			result = "A mango lover is a personality to be reckoned with; quite often "
			+ "you are a person who has quite fixed ideas, and influencing you is no "
			+ "easy task. You tend to be an extremist with strong likes and dislikes; "
			+ "and at times even like to control a situation. You enjoy getting involved "
			+ "in something that presents mental challenge. Strong as you may be, you "
			+ "are like a kitten when you are with your partner. You accommodate the "
			+ "love of your life, and make up for all the strong will elsewhere!";
			break;
		case 7: // orange
			result = "If orange is your favorite fruit; it speaks of a person who has "
			+ "enduring patience and willpower. You like to do things slowly; but very "
			+ "thoroughly and are completely undaunted by hard work. You tend to be shy; "
			+ "but are a reliable and trustworthy friend. You have an aesthetic bent of "
			+ "mind. You select your partner with care and you love with all your heart, "
			+ "and are not in for just a fling. You avoid conflict at all costs.";
			break;
		case 8: // papaya
			result = "You are truly fearless and take much that happens in life, in your "
			+ "stride. You give considerable thought to things you do. You have a sense "
			+ "of humour that along with your generous nature keeps you in most people's "
			+ "good books. You are a go-getter in your professional life, and have a knack "
			+ "for being in the right place at the right time. You enjoy meeting new people "
			+ "and seeing new sights whenever you can. Your sense of humour is what "
			+ "attracts members of the opposite sex to you more than anything else. It is "
			+ "simply charming!";
			break;
		case 9: // peach
			result = "Like a peach, you enjoy the juice of life it all its lush ripeness! "
			+ "You are the friendly sort, and are quite frank and outspoken, which adds "
			+ "to your charm. You are quick to forgive and forget; and value your "
			+ "friendships highly. You have an independent and ambitious streak in you, "
			+ "that makes you a real go-getter. You are the ideal lover, fiery and "
			+ "passionate but sincere and faithful in love. You don't however like to "
			+ "display all that passion in public.";
			break;
		case 10: // pear
			result = "If you put your mind to something you can do it successfully, but "
			+ "by and large you tend to be fickle and have trouble completing a task "
			+ "with the enthusiasm you started it with. You need to know the results of "
			+ "your efforts almost immediately. You enjoy mental stimulation and love "
			+ "to get into a good discussion. You tend to be a restless and high-strung "
			+ "person, and are easily excitable. While you are quick to strike up a "
			+ "friendship with someone, maintaining it does not seem to be easy for you.";
			break;
		case 11: // pineapple
			result = "You are quick to decide and even quicker to act. You are brave in "
			+ "making career changes; if that is what is to your advantage. You have "
			+ "exceptional organizing abilities and are undaunted by the size of the "
			+ "task at hand. You tend to be self reliant, sincere and honest in your "
			+ "dealings with others. Though you are not given to making friends very "
			+ "quickly, but once you do, it is for life. You rarely, if ever, make "
			+ "romantic overtures. Your partner is often impressed with your sterling "
			+ "qualities but disappointed in your ability to show affection.";
			break;
	}
	return result;
}


