/*

* Use http://dean.edwards.name/packer/ to compress this file and produce moneywise_c.js

* (enable 'Base62 encode' and 'Shrink variables')

*/



/*

* Schwab MoneyWise sitewide script

*

* Author: Kyle DeLong

*

* Requires:

* Overlay

* Poll

* Google Search

*	AJAX API key:	ABQIAAAAGCJTqlEsjlWoauWOokDlrxROPDTO1SZVP_RtqNHAq5n2OmLB5BQ5hk8ZDoxOVIUp6bsK9GtGU-KE8g

*	Site search id:	009571345167962076802:99tqbixyqte

*/

google.load("search", "1", {'nocss': true});





/*

* REMOVE the next line if ever implementing Google Analytics.  It is here because

* some old calcs call the function, and the site currently DOES NOT use Google Analytics.

*/

if (typeof urchinTracker != "function") urchinTracker = $empty;



window.addEvent(Browser.Engine.trident ? "load" : "domready", new MoneyWise(typeof mw_root == "undefined" ? null : mw_root).init);



function MoneyWise(mw_root) {

	var config							= new Array();

	var global							= new Array();



	/*

	* Schwab MoneyWise configuration

	* any durations, delays, etc. are in milliseconds

	*/

	config["mw_root"]					= $pick(mw_root, "") + "/";



	config["overlay_fadeDuration"]		= 200;

	config["overlay_fadeOpacity"]		= 0.7;



	config["form_error_message"]		= "There was a communications error and your request was not submitted successfully.\nPlease try again - the information you've entered is still there for you to submit.\n\nIf this problem persists, please copy your information and try submitting it again later.";

	config["error_color"]				= "#3E647E";



	config["external_link_expression"]	= "schwab";



	config["google_api_key"]			= "ABQIAAAAGCJTqlEsjlWoauWOokDlrxROPDTO1SZVP_RtqNHAq5n2OmLB5BQ5hk8ZDoxOVIUp6bsK9GtGU-KE8g";

	config["google_cse_id"]				= "009571345167962076802:99tqbixyqte";



	/*

	* global variables - for internal script use only, do not modify

	*/

	global["speedbump_href"]			= null;





	/*

	* public (this.*) & private (var *) methods

	*/

	this.init = function() {

		mw_sIFR();

		main();

		search();

	};



	var mw_sIFR = function() {

		if(typeof sIFR == "function") {

			var sIFR_groups = [

				{

					'fontFile': config["mw_root"] + "common/flash/heading.swf",

					'color': "#FFFFFF",

					'selector': ".hubBanner h1, .promo .title, .boxTitle, .tips_dialog h1"

				},

				{

					'fontFile': config["mw_root"] + "common/flash/heading.swf",

					'color': "#c3b183",

					'selector': "#askCarrie_fail h1, #askCarrie_thankYou h1"

				},

				{

					'fontFile': config["mw_root"] + "common/flash/subheading.swf",

					'color': "#c3b183",

					'selector': ".hubBanner h2, .hero h2"

				},

				{

					'fontFile': config["mw_root"] + "common/flash/subheading.swf",

					'color': "#FFFFFF",

					'selector': ".boxSubTitle"

				}

			];



			sIFR_groups.each(function(group, i) {

				sIFR.replaceElement(group.selector, named({sFlashSrc: group.fontFile, sColor: group.color, sWmode: "transparent"}));

			});

		};

	};



	var search = function() {

		var searchResults = $("searchResults");



		searchResults.setStyle("opacity", 0);

		searchResults.store("fx", new Fx.Tween(searchResults, {'duration': config["overlay_fadeDuration"]}));



		var showSearchBox = function() {

			searchResults.getElement(".loader").setStyle("display", "");

			searchResults.getElement(".noResults").setStyle("display", "");

			searchResults.getElements("li.result, li.more").dispose();

			searchResults.retrieve("fx").start("opacity", 1);

		};

		var hideSearchBox = function() {

			searchResults.retrieve("fx").start("opacity", 0);

		};



		document.addEvent("click", function(e) {

			if (e.target != $("searchWrap") && !$("searchWrap").hasChild(e.target))

				hideSearchBox();

		});



		var populateSearchBox = function(search) {

			var resultElements = new Array();



			search.results.each(function(result, i) {

				var li		= new Element("li",		{'class': "result"});

				var title	= new Element("a",		{'class': "title", 'html': result.title, 'href': result.url});

				var content	= new Element("div",	{'class': "content", 'html': result.content});



				if (i == 0)

					li.addClass("first");



				if (i == search.results.length-1)

					li.addClass("last");



				li.adopt(title, content);



				resultElements.push(li);

			});



			if (search.results.length == 0)

				searchResults.getElement(".noResults").setStyle("display", "inline");



			searchResults.getElement(".loader").setStyle("display", "none");

			searchResults.adopt(resultElements);



			// quick & dirty, not much time...

			if (search.cursor.estimatedResultCount > 4)

				new Element("img", {'src': config["mw_root"] + "images/buttons/btn-moreResults.gif", 'alt': "More Results", 'styles': {'cursor': "pointer"}}).addEvents({

					'click': function() {

						window.location = "/search?q=" + $("google_cse").q.value;

					}

				}).inject(new Element("li", {'class': "more", 'styles': {'text-align': "right"}}).inject(searchResults));

		};



		var search = new google.search.WebSearch();

		search.setSiteRestriction(config["google_cse_id"]);

		search.setNoHtmlGeneration();



		search.setSearchCompleteCallback(this, function() {

			populateSearchBox.delay(200, this, [search]);

		});



		$("google_cse").addEvent("submit", function(e) {

			new Event(e).stop();



			if (this.q.value.trim().length == 0)

				return;



			showSearchBox();

			search.execute(this.q.value);

		});

	};



	var main = function() {

		/*

		*Sliders

		*/

		multislide = new multislide('ms_container', {

			slide_duration:			300,

			slide_transition: 		'quint:out',

			class_toggler: 			'control',

			

			onExpand: function(el){

				//el.set('html', 'See Less');

				el.set('class', 'control selected');

				$(el).getElements('div')[0].set('style', 'display: block;');

			},

			

			onCollapse: function(el){

				//el.set('html', 'See More');

				el.set('class', 'control');

				$(el).getElements('div')[0].set('style', 'display: none;');

			}

			

			

		});

		

		if (_printServer == true)

		{

			multilside.expand_all();

		}

		

		/*

		* tabs

		*/

		$$(".js_tabSwitch").addEvents({

			'click': function() {

				this.className = this.className.replace("TSTabSel", "TSTab");

				this.className = this.className.replace("TSTab", "TSTabSel");

				$(this.id + "Contents").setStyle("display", "block");

				$$(".js_tabSwitch").each(

					function(item, n) {

						if (item != this) {

							item.className = item.className.replace("TSTabSel", "TSTab");

							$(item.id + "Contents").setStyle("display", "none");

						}

					},

					this

				);

				var defaultTab = Cookie.read("defaultTab");

				if ($defined(defaultTab) && $defined($("defaultTab")))

					$("defaultTab").checked = defaultTab == this.id ? true : false;

			}

		});

		

		 /* Read query string tab and set */

		var selectedTab = gup('tab');

		if (selectedTab != "")

		{

			

			$$(".js_tabSwitch").each(

					function(item, n) {

						

						if (item != this) {

							item.className = item.className.replace("TSTabSel", "TSTab");

							$(item.id + "Contents").setStyle("display", "none");

						}

						else

						{

							item.className = item.className.replace("TSTabSel", "TSTab");

							item.className = item.className.replace("TSTab", "TSTabSel");

							$(item.id + "Contents").setStyle("display", "block");

						}

					},

					$(selectedTab)

				);

		}

    



		

		

		/*

		* Overlay for use with speedbump and other functionality that may need it

		*/

		global["overlay"] = new Overlay.Screen({

			'opacity':	config["overlay_fadeOpacity"],

			'effect': {

				'duration': config["overlay_fadeDuration"]

			},

			'styles': {

				'min-width': $("mainWrap").getSize().x

			}

		});



		global["overlay"].addEvent("visible", function() {

			global["currentDialog"].fade("in");

		});



		/*

		* speedbump

		*/

		if ($defined($("speedbump"))) {

			global["speedbump"] = new Overlay.Dialog($("speedbump"), {'effect': {'duration': config["overlay_fadeDuration"]}});

			$("speedbump").setStyle("opacity", 0);

			$("speedbump").getElement(".btn_ok").addEvent("click", function() {

				//window.location = global["speedbump_href"];

				window.open(global["speedbump_href"],"","");

				global["speedbump"].fade("hide");

			});

			$("speedbump").getElement(".btn_cancel").addEvent("click", function() {

				global["speedbump"].fade("hide");

			});

			global["speedbump"].addEvent("hidden", function() { global["overlay"].fade("out"); });

		}



		/*

		* External link hook

		*/

		$$("a").addEvents({

			'click': function(e) {

				if (!this.protocol.test("javascript")

					&& !this.hasClass("nospeedbump")

					&& this.hostname.length > 0

					&& this.hostname != location.hostname

					&& !this.hostname.test(config["external_link_expression"])

				) {

					new Event(e).stop();

					global["speedbump_href"] = this.href;

					global["currentDialog"] = global["speedbump"];

					this.blur();

					global["overlay"].fade("in");

				}

			}

		});





		/*

		* Home page only section

		*/

		if ($defined($("contentHome"))) {

			/*

			* Tips dialog

			*/

			if ($defined($("tips"))) {

				document.getElement(".box186_home .tips").setStyle("display", "block");

				document.getElement(".box186_home .tips a").addEvents({

					'click': function(e) {

						global["currentDialog"] = global["tips"];

						this.blur();

						global["overlay"].fade("in");

					}

				});



				var resetTips = function(clearFields) {

					if (!$defined(clearFields))

						var clearFields = false;



					var submit	= $("tips").getElement(".controls .btn_submit").getParent();

					var loader	= $("tips").getElement(".controls .loader");



					submit.setStyles({

						'opacity': 1,

						'width': ""

					});

					loader.setStyle("display", "");



					if (clearFields) {

						// only clear content as the user would probably not change their email

						$("tip_content").setProperty("value", "");

					}



					$$("#tip_email, #tip_content").setProperty("disabled", "").setStyle("background-color", "");

				};



				$("tips").getElement(".form").addEvent("submit", function(e) {

					new Event(e).stop();



					var email	= $("tip_email").value;

					var tip		= $("tip_content").value;



					var submit	= $("tips").getElement(".controls .btn_submit").getParent();

					var loader	= $("tips").getElement(".controls .loader");



					{	// validations

						var invalid_ids = [];



						if (!isValidInput(email, "email"))

							invalid_ids.push("#tip_email");

						if (!isValidInput(tip, "text"))

							invalid_ids.push("#tip_content");



						if (invalid_ids.length > 0) {

							$$(invalid_ids.join(",")).highlight(config["error_color"]);

							return;

						}

					}



					var doSubmit = function() {



						var form	= $("tips_form");

						var action	= form.getProperty("action");



						new Request.HTML({'async': false}).addEvent("complete", function(tree, elements, html, js) {

							if (html)

								form.getElement(".key").setProperty("value", html.trim());

						}).get(action);



						// submit form here

						form.get("send").removeEvents().addEvents({

							'success': function(response) {

								/*

								* as dictated by the usual programming standards:

								*	0 = success

								*	1 = failure

								*/

								switch (response.trim()) {

									case "0":

										global["tips"].fade("hide", false);

										global["tips_done"].fade("in");

									break;

									case "1":

									default:

										this.fireEvent("failure");

									break;

								}

							},

							'failure': function() {

								global["tips"].fade("hide", false);

								global["tips_fail"].fade("in");

							}

						});

						form.send();

					};



					var fadeSubmit = function() {

						new Fx.Tween(submit, {'duration': 200, 'transition': Fx.Transitions.Quad.easeOut}).start("opacity", 0).chain(

							function() { this.start("width", 0); },

							function() { loader.setStyle("display", "block"); doSubmit.delay(900); }

						);

					};



					$$("#tip_email, #tip_content").setProperty("disabled", "true").setStyle("background-color", "#e0dfe3");



					fadeSubmit.delay(200, this);

				});



				$("tips").getElement(".btn_cancel").addEvent("click", function(e) {

					new Event(e).stop();



					resetTips();



					global["tips"].fade("hide");

				});



				$("tips_done").getElement(".btn_close").addEvent("click", function() {

					global["tips_done"].fade("hide");

					resetTips(true);

				});



				$("tips_fail").getElement(".btn_cancel").addEvent("click", function() {

					global["tips_fail"].fade("hide");

					resetTips();

				});

				$("tips_fail").getElement(".btn_tryagain").addEvent("click", function() {

					resetTips();

					global["tips_fail"].fade("hide", false);

					global["tips"].fade("in");

				});



				global["tips"] = new Overlay.Dialog($("tips").setStyle("opacity", 0), {'effect': {'duration': config["overlay_fadeDuration"]}}).addEvents({

					'hidden': function() { global["overlay"].fade("out"); },

					'visible': function() { $("tip_email").focus(); }

				});

				global["tips_done"]	= new Overlay.Dialog($("tips_done").setStyle("opacity", 0), {'effect': {'duration': config["overlay_fadeDuration"]}}).addEvent("hidden", function() { global["overlay"].fade("out"); });

				global["tips_fail"]	= new Overlay.Dialog($("tips_fail").setStyle("opacity", 0), {'effect': {'duration': config["overlay_fadeDuration"]}}).addEvent("hidden", function() { global["overlay"].fade("out"); });

			}



			/*

			* Poll

			*/

			if ($defined($("pollContainer"))) {

				var poll = new Poll($("pollContainer"), {url: "/.poll/poll_55533d701b2611df8a390800200c9a66.php", loader: {'class': "loader", 'alt': "loader", 'src': "/images/loader.gif", 'width': "16", 'height': "16"}}).addEvents({

					'display': function() {

						var poll = this;

						this.getElement().getElements(".answer").addClass("clickable");

						this.getElement().getElements(".answer").addEvents({

							'click': function() {

								poll.element.getElements(".answer").removeClass("answerSelected");

								this.addClass("answerSelected");

							}

						});



						this.element.getElement(".submit").addEvents({

							'click': function() {



								var answer = poll.element.getElement(".answerSelected");



								if ($defined(answer)) {

									poll.submit(answer.retrieve("poll_index"));

								}

								else {

									poll.showMessage("Please make a selection above.");

								}

							}

						});

					},

					'result': function() {



						var plural = function(i) {

							return (i != 1 ? "s" : "");

						};



						var answers_dom		= this.getElement().getElements(".answer");

						var answers_poll	= this.getJSON().answer;

						var total			= this.getTotal();

						var loaderEvent		= false;



						answers_dom.removeClass("clickable");



						var behavior	= {

							'spacer':	{},

							'bar':		{}

						};



						answers_dom.each(function(answer, i) {



							var result = new Element("tr", {'class': "result"});

							new Element("td").inject(result);

							result.inject(answer, "after");



							var value			= answers_poll[answer.retrieve("poll_index")].value;

							var percent			= (value / total) * 100;

							var barContainer	= new Element("div", {'class': "progressBar", 'styles': {'display': "none"}});

							var bar				= new Element("div", {'class': "progress"}).inject(barContainer);



							var barBorder		= new Element("div", {'class': "border"});

							new Element("div", {'class': "cap_right"}).inject(new Element("div", {'class': "cap_left"}).inject(barBorder));

							barBorder.inject(bar, "after");



							var labelHTML		= value.toString() + " vote" + plural(value) + " (" + percent.round(2).toString() + "%)";

							var label			= new Element("div", {'class': "pollLabel",'html': labelHTML});



							label.inject(barContainer);

							label.clone().inject(bar);



							barContainer.inject(result.getElement("td"));

							barContainer.store("percent", percent);



							behavior.spacer[i.toString()]	= {'height': "18px"};

							behavior.bar[i.toString()]		= {'width': percent};

						});





						var results_dom = this.getElement().getElements(".progressBar");

						var bar_dom		= this.getElement().getElements(".progressBar .progress");



						var fx_bar		= new Fx.Elements(bar_dom, {unit: "%", duration: 800}).addEvent("complete", function() {

							poll.hideLoader();

						});



						results_dom.setStyle("display", "block");



						fx_bar.start(behavior.bar);



					}

				});

				poll.start();



				/*

				* rotator numbers

				*/

				$("ask_ajax").store("request", new Request.HTML({evalScripts: false, url: "/"}).addEvent("complete", function(tree, elements, html, js) {

					$("ask_ajax").innerHTML = unescape(html);

				}));

				$$("#numbers a").addEvents({

					'click': function(e) {

						new Event(e).stop();



						$$("#numbers a").each(function(element, i) { element.removeClass("on"); });

						this.addClass("on");



						$("ask_ajax").retrieve("request").cancel().get({"ajax": 1, "cid": this.href.split("=")[1]});

					}

				});

			}

			



			/*

			* Calculator (compound interest)

			*/

			$("calc_btn_calculate").addEvents({

				'click': function() {



					// future value of an annuity

					function getFutureValue(principal, APR, period, duration, contribution) {

						if (!isNumeric(principal + APR + period + duration + contribution))

							return false;



						var periodicAPR = APR / 100 / period;



						if (periodicAPR == 0)

							return principal + (contribution * period * duration);



						return ( ( Math.pow((1 + periodicAPR),(period*duration)) ) * principal ) + ( contribution * ( ( Math.pow((1 + periodicAPR),(period*duration)) - 1) / (periodicAPR) ) );

					};



					var invalid = new Array();



					[$("calc_APR"), $("calc_duration"), $("calc_contribution")].each(function(el, i) {

						if (!isValidInput(el.value, "number"))

							invalid.push(el);

					});



					if (invalid.length > 0) {

						invalid.each(function(el, i) {

							el.highlight(config["error_color"]);

						});

						return;

					}



					var result = getFutureValue(0, $("calc_APR").value, 12, $("calc_duration").value, $("calc_contribution").value);



					if (typeof result == "boolean" || isNaN(result))

						alert("Calculator Error: please enter only numeric values.");

					else

						$("calc_result").innerHTML = result.round(2);

				}

			});

		}

		// END home page only section



		/*

		* Ask Carrie form

		*/

		if ($defined($("askCarrie_form")) && $defined($("askCarrie_thankYou"))) {



			$$(".talkBubble_top .talkBubble_top").setStyle("opacity", 0);



			var resetAskCarrie = function() {

				$("askCarrie_form").getElement(".loader").fade("hide");

			};



			$("askCarrie_fail").getElement(".btn_tryagain").addEvent("click", function() {

				resetAskCarrie();

				$("askCarrie_fail").fade("hide");

				$("askCarrie_form").fade("in");

			});



			$("askCarrie_form").addEvent("submit", function(e) {

				new Event(e).stop();



				var textarea	= $("askCarrie_form").getElement("textarea");



				// validate input

				if (textarea.value.trim().length == 0) {

					textarea.highlight(config["error_color"]);

					return;

				}



				$("askCarrie_form").getElement(".loader").fade("show");



				var doSubmit = function() {



					var form		= $("askCarrie_form");

					var action		= form.getProperty("action");



					new Request.HTML({'async': false}).addEvent("complete", function(tree, elements, html, js) {

						if (html)

							form.getElement(".key").setProperty("value", html.trim());

					}).get(action);



					// submit form here

					form.get("send").removeEvents().addEvents({

						'success': function(response) {

							/*

							*	0 = success

							*	1 = failure

							*/

							switch (response.trim()) {

								case "0":

									form.fade("hide");

									$("askCarrie_thankYou").fade("in");

								break;

								case "1":

								default:

									this.fireEvent("failure");

								break;

							}

						},

						'failure': function() {

							form.fade("hide");

							$("askCarrie_fail").fade("in");

						}

					});

					form.send();

				};



				doSubmit.delay(900);



			});

		}



		/*

		* 'Email Friend' form

		*/

		if ($defined($("emailFriend"))) {



			var emailFriend = $("emailFriend");

			emailFriend.addEvent("submit", function(e) {

				new Event(e).stop();



				//validations

				var invalid = new Array();



				[this.user_name, this.recipient_name, this.user_message].each(function(el, i) {

					if (!isValidInput(el.value, "text"))

						invalid.push(el);

				});

				[this.user_email, this.recipient_email].each(function(el, i) {

					if (!isValidInput(el.value, "email"))

						invalid.push(el);

				});



				if (invalid.length > 0) {

					invalid.each(function(el, i) { $(el).highlight(config["error_color"]); });

					return;

				}



				var resetFriend = function() {

					$("emailFriend").getElement(".loader").setStyle("display", "");

					$("emailFriend").getElements("input, textarea").setProperty("disabled", "").setStyle("background-color", "");

				};



				var doSubmit = function() {



					var form		= $("emailFriend");

					var action		= form.getProperty("action");



					new Request.HTML({'async': false}).addEvent("complete", function(tree, elements, html, js) {

						if (html)

							form.key.setProperty("value", html.trim());

					}).get(action);



					// submit form here

					form.get("send").removeEvents().addEvents({

						'success': function(response) {

							/*

							*	0 = success

							*	1 = failure

							*/

							switch (response.trim()) {

								case "0":

									window.location = "emailFriend_thankYou.php?friend=" + escape(form.recipient_name.value);

								break;

								case "1":

								default:

									this.fireEvent("failure");

								break;

							}

						},

						'failure': function() {

							resetFriend();

							alert(config["form_error_message"]);

						}

					});

					form.send();

				};



				emailFriend.getElements("input, textarea").setProperty("disabled", "true").setStyle("background-color", "#e0dfe3");

				emailFriend.getElement(".loader").setStyle("display", "block");

				doSubmit.delay(900);

			});

		}

		

		/*

		* Landing Pages Image

		*/

		

		if($defined($("bubbleWrap"))) {

			var bubbleWrap = $("bubbleWrap");

			var footer = $("footWrap");

			

			var spring = $("spring");

			spring.style.height = (footer.getCoordinates().top - (bubbleWrap.getCoordinates().top + bubbleWrap.getCoordinates().height) + 16)  + "px";

		}

		

		/*

		* LinkedIn URL JS

		*/

		if ($defined($("linkedin"))) {

			$("linkedin").set('href', $("linkedin").get('href').replace('{articleUrl}', window.location.href));

			$("linkedin").set('href', $("linkedin").get('href').replace('{articleTitle}', document.title));

		}

		

		/*

		*  Twitter

		*/

		if ($defined($("twitter"))) {

			$("twitter").set('href', $("twitter").get('href').replace('{tweet}', window.location.href));

		}

		

		/*

		*  FaceBook

		*/

		if ($defined($("facebook"))) {

			$("facebook").set('href', $("facebook").get('href').replace('{faceURL}', window.location.href));

			$("facebook").set('href', $("facebook").get('href').replace('{faceTitle}', document.title));

		}

		

		/*

		*  del.icio.us

		*/

		if ($defined($("del"))) {

			$("del").set('href', $("del").get('href').replace('{delURL}', window.location.href));

			$("del").set('href', $("del").get('href').replace('{delTitle}', document.title));

		}

		

		/*

		*  Google Bookmark

		*/

		if ($defined($("googlebkm"))) {

			$("googlebkm").set('href', $("googlebkm").get('href').replace('{googleURL}', window.location.href));

			$("googlebkm").set('href', $("googlebkm").get('href').replace('{googleTitle}', document.title));

		}

		

		/*

		*  Yahoo Buzz

		*/

		if ($defined($("yahooBuzz"))) {

			$("yahooBuzz").set('href', $("yahooBuzz").get('href').replace('{yahooURL}', window.location.href));

		}



		/*

		* Feedback form

		*/

		if ($defined($("feedback"))) {

			var feedback = $("feedback");

			feedback.addEvent("submit", function(e) {

				new Event(e).stop();



				//validations

				var invalid = new Array();



				if (!isValidInput(this.user_email.value, "email"))

					invalid.push(this.user_email);

				if (!isValidInput(this.user_message.value, "text"))

					invalid.push(this.user_message);



				if (invalid.length > 0) {

					invalid.each(function(el, i) { $(el).highlight(config["error_color"]); });

					return;

				}



				var resetFeedback = function() {

					$("feedback").getElement(".loader").setStyle("display", "");

					$("feedback").getElements("input, textarea").setProperty("disabled", "").setStyle("background-color", "");

				};



				var doSubmit = function() {



					var form		= $("feedback");

					var action		= form.getProperty("action");



					new Request.HTML({'async': false}).addEvent("complete", function(tree, elements, html, js) {

						if (html)

							form.key.setProperty("value", html.trim());

					}).get(action);



					// submit form here

					form.get("send").removeEvents().addEvents({

						'success': function(response) {

							/*

							*	0 = success

							*	1 = failure

							*/

							switch (response.trim()) {

								case "0":

									window.location = "thankyou.php";

								break;

								case "1":

								default:

									this.fireEvent("failure");

								break;

							}

						},

						'failure': function() {

							resetFeedback();

							alert(config["form_error_message"]);

						}

					});

					form.send();

				};



				feedback.getElements("input, textarea").setProperty("disabled", "true").setStyle("background-color", "#e0dfe3");

				feedback.getElement(".loader").setStyle("display", "block");

				doSubmit.delay(900);

			});

		}

	};



	var isValidInput = function(inputValue, type) {

		switch (type) {

			case "email":

				return inputValue.toUpperCase().test("^[A-Z0-9._%+-]+@[A-Z0-9.-]+[.][A-Z]{2,4}$");

				break;

			case "text":

				return inputValue.trim().length > 0;

				break;

			case "number":

				return isNumeric(inputValue);

				break;

			default:

				return true;

		}

	};



	var isNumeric = function(i) {

		var i = new String(i);

		return (!isNaN(i*1) && i.trim().length > 0);

	};

}



function gup( name )

{

  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

  var regexS = "[\\?&]"+name+"=([^&#]*)";

  var regex = new RegExp( regexS );

  var results = regex.exec( window.location.href );

  if( results == null )

    return "";

  else

    return results[1];

}



/*

	MultiSlide, version 1.0

	(c) 2009 Intereactive, LLC - Ryan Hargrave

	http://blueprint.intereactive.net/multislide-for-mootools

	

	Compatible with Mootools v1.2 - http://mootools.net

	Extends the capability of the Fx.Slide Class  - http://mootools.net/docs/Plugins/Fx.Slide

	

	This code is freely distributable under the terms of an MIT-style license.

*/



var multislide = new Class({

	

	Implements: [Events, Options],



	options: {

		/*

		onExpand: $empty,

		onCollapse: $empty, 

		onExpand_all: $empty, 

		onCollapse_all: $empty, 

		*/  

		slide_duration:			300,

		slide_transition: 		'sine:in:out',

		class_expand_all: 		'expand_all',

		class_collapse_all: 	'collapse_all',

		class_toggler: 			'ms_toggler',

		class_expander: 		'ms_expander'

	},

	

	//sets up the animations for the team layout

	initialize: function(container_class, options) {

		this.setOptions(options);

		

		//set empty array to hold all the sliders

		this.person_slide = [];

		

		//create the sliders and set up event listeners

		$$('.'+container_class).each(function(container, i){

			

			var toggler = container.getElement('.'+this.options.class_toggler);

			

			//set up the slide instance for each element and hide all the sliders								  

			this.person_slide[i] = new Fx.Slide(container.getElement('.'+this.options.class_expander), {

					duration: this.options.slide_duration, 

					transition: this.options.slide_transition, 

					link : 'ignore',

					onStart : function(){

						if(this.person_slide[i].open){

							this.fireEvent('collapse', toggler);

						} else {

							this.fireEvent('expand', toggler);

						}

					}.bind(this)

			}).hide();

			

			//add the toggle slide event		

			toggler.addEvent('click', function(e){

					e.stop();

					this.person_slide[i].toggle();

			}.bind(this));

		}.bind(this));

		

		

		$$('.'+this.options.class_expand_all).addEvent('click', function(e){

			e.stop();

			this.expand_all();

		}.bind(this));

		

		

		$$('.'+this.options.class_collapse_all).addEvent('click', function(e){

			e.stop();

			this.collapse_all();

		}.bind(this));

	},

	

	expand_all: function() {

		//run the effect on the entire array

		this.person_slide.each(function(sl){

			if(!sl.open){

				sl.slideIn();

			}

		});

		this.fireEvent('expand_all');

	},

	

	collapse_all: function() {

		//run the effect on the entire array

		this.person_slide.each(function(sl){

			if(sl.open){

				sl.slideOut();

			}

		});

		this.fireEvent('collapse_all');

	}

});



/* Quiz */

function GetResults()

{

	//alert(getSelectedRadio(document.forms[0].q1));	

	/*$$('form input[type=radio]').each(function(r){

											   

											   alert(getSelectedRadio(r));											   

	});

	*/

	for (i=1; i<=8; i++)

	{

		if (getSelectedRadio(document.getElementsByName("q" + i)) == -1)

		{

			alert("Please answer all the Questions");		

			return;			

		}		

	}

	

	score = 0;

	for (i=1; i<=8; i++)

	{

		score = score + parseInt(getSelectedRadioValue(document.getElementsByName("q" + i)));

				

	}

	//alert (score);

	

	$$('div.quizResult').each(function(div){

	   div.setStyle("display", "none");

	   });

	

	if (score < 14)

		$('result1').setStyle("display", "block");

	else if (score < 21)

		$('result2').setStyle("display", "block");

	else

		$('result3').setStyle("display", "block");

		

		

	

	/*

	if (getSelectedRadio(document.forms[0].q1) == -1)

	{

		alert('Please answer all questions');

		return;

	}

	*/		

	

}



function getSelectedRadio(buttonGroup) {

   // returns the array number of the selected radio button or -1 if no button is selected

   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)

      for (var i=0; i<buttonGroup.length; i++) {

         if (buttonGroup[i].checked) {

            return i

         }

      }

   } else {

      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero

   }

   // if we get to this point, no radio button is selected

   return -1;

} // Ends the "getSelectedRadio" function



function getSelectedRadioValue(buttonGroup) {

   // returns the value of the selected radio button or "" if no button is selected

   var i = getSelectedRadio(buttonGroup);

   if (i == -1) {

      return "";

   } else {

      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)

         return buttonGroup[i].value;

      } else { // The button group is just the one button, and it is checked

         return buttonGroup.value;

      }

   }

} // Ends the "getSelectedRadioValue" function



/*

* Browser PopUp

*/

var newwindow;

function poptastic(url)

{

	newwindow=window.open(url,'name','height=400,width=200');

	if (window.focus) {newwindow.focus()}

}

