jQuery.ajaxSetup({
  beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
});

var NestedAttributesJs = {
  add : function(e) {
    element = Event.findElement(e);
    template = eval(element.href.replace(/.*#/, '') + '_template');
    element.insert( { before: NestedAttributesJs.replace_ids(template) } );
  },
  replace_ids : function(template){
    var new_id = new Date().getTime();
    return template.replace(/NEW_RECORD/g, new_id);
  }
};

function showHideChannels(){
	var cat = $('#tv1_category :selected').text();
	$selChannel = $('#channel_select');
	$lblChannel = $('label[for=channel_select]');
	if (cat=='Personal Channel'){
		$selChannel.hide();
		$lblChannel.hide();
	} else {
		$selChannel.show();
		$lblChannel.show();
	}
}

function styleForm(){
	$('.styled_input, .file_input').addClass("idleField");
	$('.styled_input[id!=vlog_tv1_category_readonly][id!=vlog_tv1_channel_readonly], .file_input[id!=vlog_tv1_category_readonly][id!=vlog_tv1_channel_readonly], .description_box[id!=vlog_tv1_category_readonly][id!=vlog_tv1_channel_readonly]').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if(this.value != this.defaultValue){
			this.select();
		}
	});

	$('.styled_input, .file_input').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
	});
}

$(document).ready(function() {
	styleForm();
	showHideChannels();
});

