var searchboxUsed = {
		
	containerID: null,
	
	init: function(containerID)
	{
		searchboxUsed.containerID = containerID;
		
	},
	
	reload: function(el) {
		attrs = new Array();

		// parsing request string 
		requestString = document.location.search;
		if(requestString.indexOf('?')==0)
		    requestString = requestString.substring(1);
		requestParams = requestString.split("&",3)


		for(i=0; i< requestParams.length; i++) {
		    kv = requestParams[i].split('=');
		    if(kv[0]!='' && kv[1]!='') {
		        attrs[kv[0]] = kv[1];
		    }
		}

		//parsing form elements
		els = searchboxUsed._getFormElements();
		
		els.each(function() {
		   el = jQuery(this);
		
		   if(el.attr('type')=='checkbox') {
			   attrs[el.attr('name')] = el.is(':checked')?el.val():"";
		   }
		   else {
			   if(el.attr('placeholder')==el.val()) el.val('');
			   attrs[el.attr('name')] = el.val();
		   }
		   
		})

		url = document.location.pathname + '?mode=_ajax&_imod[]=Dfe_Modules_SearchBoxHomeUsed_Module';
		
		for(key in attrs) {
		    url += '&'+key+'='+escape(attrs[key]);
		}
		
		searchboxUsed._request(url);
	},
	
	_getFormElements: function() {
		return jQuery("#"+searchboxUsed.containerID+" form input,#"+searchboxUsed.containerID+" form select");
		
	},
	
	_request: function(url) {
		//els = searchboxUsed._getFormElements().attr('disabled','true');
		searchboxUsed._blockForm();
		jQuery.ajaxSetup({ cache: false });
		jQuery.get(url, searchboxUsed._requestComplete);
	},
	
	_blockForm: function() {
		jQuery("#"+searchboxUsed.containerID).block({css: {border: 0, background: 'none', padding: '5px', width: '45px', marginTop: '-15px'}, message: "<img src='/public/images/loading-animation.gif' />"});
	},
	_unblockForm: function() {
		//jQuery("#"+searchboxUsed.containerID).unblock();
	},
	
	_requestComplete: function(data) {
		dom = jQuery(data);
		
		searchboxUsed._unblockForm();
		//searchboxUsed._getFormElements().removeAttr('disabled');
		jQuery('#'+searchboxUsed.containerID).html('').append(dom.html()).find('input[name=keyword]').each(function() {
			inputPlaceholder(this);
		});		
	}
}

jQuery(function() {
	searchboxUsed.init("searchbox_container_used");
})
