function populateResortList(resList,alias,name) {
	var c;
	if (c = document.getElementById('resort-list-'+resList)) {
		c.innerHTML = '';
		var listValue = document.getElementById(resList).value;
		if (listValue == null || (typeof listValue == 'string' && listValue.trim()=='')){
 			c.innerHTML = '<p>- empty -</p>';
		} else {
			var listItems = listValue.split('||');
			var html = '';
			var resArr = new Array();
			for (var i=0; i<listItems.length; i++) {
				var x = listItems[i].split('^');
				var highlight = false;
				var fadefrom = new Array(255,255,51); // rgb colour
				if (alias && alias == x[0]) {
					highlight = true;
					for (var j=1; j<=10; j++) {
						setTimeout('if (cn = document.getElementById("'+resList+'-item'+i+'")) cn.style.backgroundColor="rgb('+Math.round(fadefrom[0]+(j/10)*(255-fadefrom[0]))+','+Math.round(fadefrom[1]+(j/10)*(255-fadefrom[1]))+','+Math.round(fadefrom[2]+(j/10)*(255-fadefrom[2]))+')";', ((j/10)*1000)+500);
					}
				}
				
				resArr.push(x[0]);
				html += '<li> <span id="'+resList+'-item'+i+'"'+(highlight?' style="background-color:rgb('+fadefrom[0]+','+fadefrom[1]+','+fadefrom[2]+');"':'')+'>'+x[1]+'</span> <a href="javascript://" onClick="removeResortFromList(\''+resList+'\',\''+x[0]+'\')">Remove</a></li>';
			}
			c.innerHTML = html;
		}
	}
}

function resortIsInList(resList,alias) {
	var listValue = document.getElementById(resList).value;
	if (listValue == null || listValue == '') return false;
	var reg = new RegExp("\\b"+alias+"\\b");
	return reg.test(listValue);
}

function addOtherResortToList(resList){
	var name = $('#other_resort_'+resList).attr('value');
	if (name == null || (typeof name == 'string' && name.trim()=='')){ return false }
	var alias = name;
	alias = alias.trim();
	alias = alias.replace(/[^a-zA-Z]/gi,'-');
	alias = alias.replace(/--+/g,'-');
	alias = alias.replace(/^-+/g,'');
	alias = alias.replace(/-+$/g,'');
	var d = new Date();
	$('#other_resort_'+resList).attr('value','');
	addResortToList(resList,'newResort-'+alias+'-'+d.getTime(),name);
	return false;
}

function addResortToList(resList, alias, name) {
	name = name.trim();
	if (resortIsInList(resList,alias)) {
		populateResortList(resList,alias,name);
		return false;
	}

	var listValue = document.getElementById(resList).value;
	listValue = listValue.trim();
	listValue += ((listValue)?'||':'')+alias+'^'+name;
	document.getElementById(resList).value = listValue;
	populateResortList(resList,alias,name);
	return false;
}

function removeResortFromList(resList,alias) {
	var listValue = document.getElementById(resList).value;
	if (listValue == null) {
		return false;
	}
	var listItems = listValue.split('||');
	for (var i=0; i<listItems.length; i++) {
		if (alias.indexOf(listItems[i].split('^')[0]) != -1) {
			listItems.splice(i, 1); // remove this item from the array
		}
	}
	listValue = listItems.join('||');
	if (listValue == '') listValue = ' ';
	document.getElementById(resList).value = listValue;
	populateResortList(resList);
	return false;
}

