// JavaScript Document
Search = Class.create({
	debug: false,
	debugArray: Array(),
	encoding: document.characterSet,
	baseTag: $A(document.getElementsByTagName('BASE'))[0].href,
	titleTag: $A(document.getElementsByTagName('TITLE'))[0],
	ajaxPreFixUrl: 'ajaxfunctions/search/',
	currentRequestedUrl: document.location.href.replace(this.baseTag, ''),
	
	initialize: function(){
	},
	/******************************************/
	checkForm: function(obj){
		try{
			if($F(obj)==''){
				if( ($('search_small2') && $F($('search_small2'))>0) || ($('search2') && $F($('search2'))>0) ){
					$(obj).value = '_';
					return true;
				}
				alert('Geen zoekcriteria ingevoerd!');
				return false;
			}
			return true;
		}catch(e){
			alert('Search::checkForm: ' + e);
			return false;
		}
	},
	/******************************************/
	Update_categories: function(update_obj, obj){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: true,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			ajaxOptions.parameters = { id:$F(obj) };
			var url = this.ajaxPreFixUrl + 'getListPleinen';
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert('Search::Update_categories: ' + e);
			return false;
		}
	},
	Update_subcategories: function(update_obj, obj){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: true,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			ajaxOptions.parameters = { id:$F(obj) };
			var url = this.ajaxPreFixUrl + 'getListSubpleinen';
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert('Search::Update_subcategories: ' + e);
			return false;
		}
	},
	Update_subsubcategories: function(update_obj, obj){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: true,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			ajaxOptions.parameters = { id:$F(obj) };
			var url = this.ajaxPreFixUrl + 'getListSubsubpleinen';
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert('Search::Update_subsubcategories: ' + e);
			return false;
		}
	},
	/******************************************/
	Update_brands: function(update_obj, level, obj, fromwhere){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: true,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			if(level==1){
				ajaxOptions.parameters = { id1:$F(obj), id2:0, id3:0 };
			}else if(level==2){
				ajaxOptions.parameters = { id2:$F(obj), id1:0, id3:0 };
			}else if(level==3){
				ajaxOptions.parameters = { id3:$F(obj), id1:0, id2:0 };
			}
			if(fromwhere != undefined) {
				var url = this.ajaxPreFixUrl + 'getListBrands?nofilter=1';
			} else {
				var url = this.ajaxPreFixUrl + 'getListBrands';			
			}
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert('Search::Update_brands: ' + e);
			return false;
		}
	},
	Update_models: function(update_obj, level, obj, obj1, obj2, obj3, fromwhere){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: true,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			if(level==0){
				ajaxOptions.parameters = { id1:$F(obj1), id2:$F(obj2), id3:$F(obj3), brandid:$F(obj) };
			}else if(level==1){
				ajaxOptions.parameters = { id1:$F(obj), id2:0, id3:0 };
			}else if(level==2){
				ajaxOptions.parameters = { id2:$F(obj), id1:0, id3:0 };
			}else if(level==3){
				ajaxOptions.parameters = { id3:$F(obj), id1:0, id2:0 };
			}
			if(fromwhere != undefined) {
				var url = this.ajaxPreFixUrl + 'getListModels?nofilter=1';
			} else {
				var url = this.ajaxPreFixUrl + 'getListModels';			
			}			
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert('Search::Update_models: ' + e);
			return false;
		}
	},
	/******************************************/
	Update_provincies: function(update_obj, obj){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: false,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			ajaxOptions.parameters = { id: $(obj)[$(obj).selectedIndex].value };
			var url = this.ajaxPreFixUrl + 'getListProvincies';
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert(e);
			return false;
		}
	},

	Update_modelsfrombrand: function(update_obj, obj){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: true,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			ajaxOptions.parameters = { id1: $(obj)[$(obj).selectedIndex].value };
			var url = this.ajaxPreFixUrl + 'getListModelsFromBrand';
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert(e);
			return false;
		}
	},	

	Update_modelsfrombrandplein: function(update_obj, obj1, obj2){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: true,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			ajaxOptions.parameters = { id1: $(obj1)[$(obj1).selectedIndex].value, id2: $(obj2)[$(obj2).selectedIndex].value };
			var url = this.ajaxPreFixUrl + 'getListModelsFromBrandPlein';
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert(e);
			return false;
		}
	},
	
	Update_modelsfrombrandsubplein: function(update_obj, obj1, obj2, obj3){
		try{
			var ajaxOptions = {
			  method:       'post',
			  asynchronous: true,
			  contentType:  'application/x-www-form-urlencoded',
			  encoding:     this.encoding,
			  parameters:   '',
			  evalJSON:     false,
			  evalJS:       false
			};
			ajaxOptions.parameters = { id1: $(obj1)[$(obj1).selectedIndex].value, id2: $(obj2)[$(obj2).selectedIndex].value, id3: $(obj3)[$(obj3).selectedIndex].value };
			var url = this.ajaxPreFixUrl + 'getListModelsFromBrandSubplein';
			if($(update_obj)){
				var myAjax = new Ajax.Updater($(update_obj), url, ajaxOptions);
			}
			return true;
		}catch(e){
			alert(e);
			return false;
		}
	}

});
Search = new Search();
//Event.observe(window, 'load', function(){Search = new Search();});
