function form_Join(auto_id) {
	this.DOMConstruct('form_Join', auto_id);
}
form_Join.prototype = new SK_FormHandler({
	name: 'profile_join',
	
	fields: {
		headline: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		username: {
			construct: 
							function($input) {
								var handler = this;
								
								if($input.val()!="" && $input.val()!=handler.lastValue){
									handler.check_username($input);
								}
		
								$input.change(function(){
									handler.changed = true;
								});
													
								$input.blur(function() {
									if($input.val()!="" && $input.val()!=handler.lastValue && handler.changed ){
										handler.check_username($input);
									}
									else{
										$input.parent().find(".success").remove();
									}
								});
							},
			validate: function(value, required) {},
			focus: function() {},
			changed: true,
			lastValue: "",
			check_username: 
							function($input){
							
							var handler = this;
								$.ajax({
										url: "http://www.rawfoodfriends.com/field_responder.php",
										method: "post",
										dataType: "json",
										data: {action: "check_username_exists", username: $input.val()},
										success: function(result){
												$input.parent().find(".success").remove();
												handler.changed = false;
												if (result==2){
													SK_drawError("Sorry, this username is used by another profile");
												}
		   										else if(result==1){
		   											$input.after('<span class="success">&nbsp;</span>');
		   										}
		   										else if(result==4) {
		   											SK_drawError("Sorry, this username is restricted");
		   										}
		   										else{
		   											SK_drawError("Please, enter username");
		   										}
		  								}
									});
							}
							
		},
		password: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		re_password: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		email: {
			construct: 
							function($input) {
								var handler = this;
								
								this.lastValue = $input.parent().find("input[name=last_value]").val();
								
								if($input.val()!="" && $input.val()!=this.lastValue){
									handler.check_email($input);
								}		
								
								$input.change(function(){
									handler.changed = true;
								});
												
								$input.blur(function() {
									if($input.val()!="" && $input.val()!=handler.lastValue && handler.changed ){
										handler.check_email($input);
									}
									else{
										$input.parent().find(".success").remove();
									}						
								});
							},
			validate: function(value, required) {},
			focus: function() {},
			lastValue: "",
			changed: true,
			check_email: 
							function($input){
							var handler = this;
							
								$.ajax({
										url: "http://www.rawfoodfriends.com/field_responder.php",
										method: "post",
										dataType: "json",
										data: {action: "check_email_exists", email: $input.val()},
										success: function(result){
												$input.parent().find(".success").remove();
												handler.changed = false;
												if (result==2){
													SK_drawError("Sorry, this email is already used");
												}
		   										else if(result==1){
		   											$input.after('<span class="success">&nbsp;</span>');
		   										}
		   										else{
		   											SK_drawError("Please, enter valid email");
		   										}
		   										
		   										
		  								}
									});
							}
							
		},
		re_email: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		real_name: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		sex: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		general_description: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		match_sex: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		relationship: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		location: {
			construct: 
					function($input){
						handler = this;
						this.$parent_node = $input.parents("tbody:eq(0)");
						this.$container_node = $input.parents(".location_container:eq(0)");
						if ($input.val()!=""){
						
							this.$parent_node.find("tr.state_id select").change(function(){
								handler.change_event($(this),$input.val());
							});
							
							this.$parent_node.find("input[type=button]").click(function(){
								handler.change_event(handler.$parent_node.find("tr.zip input[type=text]"),$input.val());
							});
							this.suggest(this.$parent_node.find("input[name*=city_name]"),this.$parent_node.find("tr.state_id select").val());
						}
						
						$input.change(function(){
							handler.change_event($input);
						});
					} 
				,
			validate: function(value, required) {},
			focus: function() {},
			$parent_node: {},
			$container_node: {},
			fields: [],
			$prototype_node: {},
			change_event: 
					function($input, param){
						var handler = this;
					
						handler.fields[$input.parents("tr:eq(0)").attr("class")] = $input.val();
						$.ajax({
									url: "http://www.rawfoodfriends.com/field_responder.php",
									method: "post",
									dataType: "json",
									data: {action: "process_location", changed_item : $input.parents("tr:eq(0)").attr("class") , value : $input.val(), param : param},
									success: function(result){
									 	handler.ajax_receiver(result);
									}
								});
					} 
				,
			ajax_receiver: 
					function(result){
						handler = this;
									
						$.each(result.hide_items,function(i,item){
							handler.$parent_node.find("tr."+item).css("display","none");
							handler.$parent_node.find("tr."+item+" td.value").empty();
						});
						
						$.each(result.assign,function(item,html){
							var $node = handler.$parent_node.find("tr."+item+" td.value");
							$node.empty();
							$node.append(html);
							
							
							switch(item){
							case "state_id":
								$node.find("select[name=state_id]").change(function(){
									handler.change_event($(this),handler.fields.country_id);
								});
								break;
							case "zip":
								$node.find("input[type=button]").click(function(){
									handler.change_event($node.find("input[type=text]"),handler.fields.country_id);
								});
								break;
								
							case "city_id":
								handler.suggest($node.find("input[name=city_name]"),handler.fields.state_id);
								break;
							}
							
							$node.find("input, select").each(function(){
								var name = $(this).attr("name");
								if (name!=undefined){
									$(this).attr("name","location["+name+"]");
								}
							});
						});
										
						$.each(result.show_items,function(i,item){
							//this.$parent_node.find("tr."+result.show_items[item]).css("display","table-row");
							handler.$parent_node.find("tr."+item).fadeIn("slow");
						});  
						
						
					}
					
				,
			$: function($expr){
					return this.$container_node.find($expr);
				},
			$suggest_cont_prototype: undefined,
			showSuggest: function($node, suggests){
					var handler = this;
					
					var removeSuggest = function(){
						$node.parent().siblings(".suggest_cont").remove();
					}
					
					if (this.$suggest_cont_prototype ==undefined) {
						this.$suggest_cont_prototype = this.$(".suggest_cont").remove().clone();
					}		
					
					var $suggest_cont = this.$suggest_cont_prototype.clone();
					
					removeSuggest();
					
					if (suggests.length <= 0) {
						return;
					}
					
					var itemHover = function($item){
						$item.parent().find(".suggest_item").removeClass("hover");
						$item.addClass("hover");
					}
					
					$.each(suggests, function(i, item){
					
						var $item_node = $suggest_cont.find(".prototype_node").clone().removeClass("prototype_node").css("display","block");
						var $parent_node = $suggest_cont.find(".prototype_node").parent();
						
						$item_node.html(item.suggest_label);
						
						$item_node.mouseover(function(){
							itemHover($item_node);
						});
						
						$item_node.click(function(){
							$node.val(item.name);
							removeSuggest();
							$node.focus();
						});
						
						$parent_node.append($item_node);
						
					});
					
					$node.unbind("keypress");
					$node.keypress(function(eventObject){
						
						$selected_item = $node.parent().find("div.suggest_cont ul li.hover");
						if ( $selected_item.length == 0 ) {
							$selected_item = $node.parent().find("div.suggest_cont ul li:visible:eq(0)");
							itemHover($selected_item);
							return;
						}
						
						switch(eventObject.keyCode){
							case 40:
								itemHover($selected_item.next(".suggest_item"));
								break;
							case 38:
								itemHover($selected_item.prev(".suggest_item"));
								break
							case 13:
								itemHover($selected_item.prev(".suggest_item"));
								if ($selected_item.length > 0) {
									$selected_item.click();
									return false;	
								}
								break
						}
					});
					
					$node.unbind("blur");
					$node.blur(function(){
						window.setTimeout(removeSuggest,200);
					});
								
					$node.parent().after($suggest_cont);
					$suggest_cont.css("width",$node.outerWidth()).show();
					
				},
			suggest: function($node, state_id){
					var handler = this;
					var timeout;
					var last_str;	
					
					
					$node.unbind();
					$node.keyup(function(eventObject){
						
						var $field = $(this);
						
						var getCityList = function(str, state_id) {
							if (!$.trim(str)) {
								last_str = "";
								handler.showSuggest($node, []);
								return;
							}	
						
							var key = eventObject.which;
							if ( last_str == str || key==13) {
								return;
							}
							
							var params ={
								str : str,
								state_id: state_id,
								action: "location_get_city"
							};
							$.ajax({
										url: "http://www.rawfoodfriends.com/field_responder.php",
										method: "post",
										dataType: "json",
										data: params,
										success: function(result){
											last_str = str;
											handler.showSuggest($node, result, eventObject);
										}
								});
						}
						
						var suggestGetList = function(){
							var str = $field.val();
							getCityList(str, state_id);
						}
						
						if (timeout != undefined) {
							window.clearTimeout(timeout)
						}
						timeout = window.setTimeout(suggestGetList,300);
						return false;
					});
				}
		},
		relationship_status: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		birthdate: {
			construct: function($input, form_handler) {},
			validate: function(value) {
					if ( !$.trim(value.year) ) {
						throw new SK_FormFieldValidationException("");	
					}
					
					if ( !$.trim(value.month) ) {
						throw new SK_FormFieldValidationException("");	
					}
					
					if ( !$.trim(value.day) ) {
						throw new SK_FormFieldValidationException("");	
					}
					
				},
			focus: function() {}
		},
		occupation: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		religion: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		body_type: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		eye_color: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		have_children: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		drink: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		match_agerange: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		i_agree_with_tos: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		},
		are_you_100__raw_: {
			construct: function($input, form_handler) {},
			validate: function(value, required) {},
			focus: function() {}
		}
	},
	actions: {
		action_1___: {
		fields: {"username":true,"password":true,"re_password":true,"email":true,"re_email":true,"real_name":false,"sex":true,"match_sex":true,"relationship":true,"location":true,"relationship_status":false,"birthdate":true,"match_agerange":false,"are_you_100__raw_":false}
		},
		action_1___1: {
		fields: {"username":true,"password":true,"re_password":true,"email":true,"re_email":true,"real_name":false,"sex":true,"match_sex":true,"relationship":true,"location":true,"relationship_status":false,"birthdate":true,"match_agerange":false,"i_agree_with_tos":true,"are_you_100__raw_":false}
		},
		action_2___1: {
		fields: {"headline":true,"general_description":true,"occupation":false,"body_type":false,"have_children":false,"drink":false}
		},
		action_1___2: {
		fields: {"username":true,"password":true,"re_password":true,"email":true,"re_email":true,"real_name":false,"sex":true,"match_sex":true,"relationship":true,"location":true,"relationship_status":false,"birthdate":true,"match_agerange":false,"are_you_100__raw_":false}
		},
		action_2___2: {
		fields: {"headline":true,"general_description":true,"occupation":false,"body_type":false,"have_children":false,"drink":false}
		},
		action_1___4: {
		fields: {"username":true,"password":true,"re_password":true,"email":true,"re_email":true,"real_name":false,"sex":true,"match_sex":true,"relationship":true,"location":true,"relationship_status":false,"birthdate":true,"match_agerange":false,"are_you_100__raw_":false}
		},
		action_2___4: {
		fields: {"headline":true,"general_description":true,"occupation":false,"religion":false,"body_type":false,"eye_color":false,"have_children":false,"drink":false}
		}
	},
	default_action: ''
});
