
	
common.prototype.validate_shop_minisearch = function(){
//declaring the 'current_form'
var cf='shop_minisearch';
//disabling the form
sw.enableform(cf, false);
//global variables
this.allow_to_sent="yes";
this.field_status=new Array();
this.missing_fields_msg="";
//emtying (possible showned) 'form_comments'
this.sent_content_to_object(cf+'_comments','Please wait..');
//
var q=this.val_by_name(cf, 'shop_query');

	//in case the field is emty
	if (q.length==0 || this.string_only_spaces(q)==true || q=='Zoek naar...') {
	this.field_status['q']="emty";
	//disallowing the form to sent
	this.allow_to_sent="no";
	} 
	//
	if(this.field_status['q']!="valid"){
	//setting class of label to unvalid
	this.change_class(cf+"_label_"+'q', "unvalid")
	//setting class of field to unvalid
	this.change_class(cf+"_"+'q', "required unvalid");
		//in case the field is emty
		if(this.field_status['q']=="emty"){
		//adding a new line to the 'missing_fields_msg'
		this.missing_fields_msg+=''+label.field_is_emty.replace(/#item#/g, '');
		this.missing_fields_msg=this.missing_fields_msg.replace(/'/g, '');	
		}
	}
	
	//in case the form may be sended
	if(this.allow_to_sent=="yes"){
	//refreshing validation message
	this.sent_content_to_object(cf+'_comments',label.loading_in_progress+'..');
	//calling php to send the form
	var extra_vars='';
	extra_vars+='?q='+q.replace(/&/g,'[/and]');
	this.goto_url(cf, sw.ptr+sw.searchresultsurl+extra_vars, 'submit');
	}
	//in case the form contains some unvalid fields
	else{
	//refreshing 'form_comments'
	this.sent_content_to_object('shop_minisearch_comments',this.missing_fields_msg);
	//(re)enabling the form
	this.enableform(cf, true);
	}
}


//extra minisearch class declaration
function searchClass(){
	
	this.prevData = new Array();
	this.doomed = new Array();
	this.sugboxOnScreen=false;
	
	//methods
	this.lookup = function(q){
	//removing '+' sign
	q = q.replace(/\+/g, ' ');
	
		if(q.length<3 || q=='Zoek naar...') {
			sw.console('not worth loading loading from db'); 
			// Hide the suggestion box.
			ms.hide_box();
		}
		else {
		var nochanche=false;
			for(d=0; d<ms.doomed.length; d++){
				if(q.match(ms.doomed[d])){
				nochanche=true;
				sw.console('no chanche with ('+ms.doomed[d]+')!');
				}
			}
			if(nochanche){
			sw.console('no chanche!'); 
			// Hide the suggestion box.
			ms.hide_box();
			}
			else if(ms.prevData[q] != undefined){
			sw.console(q+' is already queried!'); 
				if(ms.prevData[q].length >0) {
				$('#sugbox').show();
				$('#sugbox').html(ms.prevData[q]);
				ms.sugboxOnScreen=true;
				}
				else{
				// Hide the suggestion box.
				ms.hide_box();
				}
			}
			else{
			sw.console('loading from db'); 
			$.get(sw.ptr+"CmWare/modules/shop/pages/minisearch/website/build_suggestion_list.php?dc="+sw.session_dc, {q: q, lan: sw.lan, ptr: sw.ptr, shopurl:sw.shopurl, searchresultsurl:sw.searchresultsurl}, function(data){
				if(data.length >0) {

					if(q!=sw.val_by_name('shop_minisearch', 'shop_query')){
					sw.console('the query ('+q+') is not the same as the inputyfield ('+sw.val_by_name('shop_minisearch', 'shop_query')+')');	
					}
					else{
					$('#sugbox').show();
					$('#sugbox').html(data);			
					ms.sugboxOnScreen=true;	
					}
				}
				else{
				// Hide the suggestion box.
				ms.hide_box();
				//storing (doomed) result
				ms.doomed[ms.doomed.length] = q;
				}
			//storing result
			ms.prevData[q] = data;
			sw.console('setting ms.prevData['+q+']'); 
			});
			}
		}
	}
	
	this.fill = function(v){//not used at this time
	$('#shop_minisearch_shop_query').val(v);
	setTimeout("ms.hide_box();", 200);
	}
	
	this.hide_box = function(){
	$('#sugbox').hide();
	ms.sugboxOnScreen=false;
	}
	
}

//declaring the first (minisearch) instance
var ms = new searchClass();



//copying onload
var onload_functions_at_minisearch = window.onload;
window.onload = function () {
onload_functions_at_minisearch();
//extending onload
sw.session_dc = Number(new Date());
//disallowing browsers (ff) to autocomplete 'shop_minisearch
document.getElementById("shop_minisearch").setAttribute("autocomplete", "off");	
	
	$('#shop_minisearch_shop_query').focus(function() {
	var q=sw.val_by_name('shop_minisearch', 'shop_query');
		if(q.length>0 && ms.sugboxOnScreen==false){
			ms.lookup(q);
		}
	});


	$("#shop_minisearch_shop_query").bind("mouseenter",function(){
	//document.getElementById('test').innerHTML=document.getElementById('test').innerHTML+'mouse entered fiueld'+'<br>';
	//document.getElementById('test').innerHTML=document.getElementById('test').innerHTML+'sugboxOnScreen='+ms.sugboxOnScreen+'<br>';	
	var q=sw.val_by_name('shop_minisearch', 'shop_query');
		if(q.length>0 && ms.sugboxOnScreen==false){
			ms.lookup(q);
		}
	});
	

	$("#shop_minisearch").bind("mouseleave",function(){	   
	// Hide the suggestion box.
	ms.hide_box();
	});

	////
	var pretext='Zoek naar...';
	if (sw.val_by_name('shop_minisearch', 'shop_query') == '' || sw.val_by_name('shop_minisearch', 'shop_query') == undefined) {
	$('#shop_minisearch_shop_query').attr('value', pretext);
	$('#shop_minisearch_shop_query').addClass('ini');
	}
		
	// Focus & blur effects
	$('#shop_minisearch_shop_query').focus(function(){
		if (this.value == pretext) {
			$(this).val('');
			$('#shop_minisearch_shop_query').removeClass('ini');
		}
	});
	$('#shop_minisearch_shop_query').blur(function(){
		if (this.value == '') {
			$(this).val(pretext);
			$('#shop_minisearch_shop_query').addClass('ini');
		}
	});
	////
	
}



