
var loadActivity = function (){

	
	var value = {};
	var keys = [];
	//var options = $('.multiSelectPicklistTable .multiSelectPicklistRow select optgroup option'); 
	var options = $('.multiSelectPicklistTable .multiSelectPicklistRow select option'); 
	if ( options.length == 0  ){
		setTimeout(function(){loadActivity();},500);
	}
	else {
		$('.multiSelectPicklistTable .multiSelectPicklistRow select option').each(
			function(index,elem){
				var i = $(elem).attr('value');
				var v = $(elem).text();
				value[i] = v;
				keys.push(i);
			}
			);
		keys.sort(function compareNumbers(a, b) {
			return a - b;
		});	
		result = [];
		for (var j= 0; j< keys.length ; j++){
			var tmp = keys[j];
			result.push({"name":value[tmp],"value":tmp});
		}
		
		//Web_Contact.searchForActivity(value,  function(result, event) {
			
			//if(event.status){
			
				// UTILS.dustRender('tmpl_activity',result, $('#ActivityList'));	

				layout.listener('#ActivityList input[type=checkbox]');
				checkThechecked();

			//}
		//},
		//{escape:false});
	}
}
function checkThechecked(){
	var checked = {};
	$('.multiSelectPicklistTable .multiSelectPicklistRow span select').each(
		function (index, elem){
			var test = $(elem).attr('id');
			var n = test.indexOf('unselected');
			if (n == -1){
				$(elem).find('option').each(function (i,e){
					var tmp = $(e).text();
					checked[tmp] = true;
				})
			}
		}
	)
	$('.checkbox label').each(function (index, elem){
		var label = $(elem).html();
		if (label in checked){
			$(elem).click();
		}
	});
}

function SearchActivity (){

	UTILS.compileDustTemplates();
	loadActivity();
	//pageEvent();
}

function retrieveValues (){
	var values = [];
	
	$('#ActivityList .mediumCheckbox .checkboxButton input').each(
		function (index , elem){ 
			if($(elem).prop('checked')){
				values.push($(elem).attr('id'));
			}
		});
	
	$('.multiSelectPicklistTable .multiSelectPicklistRow span select').each(
		function (index, elem){
			var test = $(elem).attr('id');
			var n = test.indexOf('unselected');
			if (n>0){
				
				$(elem).val(values);
			}
		}
	)
	
	$('.multiSelectPicklistCell a img').click();
	setTimeout(function(){sendRequest();},500);
	
}