// JavaScript Document
$(document).ready(function(){
    $(".advancedDiv").hide();
	$(".show_advanced").show();
	
	$('.show_advanced').click(function(){
	$(".advancedDiv").slideToggle();
	});

		$('#frm input').keypress(function(e){      
				if(e.which == 13){      $('#frm').submit()       }   
				   });
				   
	// load categories
	$('#cat').one("click",function() {	
		$.ajax({
		beforeSend: function() { 
	//	$("#cat :first").remove();
		$("#cat").prepend( $('<option value="" style="background-image:url(http://softfree.co.ua/engine/ajax/loading.gif);background-repeat:no-repeat;background-position:bottom left;padding-left:30px;padding:0px;"> Loading</option>'));
		 },        
		complete: function() { $('#cat').IELongDropDown(); },
	    url: '/ajax/GetCategories/',
	    dataType : "json",
	    success: function (obj, textStatus) {
	    	$("#cat :first").remove()
				$.each(obj, function() {
				  $("<optgroup>").attr("label", this.name).text(this.name).appendTo("#cat");
				  $.each(this.childs, function() {
          				  $("<option>").attr("value", this.cid).text('\t'+this.sub_category).appendTo("#cat");
        				});
					
            });
				}
			});
	
		});
		
		
		$("#frm").submit(function(e){
		if($.trim($('#q').val())=='')
		 {
			 $('#search_example').html('<span class="exmf" style="color:red">Bitte Suchwort eingeben!</span>');
			 $('#q').focus();
		 return false;}	
		 
		var $newArray = new Array();
		var action = "/"+$.trim($('#q').val())+".htm";
		action = encodeURI(action);
		$i=0;
		$("#frm :input").each(function(key,val) {
 			  if (($(this).val() != "")&&(this.name!='q'))
    				{
					$newArray[$i]=this.name+"="+$(this).val();$i++;
					//action += "&"+this.name+'='+$(this).val();
					}
		/*		else {
					alert("empty"+this.name);
				
					}*/
				
			});
			if($newArray.length>0)
				{ action +="?"+$newArray.join('&');}
		 
		// alert("**"+action);
		location.href =action;
	return false;		//$("#frm").attr("action",  action);
				});
});
