// JavaScript Document
var jobsSearch = {
	
	setCountryCheckBox: function(obj){
		switch(obj.value){
			case "1" :
				if(obj.checked){
					this.updateProvince_ajax();
				}else{
					this.cleanProvince();
				}
				break;
				
		}
		
		this.countJobsSelection_ajax();
	},
	
	
	updateSubcat_ajax : function(){
		if($('catid').value != ''){
			_onSuccessHandler  = this.updateSubcat_ajax_callback.bind(this);
			//_onLoadingHandler = this.onLoading_message_callback.bind(this);
			options = { 
						method: 'post',
						parameters: { action : 'updateSubCat', catId : $('catid').value},
						onSuccess: _onSuccessHandler
					  };
					  
			new Ajax.Request('/common/ajax/jobs-search/ajax_request.asp',options);
		}else{
			$('subcatTitle').hide();
			$('subcat_container').update("");
			this.countJobsSelection_ajax();
		}
	},
	
	updateSubcat_ajax_callback : function(responseRequest){
		rows = String(responseRequest.responseText).evalJSON();
		if(rows.SubCatList){
			html = ""
			i=0;
			while (i < rows.SubCatList.length) {
				html = html + '<div style="width:255px; float:left;"><input type="checkbox" style="border:0px;" name="scatid" value="' + rows.SubCatList[i] + '" onclick="jobsSearch.countJobsSelection_ajax();" >&nbsp;'+ rows.SubCatList[i + 1] +'</div>'	
				i = i + 2
			}
			$('subcatTitle').show();
			$('subcat_container').update(html);
		}		
		
		this.countJobsSelection_ajax();
		
	},
	
	updateProvince_ajax : function(){
		_onSuccessHandler  = this.updateProvince_ajax_callback.bind(this);
		//_onLoadingHandler = this.onLoading_message_callback.bind(this);
		options = { 
					method: 'post',
					parameters: { action : 'updateProvince', countryId : 1},
					onSuccess: _onSuccessHandler
				  };
				  
		new Ajax.Request('/common/ajax/jobs-search/ajax_request.asp',options)	
	},
	
	updateProvince_ajax_callback : function(responseRequest){
		rows = String(responseRequest.responseText).evalJSON();
		if(rows.CountryList){
			html = ""
			i=0;
			while (i < rows.CountryList.length) {
				html = html + '<div style="width:170px; float:left;"><input type="checkbox" style="border:0px;" name="pid" value="' + rows.CountryList[i] + '" onclick="jobsSearch.countJobsSelection_ajax();" >&nbsp;'+ rows.CountryList[i + 1] +'</div>'	
				i = i + 2
			}
			$('province_container').update(html);
			$('province').show();
		}
	},
	
	cleanProvince : function(){
		$('province_container').update("");
		$('province').hide();
		this.countJobsSelection_ajax();
	},
	
	countJobsSelection_ajax : function(){
		//console.debug($('detailSearchFrm').serialize(true));
		form = $('detailSearchFrm').serialize(true);
		
		_onSuccessHandler  = this.countJobsSelection_ajax_callback.bind(this);
		//_onLoadingHandler = this.onLoading_message_callback.bind(this);
		options = { 
					method: 'post',
					parameters: form,
					onSuccess: _onSuccessHandler
				  };
				  
		new Ajax.Request('/common/ajax/jobs-search/ajax_request.asp',options)	
		
		
	},
	
	countJobsSelection_ajax_callback : function(responseRequest){
		count = responseRequest.responseText
		if(parseInt(count) > 0){
			//html = '<strong>' + count + '</strong> jobs disponibles pour votre selection';
			html = '<strong>' + count + '</strong> ' + $('jobmessage').innerHTML;;
			$('searchResult').update(html);	
			$('submitFrm').disabled = false;			
		}else{
			//html = 'jobs non disponibles pour votre selection, affinez votre recherche';
			html = $('jobnotfind').innerHTML;
			$('searchResult').update(html);	
			$('submitFrm').disabled = true;			
		}
	}
	
}

