	function load_jak2_filter(html,inline_label)
	{
		var areas  = $$('input[name^=areas] ');
		var other_group =[];
		var ja_group =[];
		
		var jak2_input =null;
		
		var eja_group  = new Element('div', {id: 'ja_group'});
		var eother_group  = new Element('div', {id: 'other_options'});
		var plg_ja_filterform  = new Element('div', {id: 'plg_ja_filterform'});
		areas.each(function (input) 
		{
			if(input.type=='checkbox')
			{
				if(input.value=='jak2_filter')
				{
					jak2_input = input;
		        	
		        	var area_jak2 = new Element('input', {type: 'radio', checked: jak2_input.checked, id: 'area_jak2', name:'filter_group',value:'jagroup',
		        	events: {
       					 click: function(){
           					 change_group(this.value);
       						 }
		        		}
		        	});
		        	ja_group.push(area_jak2);
		        	var textField = new Element('input', {type: 'hidden',  id: 'jaarea', name:'areas[]',value:"jak2_filter"});
		        	
		        	ja_group.push(textField);
		        	//var label = new Element('label', {'for':'area_jak2'});
					var label =input.getNext('label');
					label.htmlFor = 'area_jak2';
					ja_group.push(label);
					
					var other_radio = new Element('input', {type: 'radio', checked: !jak2_input.checked, id: 'other_group', name:'filter_group',value:'other_group',
        	events: {
       					 click: function(){
           					 change_group(this.value);
       						 }
		        	}});
				    ja_group.push(other_radio);
				    
				    var label = new Element('label', {'for':'other_group'});
					label.innerHTML ='Other group';
					
					ja_group.push(label);
					
					//eja_group.adopt(area_jak2,label,textField);
					eja_group.inject(input,'before');
									
					eother_group.inject(input,'before');
					
					plg_ja_filterform.inject(input,'before');
					
					/*plg_ja_filterform.innerHTML = html;
					area_jak2.checked = jak2_input.checked;*/
					input.remove();
				}
				else 
				{
					other_group.push(input);
					other_group.push(input.getNext('label'));
				}
				//input.remove();
			}
		});
		if(jak2_input !=null)
		{
			eja_group.adopt(ja_group);
			
			eother_group.adopt(other_group);
			
			plg_ja_filterform.innerHTML = html;
			$('area_jak2').checked = jak2_input.checked;
			$('other_group').checked = !jak2_input.checked;
			show_jafilterform($('area_jak2').checked,html,inline_label)
		}
			
	}
	function change_group(group)
	{
		if(group=='other_group')
		{
			$('jaarea').value='';
			$('other_options').setStyle('display','');
			$('plg_ja_filterform').setStyle('display','none');
		}
		else
		{
			$('jaarea').value='jak2_filter';
			$('other_options').setStyle('display','none');
			$('plg_ja_filterform').setStyle('display','block');
		}
	}
	function show_jafilterform(ischeck,html,inline_label)
	{
		if(ischeck)
		{
			var plg_ja_filterform = $('plg_ja_filterform');
			if(plg_ja_filterform)
			{
				$('plg_ja_filterform').setStyle('display',''); 
			}
			else
			{
				var plg_ja_filterform  = new Element('div', {id: 'plg_ja_filterform'});
				plg_ja_filterform.inject($('ja_group'),'before');
				plg_ja_filterform.innerHTML = html;
			}
			if($('other_options'))
			{
				$('other_options').setStyle('display','none'); 
			}
			label_sliding(inline_label,'plg_ja_filterform');
			
		}
		else
		{
			var plg_ja_filterform  =$('plg_ja_filterform');
			if(plg_ja_filterform)
			{
				$('plg_ja_filterform').setStyle('display','none'); 
			}
			if($('other_options'))
			{
				$('other_options').setStyle('display',''); 
			}
		}
		if($('search_searchword').value=='custom search')
		{
			$('search_searchword').value ='';
		}
		
	}
	function build_jafilter(div_parent_id,group_tag)
	{
		if(!$(div_parent_id))
		{
			return false;
		}
		var ja_filter ={};
		var catitem = $(div_parent_id).getElementById('catid');
		var group ='';
		if(catitem)
		{
			ja_filter['catid'] = catitem.value;
			var tmpl = catitem.value.split('_');
			if($(group_tag+tmpl[0]))
			{
				group =' #'+group_tag+tmpl[0];
			}
			//else if 
		}
		inputs = $$('#'+div_parent_id+group+' input')
		
		if(inputs.length>0)
		{
			inputs.each(function (input) 
			{
				if(input.type=='text')
				{
					v_label = ($$('label[for='+input.id+']')[0].innerHTML)+'...';
					if((input.value !='')&&(input.value!=v_label))
					{
						if(ja_filter[input.name]==undefined)
						{
							ja_filter[input.name] = input.value;
						}
						else ja_filter[input.name] += '-'+input.value;
					}
				}
				else if(input.type=='radio')
				{
					if(input.checked)
					{
						ja_filter[input.name] = input.value;
					}
				}
				else if(input.type=='checkbox')
				{
					if(input.checked)
					{
						if(ja_filter[input.name]==undefined)
						{
							ja_filter[input.name] = input.value;
						}
						else ja_filter[input.name] += ','+input.value;
					}
				}
			});
		}
		selects = $$('#'+div_parent_id + group+'  select');
		selects.each(function (selectitem) 
		{
			if(selectitem.id=='catid')
			{
				ja_filter['catid'] = selectitem.value;
			}
			else if(selectitem.value !='')
			{
				ja_filter[selectitem.name] = selectitem.value;
			}
		});
		
		if($('area_jak2')&&($('area_jak2').checked))
		{
			areas  = $$('input[name^=areas] ');
			areas.each(function (input) 
			{
				if(input.type=='checkbox')
				{
					if(input.checked)input.checked=false;
				}
			});
			
			if($('search_searchword').value!='')
			{
				$('ja_searchword').value =$('search_searchword').value;
			}
			
		}
		else
		{
			if($('jaarea'))
			{
				$('jaarea').value='';
			}
		}
		var cookie = Cookie.get("jak2_filter");
		if(cookie)
		{
			Cookie.remove("jak2_filter");
		}
		//alert(ja_filter);
		Cookie.set("jak2_filter",Json.toString(ja_filter),{duration: 1, path: "/"});

	}
	function label_sliding(inline_label,div_parent_id)
	{
		if(inline_label=='0')return true;
		inputs = $$('#'+div_parent_id+' input[type=text]')
		if(inputs.length>0)
		{
			inputs.each(function (input) 
			{
				label = $$('label[for='+input.id+']')[0];
				v_input = label.innerHTML +'...';
				label.setStyle('display','none');
				if(input.value=='')
				{
					input.value = v_input;
				}
		       	input.addEvents({ 
		       	
				focus: function() 
				{ 
					if(input.value == $$('label[for='+this.id+']')[0].innerHTML +'...')
					{
						input.focus();
						input.value='';
					}
				},
				keypress: function() 
				{ 
					if(this.value ==$$('label[for='+this.id+']')[0].innerHTML +'...')
					{
					 this.value = '';
					 this.removeClass("focus").addClass("typing");
					}
				},
				blur: function() { 
					this.removeClass("focus").removeClass("typing");
					if(this.value == ''){
							 this.value = $$('label[for='+this.id+']')[0].innerHTML +'...';
						}
					}
				} );
			});
		}
		selects = $$('#plg_ja_filterform  select');
		selects.each(function (selectitem) 
		{
			if($$('label[for='+selectitem.id+']')[0])
			{
				$$('label[for='+selectitem.id+']')[0].setStyle('display','none');
			}
		});
	}
	function load_extrafields(value,groupname)
	{
		var tmpl = value.split('_');
		if(tmpl.length ==2)
		{
			var groups  = $$('div[id^='+groupname+'] ');
			if(groups)
			{
				groups.setStyle ('display', 'none');
			}
			if($(groupname+tmpl[0]))
			{
				$(groupname+tmpl[0]).setStyle ('display', '');
			}
		}
	}
	function expand_catoptions()
	{
		var ua = navigator.userAgent.toLowerCase();
		var UA = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0];
		var browser = (UA[1] == 'version') ? UA[3] : UA[1];
		if(browser =='ie')
		{
		  	$('catid').addEvents({ 
		  		focus  : function(){
	       		this.setStyle("origWidth", this.getStyle("width"));
	       		this.setStyle("width", "auto");
	        	},
	       		blur : function(){
	       		this.setStyle("width", this.getStyle("origWidth"));
	        	}
			});      
		} 
	}
