/******************************************************
   AUTOR: EOLF
   WEB:   http://www.seinsico.net
   EMAIL: eolf@seinsico.net, eolf.180284@gmail.com
   FECHA: 18 - Noviembre - 2009
   DESCR: Funciones globales para el sitio
******************************************************/
var ruta_comun = "controlador/controlador.php";
var ruta_inicial = "vista/"+ruta_comun;
var ruta = "../"+ruta_comun;
function carga(ctrl) {
  $("#cargador").hide("slow");
  $("#contenido").show("slow");
  $("#pie").show("slow");
  switch(ctrl) {
    case 0:
      $("#accordion1").msAccordion({defaultid:0, autodelay:5});
      confiuracion_cu3er_ui();
	break;
	case 1:
      confiuracion_cu3er_ui();
	break;
	case 2:
      setTimeout("marquesina()",7000);
	break;
	case 3:
      confiuracion_cu3er_ui();
      configuracionCalendario();
	break;
	case 4:
      confiuracion_cu3er_ui();
  	  ocultarPartesFormulario(1);
	break;
	case 5:
      confiuracion_cu3er_ui();
      mostrarPartesServicios();
	break;
	case 6:
      ocultarPartesFormulario(2);
	break;
	case 7:
      ocultarPartesFormulario(3);
	break;
	case 8:
      ocultarPartesFormulario(4);
	break;
	case 9:
      ocultarPartesFormulario(5);
	break;
	case 10:
      confiuracion_cu3er_ui();
	  configuracionTabs();
	break;
	case 11:
  	  ocultarPartesFormulario(1);
	break;
  } // switch
  cambiarTamanio();
}
function confiuracion_cu3er_ui() {
  /* Configuraciones cu3er_ui */
  var flashvars = {};
  var idiomax = document.getElementById("idioma").value;
  flashvars.xml = "../cu3er_ui/xml/config_"+idiomax+".xml";
  var attributes = {};
  attributes.wmode = "transparent";
  attributes.id = "slider";
  swfobject.embedSWF("../cu3er_ui/cu3er.swf", "cu3er-container", "150", "350", "9", "../cu3er_ui/js/swfobject/expressInstall.swf", flashvars, attributes);
}
function configuracionTabs() {
$(".accordion div").hide();
 $(".accordion h3").click(function(){
   $(this).next("div").slideToggle("slow")
   .siblings("div:visible").slideUp("slow");
   $(this).toggleClass("active");
   $(this).siblings("h3").removeClass("active");
 });
}
function mostrarPartesServicios() {
  setTimeout("$('#_titulo_1').slideDown('slow')",4000);	
  setTimeout("$('#_logo_1').slideDown('slow')",7000);
  setTimeout("$('#_slogan_1').slideDown('slow')",9000);
  setTimeout("$('#_slogan_1').slideUp('slow')",11000);
  setTimeout("$('#_logo_1').slideUp('slow')",11000);
  setTimeout("$('#_titulo_1').slideUp('slow')",11000);
  setTimeout("$('#_titulo_2').slideDown('slow')",12000);
  setTimeout("$('#_logo_2').slideDown('slow')",14000);
  setTimeout("$('#_slogan_2').slideDown('slow')",16000);
  setTimeout("$('#_slogan_2').slideUp('slow')",18000);
  setTimeout("$('#_logo_2').slideUp('slow')",18000);
  setTimeout("$('#_titulo_2').slideUp('slow')",18000);
  setTimeout("mostrarPartesServicios()",19000);
}
function configuracionCalendario() {
  $('#calendar').fullCalendar({
	// US Holidays
	events: $.fullCalendar.gcalFeed('http://www.google.com/calendar/feeds/a63k9n085se8tqfrkjrmn7dbfg@group.calendar.google.com/public/basic'),
	eventClick: function(event) {
		// opens events in a popup window
		window.open(event.url, 'gcalevent', 'width=700,height=600');
		return false;
	}
  });
}
function ocultarPartesFormulario(ctrl) {
  switch(ctrl) {
    case 1:
	  $("#_texto_asunto").empty();
      $("#_cursosA").empty();
      $("#_cursosE").empty();
	break;
	case 2:
	  $("#_texto_asunto").show();
	  $("#_seleccion_asunto").empty();
      $("#_cursosA").show();
      $("#_cursosE").empty();
	break;
	case 3:
	  $("#_texto_asunto").show();
	  $("#_seleccion_asunto").empty();
      $("#_cursosA").empty();
      $("#_cursosE").show();
	break;
	case 4:
      $("#_seleccion_cv").empty();
      $("#_subir_cv").show("slow");
      $("#_registrar_cv").empty();
	break;
	case 5:
      $("#_seleccion_cv").empty();
      $("#_subir_cv").empty();
      $("#_registrar_cv").show("slow");
	break;
  } // switch
}
function filtrarEstados(ob) {
  var envio = "CTRL=3&id_pais="+ob.value+"&idm="+$('#idm').val()+"&secc="+$('#secc').val();
  $().ajaxStart(function() {
       $('#_ajaxseleccionpais').show();
       $('#_ajaxresultadopais').hide();
   }).ajaxStop(function() {
       $('#_ajaxseleccionpais').hide();
       $('#_ajaxresultadospais').show();
   });
   $.ajax({
       type: "POST",
       url: ruta,
       data: envio,
       success: function(datos_estados){
         $('#_ajaxresultadospais').html(datos_estados);
       },
       error: function(){
         alert("ERROR A01");
       }
   });
}

function filtrarNoticias(ob,tipo) {
  var envio = "CTRL=5&noticia="+ob.value+"&idm="+$('#idm').val()+"&tip="+tipo+"&secc="+$('#secc').val();
  $("#_ajax"+tipo+"inicial").hide();
  if(ob.value == 0) {
    $("#_ajax"+tipo+"inicial").show();
    $("#_ajax"+tipo+"resultados").empty();
  }
  else {
    $().ajaxStart(function() {
        $("#_ajax"+tipo+"espera").show();
    }).ajaxStop(function() {
        $("#_ajax"+tipo+"espera").hide();
        $("#_ajax"+tipo+"resultados").show();
    });
    $.ajax({
        type: "POST",
        url: ruta,
        data: envio,
        success: function(datos_noticias){
          $("#_ajax"+tipo+"resultados").html(datos_noticias);
        },
        error: function(){
         alert("ERROR A02");
       }
    });
  } // if else
}
function marquesina () {
  $("#marquesina").show("slow");
  fillup(); // Carrousel
}
function cambiarIdioma(obj) {
  obj.value = "ES";
  obj.disabled = true;
  alert("Funcion Temporalmente Desactivada");
  /* ACTIVAR CUANDO ESTE LISTO
  var destino = "";
  var rutax = ruta+"?CTRL=1";
  var idiomax = obj.value;
  if(idiomax.length > 0)
    destino = rutax+"&SUBCTRL="+idiomax;
  window.location.href = destino;*/
}
function redireccionarMenu(subseccion) {
  var destino = "";
  var rutax = ruta+"?CTRL=2";
  if(subseccion > 0) {
    if(parseInt(subseccion) == 4 || parseInt(subseccion) == 5) // Quitar para activar secciones
      alert("Seccion temporalmente deshabilitada");
    else {
      destino = rutax+"&SUBCTRL="+subseccion;
      window.location.href = destino;
    } // if else
  } // if
  return false;
}
function desactivada() {
  alert("Seccion temporalmente deshabilitada");
  return false;
}
function redireccionar(seccion) {
  window.location.href = ruta+"?CTRL="+seccion;
}
function redireccionarInicial(seccion) {
  //alert("--- Proximamente ---");
  window.location.href = ruta_inicial+"?CTRL=2&SUBCTRL="+seccion;
  return false;
}
var centinela = 0;
function ocultarMenu(imagen) {
  var quitar = document.getElementById("espacio");
  if(centinela == 0) {
	centinela = 1;
	cambiarImagen("abrir_"+imagen,'sideBarTabImagen');
    $("#sideBarContents").hide("slow");
    quitar.width = 30;
  }
  else {
	centinela = 0;
	cambiarImagen("cerrar_"+imagen,'sideBarTabImagen');
    $("#sideBarContents").show("fast");
    quitar.width = 170;
  } //  if else
  return false;
}
function cambiarImagen(imagen,id_imagen) {
  document.images[id_imagen].src = "../imagenes/"+imagen+".jpg";
}
function asignarTexto(origen,destino) {
  $('#'+destino).val($('#'+origen+' option:selected').text());
}
function limpiarCampo(campo){
  $("#"+campo).val('');
}
function validarFormulario(forma) {
    $.metadata.setType("attr", "validate"); // CheckBox y Select
	jQuery(function() {
		jQuery().ajaxStart(function() {
			$("#_espera").show();
		}).ajaxStop(function() {
			$("#_espera").hide();
		}).ajaxError(function(a, b, e) {
			alert("ERROR F01");
			$("#_espera").hide();
		});
		jQuery("#"+forma).validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#_respuesta"
				});
			}
		});
	});
}
function validarFormularioDirecto(forma) {
  $.metadata.setType("attr", "validate"); // CheckBox y Select
  $("#"+forma).validate();
}
function limpiarFormulario(forma) {
  $('#_recibido').hide();
  jQuery("#"+forma).validate().resetForm();
  $('#_formulario').show();
}
function quitarEnviar(forma,div1,div2) {
  cicloBorrar($("#id_empresa").val(),$("#id_empresa_limite").val(),div1)
  cicloBorrar($("#id_curso").val(),$("#id_curso_limite").val(),div2)
  validarFormularioDirecto(forma);
}
function cicloBorrar(inicio,fin,division) {
  for(i = parseInt(inicio) + 1; i <= fin; i++)
    $("#"+division+i).empty();
}
function cambiar(ctrl) {
  if(ctrl == 1) {
    $("#_subir_cv").empty();
    $("#_registrar_cv").show("slow");
  }
  else {
    $("#_subir_cv").show("slow");
    $("#_registrar_cv").empty();
  } // if else
  $("#_seleccion_cv").empty();
}
/* Funciones Botones */
function goLite(obj) {
   obj.style.color = "#F15A24";
}
function goDim(obj) {
   obj.style.color = "#FFFFFF";
}
/* Ocultar Divisiones */
function ocultarDivision(division,ctrl,aux,mensaje) {
  if(ctrl == 1) {
	if(parseInt($("#"+aux).val()) > 1) {
	  if(confirm(mensaje))
        $("#"+division).empty();
	}
	else
      $("#"+division).empty();
  }
  else
    $("#"+division).hide();
}

function validarOcultar(ctrl,paso) {
  switch(paso) {
    case 2:
	  if(verificar(ctrl,paso) == 1) {
  	    var texto = document.getElementById("form_idioma"+ctrl).options[document.getElementById("form_idioma"+ctrl).selectedIndex].text;
	    var siguiente = (ctrl+1);
        $("#_idioma"+ctrl).hide();
	    $("#_nombre_idioma"+ctrl).show();
	    $("#_nombre_idioma_aux"+ctrl).html(texto);
        $("#_idioma"+siguiente).show();
	  }
	  else
	    alert($("#_texto_validacion").val());
	break;
    case 3:
	  if(verificar(ctrl,paso) == 1) {
	    var actual = parseInt($("#id_curso").val());
	    var siguiente = (ctrl+1);
        $("#_curso"+ctrl).hide();
	    $("#_nombre_curso"+ctrl).show();
	    $("#_nombre_aux_curso"+ctrl).html($("#form_nombre_curso"+ctrl).val());
        $("#_curso"+siguiente).show();
  	    $("#id_curso").val(siguiente);
	  }
	  else
	    alert($("#_texto_validacion").val());
	break;
    case 4:
	  if(verificar(ctrl,paso) == 1) {
	    var actual = parseInt($("#id_empresa").val());
	    var siguiente = (ctrl+1);
        $("#_empresa"+ctrl).hide();
	    $("#_nombre_empresa"+ctrl).show();
	    $("#_nombre_aux"+ctrl).html($("#form_empresa"+ctrl).val());
        $("#_empresa"+siguiente).show();
  	    $("#id_empresa").val(siguiente);
	  }
	  else
	    alert($("#_texto_validacion").val());
	break;
  } // switch
}

function verificar(ctrl,paso) {
  var cerbero = 0;
  switch(paso) {
    case 2:
	  var v_idioma = document.getElementById("form_idioma"+ctrl).options[document.getElementById("form_idioma"+ctrl).selectedIndex].value;
	  var v_nivel = document.getElementById("form_idioma_nivel"+ctrl).options[document.getElementById("form_idioma_nivel"+ctrl).selectedIndex].value;
      if (v_idioma.length > 0 && v_nivel.length > 0)
	    cerbero = 1;
	break;
    case 3:
	  var v_curso = document.getElementById("form_curso"+ctrl).options[document.getElementById("form_curso"+ctrl).selectedIndex].value;
	  var v_n_curso = $("#form_nombre_curso"+ctrl).val();
	  var v_fi_mes = document.getElementById("form_ficurso_mes"+ctrl).options[document.getElementById("form_ficurso_mes"+ctrl).selectedIndex].value;
	  var v_fi_anio = document.getElementById("form_ficurso_anio"+ctrl).options[document.getElementById("form_ficurso_anio"+ctrl).selectedIndex].value;
	  var v_ff_mes = document.getElementById("form_ffcurso_mes"+ctrl).options[document.getElementById("form_ffcurso_mes"+ctrl).selectedIndex].value;
	  var v_ff_anio = document.getElementById("form_ffcurso_anio"+ctrl).options[document.getElementById("form_ffcurso_anio"+ctrl).selectedIndex].value;
	  var v_institucion = $("#form_institucion"+ctrl).val();
      if (v_curso.length > 0 && v_n_curso.length > 0 && v_fi_mes.length > 0 && v_fi_anio.length > 0 && 
		  v_ff_mes.length > 0 && v_ff_anio.length > 0 && v_institucion.length > 0)
	    cerbero = 1;
	break;
    case 4:
	  var v_empresa = $("#form_empresa"+ctrl).val();
	  var v_sector = $("#form_sector"+ctrl).val();
	  var v_p_cargo = $("#form_puesto_cargo"+ctrl).val();
	  var v_area = $("#form_area"+ctrl).val();
	  var v_i_mes = document.getElementById("form_finicio_mes"+ctrl).options[document.getElementById("form_finicio_mes"+ctrl).selectedIndex].value;
	  var v_i_anio = document.getElementById("form_finicio_anio"+ctrl).options[document.getElementById("form_finicio_anio"+ctrl).selectedIndex].value;
	  var v_f_mes = document.getElementById("form_ffin_mes"+ctrl).options[document.getElementById("form_ffin_mes"+ctrl).selectedIndex].value;
	  var v_f_anio = document.getElementById("form_ffin_anio"+ctrl).options[document.getElementById("form_ffin_anio"+ctrl).selectedIndex].value;
	  var v_s_percibido = document.getElementById("form_sueldo_percibido"+ctrl).options[document.getElementById("form_sueldo_percibido"+ctrl).selectedIndex].value;
	  var v_dactividades = $("#form_dactividades"+ctrl).val();
	  if(v_empresa.length > 0 && v_sector.length > 0 && v_p_cargo.length > 0 && v_area.length > 0 && 
		 v_i_mes.length > 0 && v_i_anio.length > 0 && v_f_mes.length > 0 && v_f_anio.length > 0 && 
		 v_s_percibido.length > 0 && v_dactividades.length > 0)
	    cerbero =1;
	break;
  } // switch
  return cerbero;
}

function cambio(imagen) {
  document.images[imagen].src = "../imagenes/informes_d.png";
  return false;
}