function ycClick(style,id){
	// style is either 'check' or 'radio'
	// id is the id of the hidden input
	// if a third argument is passed,
	// 	 turns other inputs with same name off (eg. radio button)
	// jQuery chokes on '.' in id

	var c = document.getElementById(id);
	var i = document.getElementById(id + '_i');
	var toggle = arguments[2] ?  arguments[2] : false;
	var checked = '/images/yovo/' + style + '-on.gif';
	var unchecked = '/images/yovo/' + style + '-off.gif';

	if(toggle)
	{
		var name = c.name;
		var rb = $("input[@name='" + name + "']");

		$(rb).each(function(){
			this.checked = false;
			var ri = $(this).next('a').children('img:first');
			$("#event_name").val(ri.src);
			if ($(ri).attr('src') == checked)
				$(ri).attr('src',unchecked);
		});
		c.checked = true;
		i.src = checked;
	}
	else
	{
		if(c.checked == true)
		{
			c.checked = false;
			i.src = unchecked;
		}
		else
		{
			c.checked = true;
			i.src = checked;
		}
	}
}

// shows and hides the permission msx inputs
function pLevChange(s,uid){
    if(s.options[s.selectedIndex].value == 'list'){
        $('#' + uid + '_per_list').show();
    } else {
        $('#' + uid + '_per_list:visible').hide();
    }
}

// toggle contact name/email inputs on new signup form
function toggleForFriend(s){
    if(s.selectedIndex==1){
        $('tr.ff:hidden').show();
        $('tr.fu:visible').hide();
    } else {
        $('tr.fu:hidden').show();
        $('tr.ff:visible').hide();
    }
}

// prompt user to enter a new value that is added as a select option
function custom_select_val(select_elm, prompt_text){
  if(val = prompt(prompt_text, '')) {
    var option = document.createElement('option');
    option.setAttribute('value', val);
    option.innerHTML = val;
    option.selected = true;
    select_elm.appendChild(option);
  } else {
    select_elm.options[0].selected = true;
  }
};

function findUserAutocomplete(){
    $("#find_user_id").autocomplete("autocomplete_names", {
            minChars: 2,
            width: 275,
            matchContains: true,
            extraParams: {type: "User"},
            max: 15,
            formatItem: function(row, i, max) {
                    return row[0] + ' (' + row[1] + ')';
            },
            formatResult: function(row) {
                    return row[0] + ' (' + row[1] + ')';
            }
    });

    $("#find_user_id").result(function(event, data, formatted) {
            $("#new_user_id").val(data[2]);
    });

    $("#find_user_id").bind("focus", function(e){
        $(this).prev('label.inside-ac').css("visibility","hidden");
    }).bind("blur", function(e){
        if ($(this).val()=='') {
            $("#new_user_id").val('');
            $(this).prev('label.inside-ac').css("visibility","visible");
        }
    }).blur();
}

// add highlighting to focused form fields
// add datePicker to inputs with class="cal"
// This gets called as needed from ajax calls
function formEffects() {
//makeEditor();

  $(".focusable").focus(function() {
      $(".focusable").removeClass("focused");
      $(this).addClass("focused");
  }).blur(function() { $(this).removeClass("focused"); });
  $('.hoverable').hover(function() {
    $(this).addClass('hovered');
      }, function() {
    $(this).removeClass('hovered');
  });

  // catch the error caused when jQuery.datePicker.js is not loaded
  // that would otherwise prevent any script that comes after it from running
  try {
    //$('input.cal').not('.dp-applied').datePicker({startDate:'01/01/1996',showYearNavigation: false});
    $('input.cal').not('.dp-applied').datepicker();
  } catch(err) {
    // continue
  }

  // same goes for autocomplete
  if($("#find_user_id").length > 0){
      try {
        findUserAutocomplete();
      } catch(err) {
        // continue
      }
  }
  //try {
  //  $('#wysiwyg').wysiwyg();
  //} catch(err) {
    // continue
  //}


}

// Removes Ckeditor based on Id (FYI: we always use the same id)
function removeEditor() {
  try {
    var editor = $('#jquery_ckeditor').ckeditorGet(); 

    if (editor) { 
      editor.destroy();
      editor = null;
    }
  } catch(err) {
    //continue
  }

}

// Creates Ckeditor based on Id (FYI: we always use the same id)
function makeEditor() {

  var config = {
   toolbar:
    [
      ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList'],
      ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
      [ 'Link', 'Unlink', 'Image', 'Anchor'],
      ['Paste','PasteText','PasteFromWord'],
      ['RemoveFormat'],
      '/',
      ['Format','Font','FontSize', 'TextColor'],
      ['Scayt', '-', 'Source', '-', 'Undo', 'Redo']
    ]
  };
  $('#jquery_ckeditor').ckeditor(config);
}

// On window load
$(function(){
  formEffects();
});


