function selectToggle(toggle, form) {
 var myForm = document.forms[form];
 for( var i=0; i < myForm.length; i++ ) { 
  if(toggle) {
       myForm.elements[i].checked = "checked";
  } 
  else {
   myForm.elements[i].checked = "";
  }
 }
};
(function ($) {
  $(document).ready(function() {
    promo_selection_management_build();
    $('.promo_selection_management').each(function(index) {
      $(this).parent().siblings('select').mouseup(function() {
        promo_selection_management_build($(this).attr('id'));
      });
    });
  });
})(jQuery);

function promo_selection_management_build (select_id) {
  $ = jQuery;
  if (typeof(select_id) == 'undefined') {
    var selects = $('.promo_selection_management');
  } 
  else {
    var selects = $('#' + select_id).parent().find('.promo_selection_management');
  }
  selects.each(function(index) {
    var selectedList = $(this);
    selectedList.html('<strong>Selected</strong>:<br><ul></ul>');
    
    $(this).parent().siblings('select').find('option:selected').each(function(index){
      var opt = $(this);
      item = $('<li><a href="#">[X]</a> ' +  opt.text() + '</li>');
      item.find('a').click(function(){
        $(opt).attr('selected', false);
        $(this).parent().remove();
        return false;
      });
      selectedList.find('ul').append(item);
    });
  });
};
/*
	--------------------------------------------------------------------------
	(c) 2007 Lawrence Akka
	 - jquery version of the spamspan code (c) 2006 SpamSpan (www.spamspan.com)

	This program is distributed under the terms of the GNU General Public
	Licence version 2, available at http://www.gnu.org/licenses/gpl.txt
	--------------------------------------------------------------------------
*/

(function ($) { //Standard drupal jQuery wrapper.  See http://drupal.org/update/modules/6/7#javascript_compatibility
// load SpamSpan
Drupal.behaviors.spamspan = {
  attach: function(context, settings) {
// get each span with class spamspan
       $("span.spamspan", context).each(function (index) {
// for each such span, set mail to the relevant value, removing spaces
	    var _mail = ($("span.u", this).text() +
	    	"@" +
	    	$("span.d", this).text())
	    	.replace(/\s+/g, '')
	    	.replace(/\[dot\]/g, '.');
// Find the header text, and remove the round brackets from the start and end
	    var _headerText = $("span.h", this).text().replace(/^ ?\((.*)\) ?$/, "$1");
	    // split into individual headers, and return as an array of header=value pairs
	    var _headers = $.map(_headerText.split(/, /), function(n, i){
            return (n.replace(/: /,"="));
          });
// Find the anchor text, and remove the round brackets from the start and end
	    var _anchorText = $("span.t", this).text().replace(/^ \((.*)\)$/, "$1");
// Build the mailto URI
  var _mailto = "mailto:" + encodeURIComponent(_mail);
  var _headerstring = _headers.join('&');
  _mailto += _headerstring ? ("?" + _headerstring) : '';
// create the <a> element, and replace the original span contents
   	    $(this).after(
		$("<a></a>")
		.attr("href", _mailto)
		.html(_anchorText ? _anchorText : _mail)
		.addClass("spamspan")
		).remove();
	} );
}
};
}) (jQuery);;

