jQuery.fn.check = function(o){
	var options = {mode:'unchecked',context:''};
	options = jQuery.extend({}, options, o || {});
	return this.each(function() {
		switch(options.mode) {
		case 'checked':
			this.checked = true;
			break;
		default:
			this.checked = false;
		}
	});
}

jQuery.fn.autoSelect = function(v){
	this.each(function(){
		if(parseInt(this.value) == parseInt(v)){
			this.selected = true; 
		}
	});
	return this; 
}


jQuery.fn.populateList = function(o){
	this.empty();
	if( typeof o.LIST != 'undefined' && o.LIST.length ){
		for( i = 0 ; i < o.LIST.length; i++){
			jQuery('<option value="'+o.LIST[i].locationID+'">'+o.LIST[i].name+'</option>')		
			.appendTo(this);
		}
	}
	if( typeof o.DEFAULT_TEXT != 'undefined'){
		jQuery('<option value="0">'+o.DEFAULT_TEXT+'</option>')		
		.appendTo(this);
	}
	return this; 
}

jQuery.fn.extend({
 
	populate: function(o){
		return this.populateList(o);
	},
	
	selected: function(v){ 
		var elem    = this[0];
		var options = elem.options;
		for( var i = 0; i < options.length; i++ ){
			var option = options[i];
			if(parseInt(option.value) == parseInt(v)){
				option.selected = true; 
				break;
			}
		}
		return this;
	}

});




