(function($) {
	$.fn.resetOnFocus = function() {
		return this.each(function() {
			var el = $(this);var texto = el.val();
			$(this).focus(function() {if (this.value == texto) {this.value = '';}
			})//.blur(function() {if(el.val() == '') {el.val(texto);}	});
		});
	}; 
	
	$.fn.charCount = function(val) {
		return this.each(function() {
			var el = $(this);
			
			var charCount = parseInt(el.attr('maxlength'));
			if (charCount == -1 || isNaN(charCount)) {
				charCount = val || 1000;
			}
				
			var span = $('<span class="contadorLetras">'+charCount+'</span>');
			
			var verificar = function(numero) {
				if(numero >= 0) 
					return true;
				return false;
			};
			
			var update = function() {
				var largo = (el.val() == "")?0:parseInt(el.val().length);
				if(largo > charCount)
					el.val(el.val().substr(0,charCount));
				span.text(charCount - largo);
			};
		
			el.after(span).keyup(function() {
				update();				
			}).keypress(function(e) {
				if(e.which == 8) 
					return true;
				return verificar(charCount - (el.val().length+1));
				
			}).blur(function() {
				update();	
			}).queue(function() {
				update();
			})
		});
	};
	
})(jQuery);



$(document).ready(function() {
	$('.resetOnFocus').resetOnFocus();
	$('#ingresoIdea').find('textarea').charCount(1000);
	
	$('.pestanaLinkedIn').fancybox({
		width: 600,
		height: 400,
		titleShow: false,
		content: '<iframe src="/wp-content/themes/movistarinnova/widgets/linkedin.php" frameborder="0" border="0" width="650" height="335"></iframe>'
	});
	
});


function soloNumeros(evt){
	var key = evt.keyCode ? evt.keyCode : evt.which ;
	return (key <= 31 || (key >= 48 && key <= 57)); 
}
 
function soloLetras(evt){
	var key = evt.keyCode ? evt.keyCode : evt.which ;
	return (key <= 31 || key == 32 || (key >= 65 && key <= 90) || (key >= 97 && key <= 122) || key == 45 || key == 95); 
}

function getRecuperarClave(){
	$('#cajaLogeoDerecha').hide();
	$('#cajaLogeoDerechaRecuperar').show();
}

function getIngresarClave(){
	$('#cajaLogeoDerechaRecuperar').hide();
	$('#cajaLogeoDerecha').show();
}

function getFormLogin(){
    $('#logeoHome').validate({
        errorPlacement: function(error, element) {},
        highlight: function(element, errorClass, validClass) {
             $(element).addClass(errorClass);
        },
        unhighlight: function(element, errorClass, validClass) {
             $(element).removeClass(errorClass).addClass(validClass);
        }
    });
    if ($('#logeoHome').valid()) {
        $('#logeoHome').submit();
    }
}

function getFormRecuperarClave(){
	var rut = $('#rutRecuperar').val();
    if (rut == '') {
        $('#rutRecuperar').addClass('error');
    } else {
    	$(window.location).attr('href', '/recuperar-clave/?id='+rut);
    }
 
	//$('#logeoHomeRecuperar').submit();
}

function submitFormIngresoIdea() {
    $('#ingresoIdea').submit();
    return false;
}

function guardarForm() {
    $.ajax({
        url: window.location.href, 
        type: "post",
        data: $('#ingresoIdea').serialize()
    });
}
function getPaso1(){
	$('#h1Celeste').html('Identifica tu idea');
	$('#contenidoIngresoIdeaPaso2').hide();
	$('#contenidoIngresoIdeaPaso3').hide();
	$('#contenidoIngresoIdeaPaso4').hide();
	$('#contenidoIngresoIdeaPaso5').hide();
	$('#contenidoIngresoIdeaPaso1').fadeIn("slow");
    guardarForm();
}

function getPaso2(){
	$('#h1Celeste').html('El problema a resolver');
	$('#contenidoIngresoIdeaPaso1').hide();
	$('#contenidoIngresoIdeaPaso3').hide();
	$('#contenidoIngresoIdeaPaso4').hide();
	$('#contenidoIngresoIdeaPaso5').hide();	
	$('#contenidoIngresoIdeaPaso2').fadeIn("slow");
    guardarForm();
}

function getPaso3(){
	$('#h1Celeste').html('Idea de negocio')
	$('#contenidoIngresoIdeaPaso1').hide();
	$('#contenidoIngresoIdeaPaso2').hide();
	$('#contenidoIngresoIdeaPaso4').hide();
	$('#contenidoIngresoIdeaPaso5').hide();	
	$('#contenidoIngresoIdeaPaso3').fadeIn("slow");
    guardarForm();
}

function getPaso4(){
	$('#h1Celeste').html('Mercado objetivo');
	$('#contenidoIngresoIdeaPaso1').hide();
	$('#contenidoIngresoIdeaPaso2').hide();
	$('#contenidoIngresoIdeaPaso3').hide();
	$('#contenidoIngresoIdeaPaso5').hide();	
	$('#contenidoIngresoIdeaPaso4').fadeIn("slow");
    guardarForm();
}

function getPaso5(){
	$('#h1Celeste').html('Tiempos y costos');
	$('#contenidoIngresoIdeaPaso1').hide();
	$('#contenidoIngresoIdeaPaso2').hide();
	$('#contenidoIngresoIdeaPaso3').hide();
	$('#contenidoIngresoIdeaPaso4').hide();	
	$('#contenidoIngresoIdeaPaso5').fadeIn("slow");
    guardarForm();
}

function enviarPreguntas(){
	$('#ingresoIdea').submit();
}

function paso1Tutoria(){
	$("#paso2Agendamiento").hide();
	$('#paso1Agendamiento').fadeIn("slow");
}

function paso2Tutoria(){
	$("#paso1Agendamiento").hide();
	$('#paso2Agendamiento').fadeIn("slow");
}

function paso3Tutoria(){
	var fecha = $('input[type=radio][name="Disponible"]:checked').val();
	$('#fechaPaso3Agendamiento').html(fecha.substr(0, 10));
	$('#horaPaso3Agendamiento').html(fecha.substr(11, 16));
	$("#paso2Agendamiento").hide();
	$('#paso3Agendamiento').fadeIn("slow");
}

function horarioTutoria2(){
	$("#btnFlechaDerecha").hide();
	$("#horarisDisponibles").hide();
	$("#contenedorFechasMueve").hide();
	$('#horarisDisponibles2').fadeIn("slow");	
	$('#contenedorFechasMueve2').fadeIn("slow");	
}

function horarioTutoria(){
	$("#btnFlechaDerecha").show();
	$("#horarisDisponibles2").hide();
	$("#contenedorFechasMueve2").hide();
	$('#horarisDisponibles').fadeIn("slow");	
	$('#contenedorFechasMueve').fadeIn("slow");	
}

function getForm1Agenda(){
	$('#seleccionAgenda').submit();
}
function getForm2Agenda(){
	$('#agendamientoPaso2').submit();
}

function cargaTutores(){
	var area = $('#idArea').val();
	if(area != 'Seleccione'){
		$('#idTutor').attr('disabled', '');
		$.ajax({
			url: '/wp-content/themes/movistarinnova/getTutor.php',
			type: 'get',
			data: 'area='+area,
			success: function(resultado) {
				$('#idTutor').html(resultado);
			}
		});
	}else{
		$('#idTutor').attr('disabled', 'disabled');
	}
}


