Event.addBehavior({
	'#joinform' : function(e){this.observe('submit',validateSubmit,false);},
	//'#joinform fieldset' : function(e){if(Prototype.Browser.IE){new Insertion.Bottom(this.parentNode, '<hr/>')}}, //I'm not sure this is even useful anymore... trying without it
	'div#postal_row' : function(e)
	{
		if($('postal'))
		{
			if($('postal').value.length==0)
			{
				if($('country'))
				{
					if($('country').value.length==0){this.update("");}
					else
					{
						var url = '/ajax/response_signup.xml?country='+$('country').value;
						//alert(url);
						new Ajax.Request(url,
						{
							method:'get',
							onSuccess:function(transport)
							{
								//alert("success");
								//alert(transport.responseText);
								var postalStatus="";
								for(var i=0;i<transport.responseXML.documentElement.childNodes.length;i++)
								{
									if(postalStatus!="postal")
									{
										if(transport.responseXML.documentElement.childNodes[i].nodeName == 'message'){postalStatus="message";}
										else
										{
											geoElement = $(transport.responseXML.documentElement.childNodes[i].childNodes[0].getAttribute('id'));
											if(geoElement.readAttribute("name")=="postal"){postalStatus="postal";}
											if(geoElement.readAttribute("name")=="region"){postalStatus="region";}
											if(geoElement.readAttribute("name")=="locality"){postalStatus="locality";}
										}
									}
								}
								if(postalStatus!="postal"){$("postal_row").update("");}
							}
						})
					}
				}
			}
		}
	},
	//'#joinform div.field_row' : function(e){this.setStyle({background:'white'});},
	'#joinform div.field_row input' : function(e){if(this.id!="captcha"){this.observe('blur', function(event){validate(this,'live');});}},
	'#joinform div.field_row select' : function(e){this.observe('change', function(event){validate(this,'live');});},
	'#joinform div.check_row input' : function(e){this.observe('change', function(event){validate(this,'live');});},
	'#captcha' : function(e){this.observe('change', function(event){validate(this,'live');});},
	//'.field_row #captcha' : function(element){element.stopObserving('blur',coolAction);},//I should use the stopObserving but I can't seem to reference an anonymous function
	'#captcha_img' : function(e)
	{
		//element.setStyle({width:'25em',height:'5em'});
		new Insertion.After(this, '<a href="#refresh" id="captcha-refresh">Refresh image</a>');
		if($('captcha-refresh'))
		{
			Event.observe($('captcha-refresh'),'click',function(event){Event.stop(event);url="/ajax/response_captcha.xml";new Ajax.Request(url,{method:'get',onCreate:function(){ajaxCursorStart();},onComplete:function(){ajaxCursorEnd();},onSuccess:function(transport){$("captcha_img").src=transport.responseXML.documentElement.firstChild.nodeValue;}});},false);
		}
	}
});
//rules.merge(joinRules);






function validateSubmit(e){Event.stop(e);validate('d','submit');if(noErrors()){$("joinform").submit();}}//noEmpties() removed
//function validateSubmit(e){Event.stop(e);validate('d','submit');if(noErrors() && noEmpties()){$("joinform").submit();}}

/* prototype.js required */
/* _javascript.js required */
/* validate.js required */



