Event.addBehavior({
	'#marital__all' : function(e)
	{
		maritalToggler(this,$$("#marital li"));
		if(!Prototype.Browser.IE){this.observe('change',function(event){maritalToggler(this,$$("#marital li"))});}
		else{this.observe('click',function(event){maritalToggler(this,$$("#marital li"))});}
	},
	'#nickname_row,#save_row,#tags_row' : function(e)
	{
			this.addClassName("labelHint");
			this.childElements()[0].observe('change',function(event){this.setAttribute("value",this.value.toString());});
			if(Prototype.Browser.IE)
			{
				this.childElements()[0].observe('focus',function(event){this.setStyle({background:"white"});});
				this.childElements()[0].observe('blur',function(event){if(this.readAttribute("value")==''){this.setStyle({background:"transparent"})};});
				if(this.childElements()[0].readAttribute("value")=='' || this.childElements()[0].readAttribute("value")==null){this.childElements()[0].setStyle({background:"transparent"})}
				else{this.childElements()[0].setStyle({background:"white"})}
			}
	},
	'form#searchform fieldset.advanced' : function(e){this.addClassName("collapsed");if(this.hasClassName("locked")){this.insert({top:'<div class="toggle_off"><a href="/action/signup.html">More advanced search options</a></div>'})}else{this.insert({top:'<div class="toggle_off"><a href="#" onclick="this.ancestors()[1].removeClassName(\'collapsed\')">More advanced search options</a></div><div class="toggle_on"><a href="#" onclick="this.ancestors()[1].addClassName(\'collapsed\')">Less search options</a></div>'})}},
	'#location_row dt label' : function(e){this.observe('click',function(event){setTimeout('$("'+this.readAttribute("for")+'").blur()',50);});},
	'#location_row input.locmode' : function(e){this.observe('change',function(event){locMode=$RF("searchform","locmode");$("location_row").select("dt,dd").each(function(node){(node.hasClassName(locMode))?node.addClassName("active"):node.removeClassName("active")});});},
	'#location_row select.country' : function(e){if(!$("region")&&$F("country")!="00"){locationRefresh("load")};this.observe('change',function(event){locationRefresh("country");});},
	'#location_row select.region' : function(e){this.observe('change',function(event){locationRefresh("region");});},
	'form#searchform a.search_criteria' : function(e){this.observe('click', function(event){Event.stop(event);detailsEdit(this,event.pointerX(),event.pointerY());});}//,
//	'ul.browse_menu li a' : function(e)
//	{
//		if(this.readAttribute("href") && this.readAttribute("href")!='')
//		{
//			this.observe('click', function(event)
//			{
//				Event.stop(event);
//				url=this.readAttribute("href").concat("&content_type=xml");
//				new Ajax.Request(url,
//				{
//					method:'get',
//					onCreate:function(){ajaxCursorStart();},
//					onComplete:function(){ajaxCursorEnd();},
//					onSuccess:function(transport){refreshById(transport.responseXML,"div","search_results");location.href="#container"}
//				});
//			});
//		}
//	}
});

function locationRefresh(mode)
{
	url="/action/search/regular/?content_type=xml&ajax=yes&group=location";
	url+=(mode!="load")? "&fill=params":"";
	pars=(mode=="region")? Form.serializeElements($$("#location_row input,#location_row select")) : Form.serializeElements($$("#country"));
	new Ajax.Request(url,{method:'post',postBody:pars,onCreate:function(){ajaxCursorStart();},onComplete:function(){ajaxCursorEnd();},onSuccess:function(transport){refreshById(transport.responseXML,"dl","locmodes")}});
}

function maritalToggler(toggler,togglees){for(i=1;i<togglees.length;i++){togglees[i].firstChild.disabled=toggler.checked;(toggler.checked)?togglees[i].addClassName("disabled"):togglees[i].removeClassName("disabled");}}


function detailsEdit(element,x,y)
{
	url=element.readAttribute("href").replace("=all,","=").concat("&content_type=xml");
	editrow="";
	element.ancestors().each(function(node){if(node.hasClassName("details_row")){editrow=node.readAttribute("id")}}) 
	if(editrow)
	{
		var content = document.createElement('div');
		var nodeCopy ="";
		new Ajax.Request(url,
		{
			method:'get',
			onCreate:function(){ajaxCursorStart();},
		  onComplete:function(){ajaxCursorEnd();},
			onSuccess:function(transport)
			{
				FormRows=transport.responseXML.getElementsByTagName("form")[1].getElementsByTagName("div");		
				for(f=0;f<FormRows.length;f++){if(FormRows[f].getAttribute("id")==editrow){nodeCopy=FormRows[f].cloneNode(true);}}
				$(editrow).replace(serializeNode(nodeCopy));
				$(editrow).addClassName("edit_row");
			}
		});
	}
}

function detailsRestore(detailsForm)
{
	url="/action/search/regular/?content_type=xml&ajax=yes";
	if(Prototype.Browser.IE){pars=$(detailsForm.readAttribute("id")).serialize();}
	else{pars=detailsForm.serialize();}
	new Ajax.Request(url,{
		method:'post',
		postBody:pars,
    onCreate:function(){ajaxCursorStart();},
		onComplete:function(){ajaxCursorEnd();},
		onSuccess:function(transport)
		{
			detailsForm.getElementsByClassName("field_row").each(function(node){refreshById(transport.responseXML,"div",node.readAttribute("id"))})
		}
	});
}

