function enviar() {
	var opt = {
		// Use POST
		method: 'post',
		postBody:  Form.serialize('formularioNegocios'),
		// Handle successful response
		onSuccess: function(t) {
			Element.show('mensajeExito');
			Element.hide('enviandoMensaje');
		},
		// Handle 404
		on404: function(t) {
			alert('Error 404: location "' + t.statusText + '" was not found.');
			Element.show('formularioNegocios');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
			Element.show('formularioNegocios');
		}
	}
	new Ajax.Request('/es/servicios/formacion_negocios/index.php', opt);
	Element.hide('formularioNegocios');
	Element.show('enviandoMensaje');
	Element.hide('mensajeError');
	Element.hide('botonEnviar');
}

function verificarRolOperativo() {
	var listado = $("rolOperativo");
	var tipoRolOperativo = listado.value;
	var filaOtro = $("rolOperativoOtraOpcion");

	switch (tipoRolOperativo) {
		case "Otro" :
			filaOtro.show();
			break;
		default :
			filaOtro.hide();
	}
}

function charCounter(id, maxlimit, limited){
	if (!$('counter-'+id)){
		$(id).insert({after: '<div id="counter-'+id+'" class="contador_caracteres"></div>'});
	}
	
	var strip = $F(id).replace(/(<([^>]+)>)/ig,"");
	
	if (strip.length >= maxlimit) {
		if (limited) {	
			$(id).value = strip.substring(0, maxlimit); }
			$('counter-'+id).addClassName('charcount-limit');
	} else {	
		$('counter-'+id).removeClassName('charcount-limit');
	}
	$('counter-'+id).update( strip.length + '/' + maxlimit );	
		
}

function makeItCount(id, maxsize, limited){
	if (limited == null) limited = true;
	if ($(id)){
		Event.observe($(id), 'keyup', function(){charCounter(id, maxsize, limited);}, false);
		Event.observe($(id), 'keydown', function(){charCounter(id, maxsize, limited);}, false);
		charCounter(id,maxsize,limited);
	}
}

$j(document).ready(function() {
	
	$j('.counter').each(function(){
		makeItCount($j(this).attr('id'), $j(this).attr('maxlength'), true);
	});
	
	$j('select.otros').change(function(){
		if ($j(this).val() == 'otro') {
			$j(this).hide();
			var input_otros = $j(this).attr('id') + '_' + 'otro';
			$j('#' + input_otros).show();
			$j('#' + input_otros).addClass('isNotEmpty');
			$j('#label_' + $j(this).attr('id')).attr('id', 'label_' + $j(this).attr('id') + '_otro');
			$j('#label_' + $j(this).attr('id')).attr('for', $j(this).attr('id') + '_otro');
		}
	});
	
	$j('input[type=checkbox].otros').change(function() {
		var input_otros = $j(this).attr('name') + '_' + 'otro';
		if ($j(this).is(':checked')) {
			$j('#' + input_otros).show();
			$j('#' + input_otros).addClass('isNotEmpty');
		} else {
			$j('#' + input_otros).hide();
			$j('#' + input_otros).removeClass('isNotEmpty');
		}
	});
	
	$j('#integrantes_equipo_AEP').change(function(){
		if ($j(this).val() != '0') {
			$j('.integrantes_holder').load('/site/include/forms/formAdmisionAEP_integrante_equipo_emprendedor.inc?cantidad_integrantes=' + $j(this).val());
		} else {
			$j('.integrantes_holder').empty();
		} 
	});
	
	$j('.isDate').each(function() {
		$j(this).datepicker({
			changeMonth: true,
			changeYear: true,
			yearRange: '1950:2010',
			dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
			dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
			dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
			monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
			monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
			dateFormat: 'yy-mm-dd'
		});
	});
	
	
});