function irNueva(pagina) {
    var win = window.open(pagina, 'IriaCastro', "toolbar=no,location=no,direction=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=1024,height=768");
    win.focus();
    return false;
}

function ir(pagina) {
    if (pagina && pagina != "") { self.location = pagina; }
}

function pte()
{
    alert('Funcionalidad pendiente de implementar');
}

function modalIframe(href)
{
    var h = 550, w = 825;

    // if (width) { w = width; } if (height) { h = height; }

    var iframe = '<div class="divModal"><iframe id="modal_iframe" width="' + w + 'px" height="' + h + 'px" scrolling="no" frameborder="0" src="' + href + '" /></div>';
    $(iframe).dialog({ modal: true, overlay: { opacity: 0.6, background: 'black' }, width: w + 'px' });
}

function confirmarSubmit(f, pregunta, accion)
{
    if (confirm("¿Está seguro/a de que desea " + pregunta + "?")) {
        f.action = accion;
        f.submit();
    }
}

function confirmarTo(pregunta, pagina)
{
    if (confirm("¿Está seguro/a de que desea " + pregunta + "?")) {
        ir(pagina);
    }
}

function submitTo(f, accion)
{
    f.attr('action', accion);
    f.submit();
}

function statusMsg(msg) {
    window.status = msg;
    return true
}

function ordenar(destino, id, orden, tipo)
{
    ir(destino + '?id=' + id + '&orden=' + orden + '&tipo=' + tipo);
}

/* Piezas */
var carrusel = {}, carruselHome = {};

function moverSlide(id, d)
{
    var datos = carrusel[id], current = parseInt(datos[0]) + d, total = datos[1], num = datos[2];

    $('.flechaDer').show(); $('.flechaIzq').show();
    if (current + num - 1 >= total) { current = total - num; $('.flechaDer').hide(); }
    if (current + num - 1 == total - 1) { $('.flechaDer').hide(); }

    if (current < 0) { current = 0; $('.flechaIzq').hide(); }
    if (current == 0) { $('.flechaIzq').hide(); }

    $('#pieza' + id + ' .slide').hide();

    for (var i = 0; i < num; i++) { $('#slide' + id + '_' + (current + i)).show(); }

    carrusel[id] = [current, total, num];
}

function moverSlideHome(d)
{
    var datos = carruselHome, current = parseInt(datos[0]) + d, total = datos[1], num = datos[2];

    $('.flechaDerDes').show(); $('.flechaIzqDes').show();
    if (current + num - 1 >= total) { current = total - num; $('.flechaDerDes').hide(); }
    if (current + num - 1 == total - 1) { $('.flechaDerDes').hide(); }

    if (current < 0) { current = 0; $('.flechaIzqDes').hide(); }
    if (current == 0) { $('.flechaIzqDes').hide(); }

    $('.contenidoDestacado' + ' .slide').hide();

    for (var i = 0; i < num; i++) { $('#slide' + '_' + (current + i)).show(); }

    carruselHome = [current, total, num];
}

function initPolitica()
{
    $('#politica').hide();
}

function abrirPolitica()
{
    $('#politica').show();
}

function enviarReserva(op)
{
    var datos = {};

    $('#guardar input:text').each( function() { datos[$(this).attr('name')] = $(this).val(); } );
    $('#guardar input:hidden').each( function() { datos[$(this).attr('name')] = $(this).val(); } );
    $('#guardar textarea').each( function() { datos[$(this).attr('name')] = $(this).val(); } );

    $.post('ops.php', {'op': op, 'datos': datos }, function(data) {
        if (data == 'OK') { top.location.href = homeUrl + '/index.php?nodId=' + datos['nodId'] + '&send=1'; }
        else { alert(data); }
    });
}

function enviarLogin()
{
    var datos = {};

    $('#alumnos input:text').each( function() { datos[$(this).attr('name')] = $(this).val(); } );
    $('#alumnos input:password').each( function() { datos[$(this).attr('name')] = $(this).val(); } );

    if (datos['usuario'] == '') { alert('Debes introducir usuario'); return; }
    if (datos['password'] == '') { alert('Debes introducir password'); return; }

    $.post('ops.php', {'op': 'areaAlumnos', 'datos': datos }, function(data) {
        if (data == 'OK') { top.location.href = homeUrl + '/alumnos.php'; }
        else { alert(data); }
    });
}

/* Más info */
function masInfo()
{
    $('.contenidoInfo').toggle();
    $('.contenidoGoogle').hide();
}

function abrirMapa()
{
    $('.contenidoGoogle').toggle();
}

function reservarCurso()
{
    $('#contenido').toggle();
    $('#reserva').toggle();
}

function avisoLegal()
{
    $('.avisoLegal').toggle();
    $('.avisoLegal #scrollPanePie').jScrollPane({scrollbarWidth: 20});
}

/* Un poco chapuza*/
function cerrarModal()
{
    parent.document.location.reload();
}


function initTipo(tipo)
{
    $('.enlace').hide();
    $('#tipo' + tipo).show();
}

function actualizaTipo()
{
    var tipo = $("#enlaceFlg").val();
    initTipo(tipo);
}

function borrarFoto(fotId)
{
    if (confirm("¿Está seguro/a de que desea borrar la imagen?"))
    {
        ir('borrarFoto.php?fotId=' + fotId);
    }
}

function initCheckbox()
{
    var opsCheckbox = { empty: homeUrl + '/images/empty.png'};
    $('input[@type=checkbox]').checkbox(opsCheckbox);
    $('input[@type=radio]').checkbox(opsCheckbox);
}

function initSelectBox()
{
    $('select').selectbox();
}

function initScrollPane(id)
{
    $('#' + id).jScrollPane({scrollbarWidth: 20});
}

function modalImagen(urlImagen)
{
    if (urlImagen == '') { return; }

    var html = '<div id="basic-modal-content"><img src="' + urlImagen + '"/></div>';
    $.modal(html, {position: ['20%', '30%']});
}

function init()
{

}


function initDatePicker(id)
{
	jQuery(function($){
		$.datepicker.regional['es'] = {
			closeText: 'Cerrar',
			prevText: '&#x3c;Ant',
			nextText: 'Sig&#x3e;',
			currentText: 'Hoy',
			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'],
			dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
			dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
			dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
			weekHeader: 'Sm',
			dateFormat: 'dd/mm/yy',
			firstDay: 1,
			isRTL: false,
			showMonthAfterYear: false,
			yearSuffix: ''};
		$.datepicker.setDefaults($.datepicker.regional['es']);
	});

	$(document).ready(function() {
	   $("#" + id).datepicker();
	});
}


$(document).ready( init );
