﻿
$(function() {
	$('textarea[maxlen]').each(checklength);
	$('textarea[maxlen]').keyup(checklength);
	$('input').keypress(function(e) { return e.which != 13; });
	//$('.area').sortable({ containment:'parent', handle:'div.menu', items:'div.block' });
});

function checklength() {
	var max = parseInt($(this).attr('maxlen'));
	if ($(this).val().length > max) {
		$(this).val($(this).val().substr(0, $(this).attr('maxlen')));
	}
	$(this).parent().find('.charsRemaining').html('' + (max - $(this).val().length) + ' Characters Remaining');
}

function IsChecked(sender, args) {
	args.IsValid = $("#" + sender.id.replace(/_Check/, '')).attr("checked");
}

//-- CONFIRM --\\
$(function() {
	$('.confirm').each(function(i, e) {
		var name = $(e).attr('value');
		if (name == undefined && $(e).children.length > 0) name = $(e).children(0).attr('alt');
		if (name == undefined) name = $(e).html();
		e.handler = eval($(e).attr('onclick'));
		$(e).attr('onclick', null);
		$(e).click(function() {
			if (!confirm('Are you sure you want to ' + name + '?')) return false;
			if (e.handler) return e.handler();
			return true;
		});
	});
});

jQuery.fn.hoverClass = function(cls) {
	var o = $(this[0]);
	o.hover(
		function() { o.addClass(cls); },
		function() { o.removeClass(cls); }
	);
};

//-- BLOCK HOVER --\\
$(function() {
	$("div.area").hover(
		function() { $(this).addClass("border"); },
		function() { $(this).removeClass("border"); }
	);
	$("div.block").hover(
		function() { $(this).children("div.menu").show(); },
		function() { $(this).children("div.menu").hide(); }
	);
});

jQuery.fn.editArea = function() {
	if (typeof editAreaLoader == "undefined") return;
	var o = $(this[0]);
	editAreaLoader.init({
		id: o.attr('id')	// id of the textarea to transform	
		, start_highlight: true
		, allow_resize: 'y'
		, allow_toggle: true
		, language: 'en'
		, syntax: 'html'
		, toolbar: 'search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help'
		, syntax_selection_allow: 'css,html,js,php,python,vb,xml,c,cpp,sql,basic,pas'
		//		,is_multi_files: true
		//		,EA_load_callback: 'editAreaLoaded'
		, show_line_colors: true
	});
}

$(function() {
	$('textarea.editArea').editArea();
});
