﻿function showModal(inputName, objectID, objectType, parentID, connectionName) {
//    alert(parentID);
	if (jQuery('#' + inputName)) {
		jQuery.facebox(function($) { 
			jQuery.get(
				'/0_262.aspx', 
				{
					'inputName': inputName,
					'object': objectID,
					'objectType': objectType,
					'search': '',
					'selected': jQuery('#' + inputName).val(),
					'showmodal': 1,
					'hash': new Date(),
					'parentID': parentID,
					'connection': connectionName,
					'rnd': Math.random()
				}, 
				function(data) {
					jQuery.facebox(data);
					jQuery('#_mt_'+objectID).multiselectable();
				}
			)
		})
	}
}

String.prototype.trim = function () {
	return this.replace(/(^\s+)|(\s+$)/g, "");
}

function applySelected(from, to) {
	if (jQuery(to).length && jQuery(from).length) {
		if (jQuery(from).val()) {
			var ids = jQuery(from).val();
			jQuery(to).val(ids.join(','));
			
			var titles = new StringBuilder();
			for (option in ids) {
				titles.Append('<div class="m_item">[ <span>', jQuery(from).find('option[value=' + ids[option] + ']').text().trim(), '</span> ]</div>');
			}
			jQuery(to+'_titles').html(titles.ToString(' ')); 
		} else {
			jQuery(to).val('');
			jQuery(to+'_titles').empty();
		}
	}
}