var t;
var tt;
var imgact;
var pact=0;
$(function () {
    
    if ($.browser.msie){
        if($('#btmetodologia').attr('class') != 'active'){
            $('#btmetodologia').hover(function() {        
                $('#btmetodologia img').attr('src','/img/menu_metodologia_hover.png');                
            }, function () {
                $('#btmetodologia img').attr('src','/img/menu_metodologia.png');
            });
        }
        
        if($('#btsoluciones').attr('class') != 'active'){
            $('#btsoluciones').hover(function() {        
                $('#btsoluciones img').attr('src','/img/menu_soluciones_formativas_hover.png'); 
                $("#m2n4").show();               
            }, function () {
                $('#btsoluciones img').attr('src','/img/menu_soluciones_formativas.png');
                t = setTimeout("fadeoutcapaexplorer('m2n4')",300);    
            });
        }else{
            $('#btsoluciones').hover(function() {        
                $("#m2n4").show();               
            }, function () {
                t = setTimeout("fadeoutcapaexplorer('m2n4')",300);    
            });
        }
        
        if($('#btformacion').attr('class') != 'active'){
            $('#btformacion').hover(function() {        
                $('#btformacion img').attr('src','/img/menu_servicios_formacion_hover.png');    
                $("#m1n4").show();                    
            }, function () {
                $('#btformacion img').attr('src','/img/menu_servicios_formacion.png');
                t = setTimeout("fadeoutcapaexplorer('m1n4')",300);
            });
        }else{
            $('#btformacion').hover(function() {        
                $("#m1n4").show();                    
            }, function () {
                t = setTimeout("fadeoutcapaexplorer('m1n4')",300);
            });
        }
        
        if($('#btsomos').attr('class') != 'active'){
            $('#btsomos').hover(function() {        
                $('#btsomos img').attr('src','/img/menu_quienes_somos_hover.png');                
            }, function () {
                $('#btsomos img').attr('src','/img/menu_quienes_somos.png');
            });
        }
        
        if($('#btinicio').attr('class') != 'active'){
            $('#btinicio').hover(function() {        
                $('#btinicio img').attr('src','/img/menu_inicio_hover.png');                
            }, function () {
                $('#btinicio img').attr('src','/img/menu_inicio.png');
            });
        }
    }else{                
        if($('#btmetodologia').attr('class') != 'active'){
            $('#btmetodologia').hover(function() {        
                var fade = $('#sbtmetodologia');
        
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(350, 1);
                } else {
                    fade.fadeIn(350);
                }
            }, function () {
                var fade = $('#sbtmetodologia');
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(500, 0);
                } else {
                    fade.fadeOut(500);
                }
            });
        }
        
        $('#btsoluciones').hover(function() {        
            var fade = $('#sbtsoluciones');
            var fade2 = $("#m2n4");
            if($('#btsoluciones').attr('class') != 'active'){
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(350, 1);
                } else {
                    fade.fadeIn(350);
                }
            }
            if (fade2.is(':animated')) {
                fade2.stop().fadeTo(350, 1);
            } else {
                fade2.fadeIn(350);
            }
    
        }, function () {
            var fade = $('#sbtsoluciones');
            var fade2 = $("#m2n4");
            if($('#btsoluciones').attr('class') != 'active'){
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(500, 0);
                } else {
                    fade.fadeOut(500);        
                }
            }
            t = setTimeout("fadeoutcapa('m2n4')",300);                    
        });
        
        $('#btformacion').hover(function() {        
            var fade = $('#sbtformacion');
            var fade2 = $("#m1n4");
            if($('#btformacion').attr('class') != 'active'){
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(350, 1);
                } else {
                    fade.fadeIn(350);
                }
            }
            if (fade2.is(':animated')) {
                fade2.stop().fadeTo(350, 1);
            } else {
                fade2.fadeIn(350);
            }
    
        }, function () {
            var fade = $('#sbtformacion');
            var fade2 = $("#m1n4");
            if($('#btformacion').attr('class') != 'active'){
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(500, 0);
                } else {
                    fade.fadeOut(500);        
                }
            }
            t = setTimeout("fadeoutcapa('m1n4')",300);                    
        });
        
       
        
        if($('#btsomos').attr('class') != 'active'){
            $('#btsomos').hover(function() {        
                var fade = $('#sbtsomos');
        
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(350, 1);
                } else {
                    fade.fadeIn(350);
                }
            }, function () {
                var fade = $('#sbtsomos');
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(500, 0);
                } else {
                    fade.fadeOut(500);
                }
            });
        }
        if($('#btinicio').attr('class') != 'active'){
            $('#btinicio').hover(function() {        
                var fade = $('#sbtinicio');
        
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(350, 1);
                } else {
                    fade.fadeIn(350);
                }
            }, function () {
                var fade = $('#sbtinicio');
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(500, 0);
                } else {
                    fade.fadeOut(500);
                }
            });
        }
    }    
});

function fadeoutcapa(capa){    
    $('#'+capa).fadeOut(500);            
}

function fadeoutcapaexplorer(capa){    
    $('#'+capa).hide();            
}

function restaurarFade(){
    $('#cp_empleo').fadeTo(200,1);
    $('#cp_learning').fadeTo(200,1);
    $('#cp_certificado').fadeTo(200,1);
    $('#cp_especial').fadeTo(200,1);
    $('#cp_formacion').fadeTo(200,1);
}

function restaurarCajas(){
    $('#cp_formacion').css('background','url(../img/index_bloque.png) 0 0 no-repeat;');
    $('#cp_empleo').css('background','url(../img/index_bloque.png) 0 0 no-repeat;');
    $('#cp_learning').css('background','url(../img/index_bloque.png) 0 0 no-repeat;');
    $('#cp_certificado').css('background','url(../img/index_bloque.png) 0 0 no-repeat;');
    $('#cp_especial').css('background','url(../img/index_bloque_especial.png) 0 0 no-repeat;');  
}

$(function () {
    
    if ($.browser.msie){
        
        $('#cp_formacion').hover(function() {            
            $('#cp_formacion').css('background','url(../img/index_bloque.png) 0 0 no-repeat;');
            $('#cp_empleo').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_learning').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_certificado').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_especial').css('background','url(../img/index_bloque_especial_over.png) 0 0 no-repeat;');       
            clearInterval(tt);
        }, function () {
           tt = setTimeout("restaurarCajas()",300);
        });
        
        $('#cp_empleo').hover(function() {
            $('#cp_empleo').css('background','url(../img/index_bloque.png) 0 0 no-repeat;');
            $('#cp_formacion').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_learning').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_certificado').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_especial').css('background','url(../img/index_bloque_especial_over.png) 0 0 no-repeat;');     
            clearInterval(tt);
        }, function () {
           tt = setTimeout("restaurarCajas()",300);
        });
        
        $('#cp_learning').hover(function() {
            $('#cp_learning').css('background','url(../img/index_bloque.png) 0 0 no-repeat;');
            $('#cp_empleo').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_formacion').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_certificado').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_especial').css('background','url(../img/index_bloque_especial_over.png) 0 0 no-repeat;');     
            clearInterval(tt);
        }, function () {
           tt = setTimeout("restaurarCajas()",300);
        });
        
        $('#cp_certificado').hover(function() {
            $('#cp_certificado').css('background','url(../img/index_bloque.png) 0 0 no-repeat;');
            $('#cp_empleo').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_learning').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_formacion').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_especial').css('background','url(../img/index_bloque_especial_over.png) 0 0 no-repeat;');     
            clearInterval(tt);
        }, function () {
           tt = setTimeout("restaurarCajas()",300);
        });
        
        $('#cp_especial').hover(function() {
            $('#cp_especial').css('background','url(../img/index_bloque_especial.png) 0 0 no-repeat;');
            $('#cp_empleo').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_learning').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_certificado').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');
            $('#cp_formacion').css('background','url(../img/index_bloque_over.png) 0 0 no-repeat;');     
            clearInterval(tt);
        }, function () {
           tt = setTimeout("restaurarCajas()",300);
        });
            
    }else{    
        $('#cp_formacion').hover(function() {
            $('#cp_formacion').fadeTo(200,1);
            $('#cp_empleo').fadeTo(200,0.75);
            $('#cp_learning').fadeTo(200,0.75);
            $('#cp_certificado').fadeTo(200,0.75);
            $('#cp_especial').fadeTo(200,0.75);
                    
            clearInterval(tt);
        }, function () {
           tt = setTimeout("restaurarFade()",300);
        });
        
        $('#cp_empleo').hover(function() {
            $('#cp_empleo').fadeTo(200,1);
            $('#cp_formacion').fadeTo(200,0.75);
            $('#cp_learning').fadeTo(200,0.75);
            $('#cp_certificado').fadeTo(200,0.75);
            $('#cp_especial').fadeTo(200,0.75);        
            clearInterval(tt);
        }, function () {
            tt = setTimeout("restaurarFade()",300);
        });
        
        $('#cp_learning').hover(function() {
            $('#cp_learning').fadeTo(200,1);
            $('#cp_empleo').fadeTo(200,0.75);
            $('#cp_formacion').fadeTo(200,0.75);
            $('#cp_certificado').fadeTo(200,0.75);
            $('#cp_especial').fadeTo(200,0.75);        
            clearInterval(tt);
        }, function () {
            tt = setTimeout("restaurarFade()",300);
        });
        
        $('#cp_certificado').hover(function() {
            $('#cp_certificado').fadeTo(200,1);
            $('#cp_empleo').fadeTo(200,0.75);
            $('#cp_learning').fadeTo(200,0.75);
            $('#cp_formacion').fadeTo(200,0.75);
            $('#cp_especial').fadeTo(200,0.75);        
            clearInterval(tt);
        }, function () {
            tt = setTimeout("restaurarFade()",300);
        });
        
        $('#cp_especial').hover(function() {
            $('#cp_especial').fadeTo(200,1);
            $('#cp_empleo').fadeTo(200,0.75);
            $('#cp_learning').fadeTo(200,0.75);
            $('#cp_certificado').fadeTo(200,0.75);
            $('#cp_formacion').fadeTo(200,0.75);        
            clearInterval(tt);
        }, function () {
            tt = setTimeout("restaurarFade()",300);
        });
        
    }
});

function calcularEmp(valor){
  
  if (!/^([0-9])*$/.test(valor))  
  {    
    $("#credito").html('0');
  }else{          
    if (valor < 6){
        $("#credito").html('420');        
    }else{
        $("#credito").html(65*valor);        
    }
  }  
}

function cambiaPestania(seleccionada,valor,secc){
    
    if (pact == '') {pact = 0}
    if (pact != valor){
        $('#cont-pest-'+pact).fadeOut(200);
        $('#cont-pest-'+valor).fadeIn(300);    
        pact = valor;
        if ($.browser.msie){
            for (i=0;i < secc;i++){
                if (i == valor){
                    imgact = $('#pt'+i).attr('src');
                    imgact = imgact.substring(0,imgact.length - 4) + '_active.png';                                
                    $('#pt'+i).attr('src',''+imgact);                                               
                }else{                           
                    imgact = $('#pt'+i).attr('src');
                    if (imgact != undefined){
                    if (imgact.indexOf("_active") > 0){
                        imgact = imgact.substring(0,imgact.length - 11) + '.png';    
                        $('#pt'+i).attr('src',''+imgact);                        
                    }               
                    }
                }
            }
        }else{
            for (i=0;i < secc;i++){
                if (i == valor){
                    imgact = $('#pt'+valor).attr('src');
                    imgact = imgact.substring(0,imgact.length - 4) + '_active.png';                    
                    $('#pt'+valor).attr('src',''+imgact);
                    //$('#pt'+valor).mouseover(function (){$(this).fadeTo(1,1);});                           
                    $('#pt'+valor).attr('onmouseover','');
                }else{                
                    imgact = $('#pt'+i).attr('src');
                    if (imgact.indexOf("_active") > 0){
                        imgact = imgact.substring(0,imgact.length - 11) + '.png';    
                        $('#pt'+i).attr('src',''+imgact);
                        $('#pt'+i).mouseover(function (){$(this).fadeTo(1,0.4);});
                    }               
                }
            }
        }
    }
}

function abrirpop(wpop,ancho,alto)
{
	var ancho=ancho;
	var alto=alto;
	var mileft=(screen.width-ancho)/2;
	var mitop=(screen.height-alto)/2;
	
	myRef = window.open(wpop,'Aviso_Legal','left='+mileft+',top='+mitop+',width='+ancho+',height='+alto+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0');
}

function getProvincias()
{
    var idpais=$('#pais').val();
       
    var el=$('#td-provincia');
    el.css('display','block');    
    $.post('/inc/ajax_cup.php?funcion=printaProvincias&pais='+idpais, function(data) {       
      el.html(data);
    });    
}
function validarC(){   
    
    var errores=""; 
    
    //expresion regular para telefonos
    var er_tlfono = /^[0-9]{2,3}-? ?[0-9]{6,7}$/
    
    //expresion regular para emails
    var er_email = /^(.+\@.+\..+)$/
    
    if(document.getElementById("id")!=null && (document.getElementById("id").value == "" || document.getElementById("id").value == "-1")){
        errores+="- Debes seleccionar un curso. \n"
    }
    if(document.getElementById("nombre")!=null && (document.getElementById("nombre").value == "" || document.getElementById("nombre").value == "Razon social")){
        errores+="- Debes completar el campo Razón Social. \n"
    }
  if(document.getElementById("apellidos")!=null && (document.getElementById("apellidos").value == "" || document.getElementById("apellidos").value == "Persona de contacto")){
        errores+="- Debes completar el campo Persona de contacto. \n"
    }
    if(document.getElementById("telefono")!=null && (document.getElementById("telefono").value == "" || document.getElementById("telefono").value == "Teléfono")){
        errores+="- Debes completar el campo Teléfono. \n"
    }else if(!er_tlfono.test(document.getElementById("telefono").value)) {
        errores+="- El número de teléfono esta formado por 9 números. \n"
    }
    if(document.getElementById("email")!=null && (document.getElementById("email").value == "" || document.getElementById("email").value == "E-mail")){
        errores+="- Debes completar el campo E-mail. \n"
    }else if(!er_email.test(document.getElementById("email").value)) {
        errores+="- El email no tiene el formato requerido. \n"
    }
    
     if(document.getElementById("cupon_comboProvinciaId")!=null && (document.getElementById("cupon_comboProvinciaId").value == "" || document.getElementById("cupon_comboProvinciaId").value == "-1")){
        errores+="- Debes seleccionar una Provincia. \n"
    }
    
    // Modificamos el valor por defecto del campo "telefono2" ya que la marca de agua fastidia la validacion interna.
    if (document.getElementById("movil").value == "Teléfono de la Empresa"){
        document.getElementById("movil").value ="";
    }
        
    if(errores.length>0){
        alert("Errores: \n\n"+errores);
        return false;
    } else {
        return true;
    }
    //document.getElementById("frmCupon").submit()
}

function getProvincias_fch()
{
    var idpais=$('#pais').val();
       
    var el=$('#td-provincia');
    el.css('display','block');    
    $.post('/inc/ajax_cup.php?funcion=printaProvincias_fch&pais='+idpais, function(data) {       
      el.html(data);
    });    
}
