var regemail = new RegExp("^[0-9a-zA-Z]+@[0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$");
var cpa = false;
var last_active,new_active;
var busy = false;
var scrollmax = 0;
var scrollcurrent = 0;
var lettersort = "";
var savedform = "";
var max = 0;
var pg_scroll_current = 0;

Event.observe(window,"load",function(ev) {
	
	// All the member login stuff.
	$$(".member_login").invoke("observe","click",function(ev) {
		ev.stop();
		new Effect.toggle("member_login", "appear", { duration: 0.5 });
	});

	$$("#member_login_form").invoke("observe","submit",function(ev) {
		ev.stop();
		$$("#member_login_form img")[0].show();
		new Ajax.Request("www_root/ajax/login/", { method: "post", parameters: { form: $("member_login_form").serialize() }, evalScripts: true });
	});
	
	$$("#t_nav > li.members").invoke("observe","mouseenter",function(ev) {
		//width = parseInt($$("#t_nav li.members")[0].getWidth());
		//left = width - 211;
		//$$("#t_nav li.members ul")[0].setStyle({ marginLeft: left + "px" });
		$$("#t_nav li.members ul")[0].style.display = '';
	});
	$$("#t_nav > li.members").invoke("observe","mouseleave",function(ev) {
		$$("#t_nav li.members ul")[0].style.display = 'none';
		//$$("#t_nav li.members ul")[0].setStyle({ marginLeft: "-10000px" });
	});
	
	$$(".forgot_password").invoke("observe","click",function(ev) {
		ev.stop();
		user = this.up().previous("input",1).value;
		if (user == "") {
			throwAlert("Please enter your Username or Email Address and click the Forgot Password link again and we will email you your password.");
		} else {
			new Ajax.Request("www_root/ajax/forgot-password/", { parameters: { user: user } });
		}
	});
	
	// Add to favorites.
	$$(".favoritify").invoke("observe","click",function(ev) {
		ev.stop();
		new Ajax.Request("www_root/ajax/favoritify/", { parameters: { data: this.readAttribute("name") }, evalScripts: true });
	});
	
	// Clear defaults on input focus
	$$(".default").invoke("observe","focus",function(ev) { if (this.value == this.defaultValue) { this.value = ""; } });
	$$(".default").invoke("observe","blur",function(ev) { if (this.value == "") { this.value = this.defaultValue; } });
		
	// Embed custom dropdowns
	ProtoDrop.Embed();

	// Search Tabs
	$$("form.search ul.tabs a").invoke("observe","click",function(ev) {
		ev.stop();
		this.up("form").setAttribute("action",this.readAttribute("href"));
		$$("form.search ul.tabs a").invoke("removeClassName","selected");
		this.addClassName("selected");
	});
	
	// Print Links
	$$(".print_link").invoke("observe","click",function(ev) {
		ev.stop();
		window.print();
	});
	
	// Email Links
	$$(".email_link").invoke("observe","click",function(ev) {
		ev.stop();
		if ($("email_window"))
			$("email_window").remove();
		ethis = new Element("span", { style: "position: absolute; padding-left: 5px; margin-top: -37px;" });
		ethis.id = "email_window";
		
		if (this.readAttribute("href") != "#")
			url = this.readAttribute("href");
		else
			url = document.location.href;
		
		ethis.innerHTML = '<div style="float: left; width: 10px;"><img src="www_root/images/email-this-arrow.gif" alt="" style="margin-top: 32px;" /></div><div style="float: left; width: 218px; background: #0076C7; padding: 8px; color: #FFF; font-size: 16px; font-family: Georgia; margin-left: -2px;"><span style="float: left; padding-bottom: 8px; padding-left: 3px;">Email This</span><a style="display: block; width: 21px; margin: -3px 0 0 0; height: 21px; float: right;" onclick="$(\'email_window\').remove();"><img src="www_root/images/close-email.jpg" alt="" /></a><div style="clear: both; width: 202px; background: #FFF; padding: 8px; color: #333; font-size: 12px; font-family: Arial;"><form method="post" onsubmit="emailThisForm(); return false;" id="email_form"><input type="hidden" name="url" value="' + url + '" />Your Name:<br /><input name="your_name" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Your Email:<br /><input name="your_email" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Recipient\'s Name:<br /><input name="friend_name" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Recipient\'s Email:<br /><input name="friend_email" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Your Message:<br /><textarea name="message" style="background: #F6F6F6; border: 1px solid #83B9E6; width: 194px; height: 64px; margin: 0; padding: 2px; margin-top: 3px;"></textarea><br /><input type="image" src="www_root/images/submit_button.png" alt="Submit" style="width: auto; height: auto; border: 0; margin: 7px 0 0 0; padding: 0; float: right;" /></form><br class="clear" /></div></div>';
		
		this.insert({ after: ethis });
	});
	
	// Alerts
	$$("#news_alert img").invoke("observe","click",function(ev) {
		new Ajax.Request("www_root/ajax/ignore-alert/", { parameters: { id: this.readAttribute("name") } });
		new Effect.Fade(this.up("div"), { duration: 0.5 });
	});
	
	// !Homepage
	if ($("homepage_container")) {
		// Key Issues
		$$("#main_topics a").invoke("observe","click",function(ev) {
			ev.stop();
			id = this.readAttribute("href").substr(1);
			$$(".topic_content").invoke("hide");
			$("topic_" + id).show();
			$$("#main_topics a.active")[0].removeClassName("active");
			this.addClassName("active");
		});
		
		// Events scroller
		$$(".scroll_right").invoke("observe","click",function(ev) {
		    ev.stop();
		    if (this.hasClassName("disabled") || busy)
		    	return;
		    busy = true;
		    
		    ul = this.previous("div").down("ul");
		    margin = parseInt(ul.getStyle("margin-left"));
		    margin -= 560;
		    
		    new Effect.Morph(ul, { style: "margin-left: " + margin + "px;", duration: 0.5, afterFinish: function() { busy = false; } });
		    
		    scrollcurrent++;
		    if (scrollcurrent == scrollmax)
		    	this.addClassName("disabled");
		    $$(".scroll_left").invoke("removeClassName","disabled");
		});
		
		$$(".scroll_left").invoke("observe","click",function(ev) {
		    ev.stop();
		    if (this.hasClassName("disabled") || busy)
		    	return;
		    busy = true;
		    
		    ul = this.next("div").down("ul");
		    margin = parseInt(ul.getStyle("margin-left"));
		    margin += 560;
		    
		    new Effect.Morph(ul, { style: "margin-left: " + margin + "px;", duration: 0.5, afterFinish: function() { busy = false; } });
		    
		    scrollcurrent--;
		    if (scrollcurrent == 0)
		    	this.addClassName("disabled");
		    if (scrollmax > 0)
		    	$$(".scroll_right").invoke("removeClassName","disabled");
		});
		
		$$(".scroll_wrap a").invoke("observe","click",function(ev) {
		    ev.stop();
		    if (busy)
		    	return;
		    busy = true;
		    margin = parseInt(this.readAttribute("href").substr(1)) * -582;
		    new Effect.Morph($$(".scroller")[0], { style: "margin-left: " + margin + "px;", duration: 0.5, afterFinish: function() { busy = false; } });
		    
		    $$(".scroll_wrap a").invoke("removeClassName","active");
		    this.addClassName("active");
		});
		
		scrollmax = Math.ceil($$(".item").length / 3) - 1;
		if (scrollmax == 0)
		    $$(".scroll_right").invoke("addClassName","disabled");
	}

	// !Events
	$$("#event_type").invoke("observe","change",function(ev) {
		new Ajax.Updater("featured_upcoming_events","www_root/ajax/filtered-events/", { method: "post", parameters: { type: type, category: this.value }, onComplete: function(ev) { refreshEventHooks(); } });
	});
	$$(".save_to_calendar").invoke("observe","click",function(ev) {
		ev.stop();
		new Ajax.Request("www_root/ajax/save-event/",{ parameters: { event: this.readAttribute("name") }, evalScripts: true });
	});
	
	
	// !Bookstore
	if ($("bookstore_container")) {
	
		if ($$(".credit_card_input").length == 0) {
			$$(".row").invoke("observe","click", function(ev) {
			    ev.stop();
			    div = this.next("div");
			    if (div.style.display == "none") {
			    	div.show();
			    	this.addClassName("row_expanded");
			    } else {
			    	div.hide();
			    	this.removeClassName("row_expanded");
			    }
			});
		}
		
		$$(".add_to_cart").invoke("observe","click",function(ev) {
			ev.stop();
			document.location.href = "www_root/bookstore/cart/add/" + this.readAttribute("title") + "/";
		});
		
		$$(".add_to_cart").invoke("observe","mouseover",function(ev) {
			this.addClassName("add_to_cart_hover");
		});
		
		$$(".add_to_cart").invoke("observe","mouseout",function(ev) {
			this.removeClassName("add_to_cart_hover");
		});
		
		$$("form.checkout").invoke("observe","submit",function(ev) {
			ev.stop();
			errors = 0;
			var first_el;
			$$("input.required, select.required").each(function(ell) {
			    if (ell.value != "")
			    	ell.up().next("div.error").hide();
			});
			$$("input.required, select.required").each(function(ell) {
			    if (ell.value == "") {
			    	new Effect.Appear(ell.up().next("div.error"));
			    	errors++;
			    	if (!first_el)
			    		first_el = ell.up("div");
			    }
			});
			
			if (errors == 0)
				this.submit();
			else
				Effect.ScrollTo(first_el);
		});
		
		$$("#same_as_billing").observe("click",function(ev) {
		    if (this.checked) {
		    	$$("#billing input[type=text]").each(function(el) {
		    		eval("el.value = billing_info." + el.readAttribute("name") + ";");
		    	});
		    	$$("#billing select").each(function(el) {
		    		eval("tval = billing_info." + el.readAttribute("name") + ";");
		    		x = 0;
		    		while (x < el.options.length) {
		    			if (el.options[x].value == tval)
		    				el.selectedIndex = x;
		    			x++;
		    		}
		    	});
		    }
		});
	}
	
	// !Event Registration
	if ($("event_registration_container")) {
		$$(".registration_form").invoke("observe","submit", function(ev) {
			ev.stop();
			
			first_el = false;
			errors = 0;
		
			// Special stuff for PAC
			if (formtype == "online-pac") {
				if (!$("us_citizen").checked) {
					new Effect.Appear($("us_citizen").up("p").next("div.error"));
			    	errors++;
			    	if (!first_el)
			    		first_el = $("us_citizen");
				} else {
					$("us_citizen").up("p").next("div.error").hide();
				}
				
				if (!$("contribute").checked) {
					new Effect.Appear($("contribute").up("p").next("div.error"));
			    	errors++;
			    	if (!first_el)
			    		first_el = $("contribute");
				} else {
					$("contribute").up("p").next("div.error").hide();
				}
				
				if ($("total").value == "" || parseInt($("total").value) == NaN) {
					new Effect.Appear("amount_error");
					errors++;
					if (!first_el)
						first_el = $$("div.tabbed")[0];
				} else {
					$("amount_error").hide();
				}
			}
			// End Special For PAC
		
			// Dairy Forum Special
			if (formtype == "dairy-forum") {
				if (user_type_price == 0) {
					new Effect.Appear("reg_error");
					first_el = $("reg_error").previous("h3");
					errors++;
				} else
					$("reg_error").hide();
			}
			
			// Validate numeric fields.
			$$(".validate_numeric").each(function(el) {
				num = parseInt(el.value);
				if (isNaN(num)) {
					new Effect.Appear(el.up("p").next("div.error"));
					first_el = el.up("p");
					errors++;
				}
			});
			
			$$("input.required, select.required").each(function(ell) {
			    if (ell.value != "")
			    	ell.up().next("div.error").hide();
			});
			$$("input.required, select.required").each(function(ell) {
			    if (ell.value == "") {
			    	new Effect.Appear(ell.up().next("div.error"));
			    	errors++;
			    	if (!first_el)
			    		first_el = ell.up("div");
			    	if (ell.up(".reg_info")) {
			    		ell.up(".reg_info").show().previous("a").addClassName("active");
			    	}
			    }
			});
			
			if (errors == 0)
				this.submit();
			else
				Effect.ScrollTo(first_el);
		
		});
		
		$$(".pac_amount").invoke("observe","click",function(ev) {
			if (this.value == "other") {
				$("total").value = $("other_amt").value;
				cpa = true;
			} else {
				$("total").value = this.value;
				cpa = false;
			}
		});
		
		$$("#other_amt").observe("keyup",function(ev) {
			if (cpa)
				$("total").value = parseInt(this.value);
		});
	
		// All stuff for Board Meeting Page
		$$("#number_registering").observe("change", function(ev) {
		    num = parseInt(this.value);
		    if (isNaN(num)) {
		    	new Effect.Appear(this.up("div").down("div.error"));
		    	num = 0;
		    } else
		    	this.up("div").down("div.error").hide();
		    onum = parseInt($("number_playing_golf").value);
		    if (isNaN(onum))
		    	onum = 0;
		    total = (num * 250) + (onum * 165);
		    $("total_span").innerHTML = "$" + total + ".00";
		    $("total").value = total;
		});
		$$("#number_playing_golf").observe("change", function(ev) {
		    num = parseInt(this.value);
		    if (isNaN(num)) {
		    	new Effect.Appear(this.up("div").down("div.error"));
		    	num = 0;
		    } else
		    	this.up("div").down("div.error").hide();
		    onum = parseInt($("number_registering").value);
		    if (isNaN(onum))
		    	onum = 0;
		    total = (onum * 250) + (num * 165);
		    $("total_span").innerHTML = "$" + total + ".00";
		    $("total").value = total;
		});
	}
	
	// !Membership Directory
	if ($("md_search_form")) {
		$$(".reset").invoke("observe","click", function(ev) {
			ev.stop();
			$$("#md_search_form input").each(function(el) {
				el.value = "";
			});
			$$("#md_search_form select").each(function(el) {
				el.selectedIndex = 0;
			});
			$("products").innerHTML = "";
			
			savedform = "";
			lettersort = "";
			
			$("directory_content").innerHTML = '<img src="www_root/images/loader.gif" alt="" />';
			new Ajax.Updater("results","www_root/ajax/member-directory/", { evalScripts: true, method: "post", parameters: { letter: "", page: "1", form: savedform } });
				
		});
		
		$$("#product_category").observe("change", function(ev) {
			$("products").innerHTML = '<img src="www_root/images/loader.gif" alt="" />';
			new Ajax.Updater("products","www_root/ajax/member-directory-products/", { parameters: { category: this.value } });
		});
		
		$$("#md_search_form").observe("submit", function(ev) {
			ev.stop();
			
			savedform = $("md_search_form").serialize();
			$("directory_content").innerHTML = '<img src="www_root/images/loader.gif" alt="" />';
			new Ajax.Updater("results","www_root/ajax/member-directory/", { evalScripts: true, method: "post", parameters: { letter: lettersort, page: "1", form: savedform } });
		});
		
		$$("#directory_content.member_dir a span.address_book").invoke("observe","mouseenter",function(ev) {
			this.addClassName("address_book_hover");
		});
		$$("#directory_content.member_dir a span.address_book").invoke("observe","mouseleave",function(ev) {
			this.removeClassName("address_book_hover");
		});
	}
	
	// !My Profile
	if ($("my_profile_container")) {
		$$(".row").invoke("observe","click", function(ev) {
		    ev.stop();
		    div = this.next("div");
		    if (div.style.display == "none") {
		    	div.show();
		    	this.addClassName("row_expanded");
		    } else {
		    	div.hide();
		    	this.removeClassName("row_expanded");
		    }
		});	
		
		
		$$("span.remove").invoke("observe","mouseenter",function(ev) {
			this.addClassName("remove_hover");
		});
		
		$$("span.remove").invoke("observe","mouseleave",function(ev) {
			this.removeClassName("remove_hover");
		});
		
		$$("span.remove").invoke("observe","click",function(ev) {
			ev.stop();
			new Ajax.Request("www_root/ajax/remove-contact/", { parameters: { id: this.readAttribute("title") } });
			this.up("a").next("div").remove();
			this.up("a").remove();
		});
		
		$$("dd a.remove").invoke("observe","click",function(ev) {
			ev.stop();
			new Ajax.Request("www_root/ajax/remove-event/", { parameters: { id: this.readAttribute("href").substr(1) } });
			this.up("dd").previous("dt").remove();
			this.up("dd").remove();
		});
		
		$$("li a.remove").invoke("observe","click",function(ev) {
			ev.stop();
			new Ajax.Request("www_root/ajax/remove-page/", { parameters: { id: this.readAttribute("href").substr(1) } });
			this.up("li").remove();
		});	
		
		if ($("doc_folder")) {
			$("doc_folder").observe("change",function(ev) {
				new Ajax.Updater("doc_list","www_root/ajax/documents-in-folder/", { parameters: { id: this.value } });
			});	
		}
	}
	
	// !News Landing Page
	if ($("news_container")) {
		max = $$("#scroller .item").length;
		
		$("scroll_right").observe("click",function(ev) {
			ev.stop();
			if (this.hasClassName("active") && busy == false) {
				busy = true;
				left = parseInt($("scroller").getStyle("marginLeft"));
				new Effect.Morph("scroller", { style: "margin-left: " + (left - 592) + "px", duration: 0.5, afterFinish: function() { busy = false; } });
				$("scroll_left").removeClassName("active").addClassName("active");
				span = $$("#scroller_count span")[0];
				c = parseInt(span.innerHTML) + 1
				span.innerHTML = c;
				if (c == max)
					this.removeClassName("active");
			}
		});
		
		$("scroll_left").observe("click",function(ev) {
			ev.stop();
			if (this.hasClassName("active") && busy == false) {
				busy = true;
				left = parseInt($("scroller").getStyle("marginLeft"));
				new Effect.Morph("scroller", { style: "margin-left: " + (left + 592) + "px", duration: 0.5, afterFinish: function() { busy = false; } });
				$("scroll_right").removeClassName("active").addClassName("active");
				span = $$("#scroller_count span")[0];
				c = parseInt(span.innerHTML) - 1
				span.innerHTML = c;
				if (c == 1)
					this.removeClassName("active");
			}
		});
	}
	
	// !Password Request Form
	$$("#password_form").observe("submit",function(ev) {
	    ev.stop();
	    error = false;
	    $$("#password_form .error").each(function(el) { el.hide(); });
	    $$("#password_form input.required").each(function(el) {
	    	if (el.value == "") {
	    		el.up("div").down(".error").show();
	    		error = true;
	    	}
	    });
	    if ($("requested_password").value != $("confirm_password").value) {
	    	error = true;
	    	$("password_error").innerHTML = "<p>Passwords do not match.</p>";
	    	$("password_error").show();
	    } else
	    	$("password_error").innerHTML = "<p>You must enter and confirm your Requested Password.</p>";
	    
	    if (!error)
	    	$("password_form").submit();
	});
	
	// !Update My Information Form
	if ($("update_information_container")) {
		$$("form.update").invoke("observe","submit",function(ev) {
			ev.stop();
			errors = 0;
			var first_el;
			$$("input.required, select.required").each(function(ell) {
			    if (ell.value != "")
			    	ell.up().next("div.error").hide();
			});
			$$("input.required, select.required").each(function(ell) {
			    if (ell.value == "") {
			    	new Effect.Appear(ell.up().next("div.error"));
			    	errors++;
			    	if (!first_el)
			    		first_el = ell.up("div");
			    }
			});
			
			if (errors == 0)
				this.submit();
			else
				Effect.ScrollTo(first_el);
		});
	}
	
	// !Photo Galleries
	$$(".pg_scroll_right").click(function(ev) {
		ev.stop();
		if (busy)
			return;
		count = $$(".photo_gallery li").length;
		if (count > ((pg_scroll_current + 1) * 5)) {
			busy = true;
			pg_scroll_current++;
			new Effect.Morph($$(".photo_gallery ul")[0], { style: "margin-left: -" + (pg_scroll_current * 520) + "px", duration: 0.5, afterFinish: function() { busy = false; } });
		}
	});
	$$(".pg_scroll_left").click(function(ev) {
		ev.stop();
		if (busy)
			return;
		if (pg_scroll_current > 0) {
			busy = true;
			pg_scroll_current--;
			new Effect.Morph($$(".photo_gallery ul")[0], { style: "margin-left: -" + (pg_scroll_current * 520) + "px", duration: 0.5, afterFinish: function() { busy = false; } });
		}
	});
	$$(".photo_gallery li a").click(function(ev) {
		ev.stop();
		$$(".photo_gallery li a.selected")[0].removeClassName("selected");
		this.addClassName("selected");
		$$(".photo_gallery .big_image img")[0].setAttribute("src",this.readAttribute("href"));
		if (this.readAttribute("title")) {
			$$(".photo_gallery .big_image p")[0].show().innerHTML = this.readAttribute("title");
		 } else {
		 	$$(".photo_gallery .big_image p")[0].hide();
		 }
	});

});

function emailThisForm() {
	new Ajax.Request("www_root/ajax/send-to-friend/", { parameters: $("email_form").serialize(true) });
}

function throwAlert(msg) {
	alert(msg);
}

// Dropdown plugin for Prototype / Scriptaculous
var ProtoDrop = {

	Embed: function() {
		$$(".dropdown > a").invoke("observe","click", ProtoDrop.Drop); 
	},
	
	Drop: function(ev) {
		ev.stop();
	    // If the dropdown isn't visible...
	    if (this.next("ul").style.display == "none") {
	    	new Effect.toggle(this.next("ul"), "blind", { duration: 0.25 });
	    
	    	// Check the body for clicks, like a normal dropdown would
	    	Event.observe($$("body")[0],"click",function(ev) {
	    		$$(".dropdown > ul").each(function(el) { if (el.style.display != "none") { new Effect.BlindUp(el, { duration: 0.25 }); } });
	    		Event.stopObserving($$("body")[0]);
	    	});
	    	
	    	// Only observe the clicks on the currently dropped list.  That way any other click is going to cause the normal body click and close this dropdown.
	    	x = 0;
	    	while (this.next("ul").down("a",x)) {
	    		this.next("ul").down("a",x).observe("click",function(ev) {
	    			ev.stop();
	    			newLink = new Element("a", { href: "#" });
	    			newLink.observe("click", ProtoDrop.Drop);
	    			newLink.innerHTML = this.innerHTML;
	    			this.up("ul").previous("a").replace(newLink);
	    			this.up("ul").previous("input").value = this.readAttribute("href").substr(1);
	    			new Effect.toggle(this.up("ul"),"blind", { duration: 0.25 });
	    			this.up("ul").previous("input").fire("dropdown:change");
	    		});
	    		x++;
	    	}
	
	    } else {
	    	// Stop all the events and Blind Up.
	    	$$(".dropdown ul a").each(function(el) { Event.stopObserving(el); });
	    	Event.stopObserving($$("body")[0]);
	    	x = 0; while (this.next("ul").down("a",x)) { Event.stopObserving(this.next("ul").down("a",x)); x++; }
	    	new Effect.toggle(this.next("ul"), "blind", { duration: 0.25 });
	    }
	}
}

function refreshEventHooks() {
	$$(".save_to_calendar").invoke("observe","click",function(ev) {
		ev.stop();
		new Ajax.Request("www_root/ajax/save-event/", { parameters: { event: this.readAttribute("name") }, evalScripts: true });
	});

	// Email Links
	$$(".email_link").invoke("observe","click",function(ev) {
		ev.stop();
		if ($("email_window"))
			$("email_window").remove();
		ethis = new Element("span", { style: "position: absolute; padding-left: 5px; margin-top: -37px;" });
		ethis.id = "email_window";
		
		if (this.readAttribute("href") != "#")
			url = this.readAttribute("href");
		else
			url = document.location.href;
		
		ethis.innerHTML = '<div style="float: left; width: 10px;"><img src="www_root/images/email-this-arrow.gif" alt="" style="margin-top: 32px;" /></div><div style="float: left; width: 218px; background: #0076C7; padding: 8px; color: #FFF; font-size: 16px; font-family: Georgia; margin-left: -2px;"><span style="float: left; padding-bottom: 8px; padding-left: 3px;">Email This</span><a style="display: block; width: 21px; margin: -3px 0 0 0; height: 21px; float: right;" onclick="$(\'email_window\').remove();"><img src="www_root/images/close-email.jpg" alt="" /></a><div style="clear: both; width: 202px; background: #FFF; padding: 8px; color: #333; font-size: 12px; font-family: Arial;"><form method="post" onsubmit="emailThisForm(); return false;" id="email_form"><input type="hidden" name="url" value="' + url + '" />Your Name:<br /><input name="your_name" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Your Email:<br /><input name="your_email" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Recipient\'s Name:<br /><input name="friend_name" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Recipient\'s Email:<br /><input name="friend_email" type="text" style="background: #F6F6F6; width: 194px; padding: 2px; margin: 3px 0 3px; border: 1px solid #83B9E6; display: block;" />Your Message:<br /><textarea name="message" style="background: #F6F6F6; border: 1px solid #83B9E6; width: 194px; height: 64px; margin: 0; padding: 2px; margin-top: 3px;"></textarea><br /><input type="image" src="www_root/images/submit_button.png" alt="Submit" style="width: auto; height: auto; border: 0; margin: 7px 0 0 0; padding: 0; float: right;" /></form><br class="clear" /></div></div>';
		
		this.insert({ after: ethis });
	});
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
