// SEVEN Basic Javascript


//rollover image -------------------------------- begin


$(document).ready(function (){
	$("img.rolloverimagen").mouseover(function (){
		var newImage = $(this).attr('src').replace(/^(.*?)(\.(?:gif|jpg|png))$/, "$1_over$2");
		$(this).attr('src', newImage);
	});
	$("img.rolloverimagen").mouseout(function (){
		var newImage = $(this).attr('src').replace('_over', '');
		$(this).attr('src', newImage);
	});
	
	$(".politica").colorbox({inline:true, width:"50%"});
	
	$("#sendcontactform").click (sendForm);
	
	var seccion=1;
	
	$('#b_info a').click(function() {
		if(seccion==1){
			$('#module1').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module1').css('display','none');
				$('#module1').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '318px'
			}, 500, function() {
			});
			$('#module2').css('display','block');
			$('#module2').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=2;
		}
		else if(seccion==2){
			$('#module2').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module2').css('display','none');
				$('#module2').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '647px'
			}, 500, function() {
			});
			$('#module3').css('display','block');
			$('#module3').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=3;
		}
		else if(seccion==3){
			$('#module3').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module3').css('display','none');
				$('#module3').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '0px'
			}, 500, function() {
			});
			$('#module1').css('display','block');
			$('#module1').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=1;
		}
	});
	$('#link1').click(function() {
		if(seccion==1){
			
		}else if(seccion==2){
			$('#module2').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module2').css('display','none');
				$('#module2').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '0px'
			}, 500, function() {
			});
			$('#module1').css('display','block');
			$('#module1').css('margin-left','4000px');
			$('#module1').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=1;
		}else if(seccion==3){
			$('#module3').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module3').css('display','none');
				$('#module3').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '0px'
			}, 500, function() {
			});
			$('#module1').css('display','block');
			$('#module1').css('margin-left','4000px');
			$('#module1').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=1;
		}
	});
	$('#link2').click(function() {
		if(seccion==2){
			
		}else if(seccion==1){
			$('#module1').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module1').css('display','none');
				$('#module1').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '318px'
			}, 500, function() {
			});
			$('#module2').css('display','block');
			$('#module2').css('margin-left','4000px');
			$('#module2').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=2;
		}else if(seccion==3){
			$('#module3').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module3').css('display','none');
				$('#module3').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '318px'
			}, 500, function() {
			});
			$('#module2').css('display','block');
			$('#module2').css('margin-left','4000px');
			$('#module2').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=2;
		}
	});
	$('#link3').click(function() {
		if(seccion==3){
			
		}else if(seccion==1){
			$('#module1').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module1').css('display','none');
				$('#module1').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '647px'
			}, 500, function() {
			});
			$('#module3').css('display','block');
			$('#module3').css('margin-left','4000px');
			$('#module3').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=3;
		}else if(seccion==2){
			$('#module2').animate({
				'margin-left' : '-4000px'
			}, 1000, function() {
				$('#module2').css('display','none');
				$('#module2').css('margin-left','4000px');
			});
			$('#menu_roll .menu_pos').animate({
				'margin-left' : '647px'
			}, 500, function() {
			});
			$('#module3').css('display','block');
			$('#module3').css('margin-left','4000px');
			$('#module3').animate({
				'margin-left' : '-500px'
			}, 1000, function() {});
			seccion=3;
		}
	});
	
	
});

function sendForm() {
    var frm = document.contactform;
    var _nombre = frm.nombre.value;
    var _apellidos = frm.apellidos.value;
    var _telefono = frm.telefono.value ;
    var _mail = frm.email.value; 
    var _empresa = frm.empresa.value; 
    var _moreinfo = frm.moreinfo.checked? '1': '';
    
    if (_nombre=='' || _nombre=='Nombre:'){
    	alert ("Debe rellenar el campo Nombre");
    	frm.nombre.value='';
    	frm.nombre.focus();
        return false;
    }
    
    if (_apellidos=='' || _apellidos=='Apellidos:'){
    	alert ("Debe rellenar el campo Apellidos");
    	frm.apellidos.value='';
    	frm.apellidos.focus();
        return false;
    }
    
    if (_empresa=='' || _empresa=='Empresa:'){
    	alert ("Debe rellenar el campo Empresa");
    	frm.empresa.value='';
    	frm.empresa.focus();
        return false;
    }
    
    if (_mail=='' || _mail=='e-mail:'){
    	alert ("Debe rellenar el campo E-mail");
    	frm.email.value='';
    	frm.email.focus();
        return false;
    }
    
    if (!wbValidateFormL (frm, "es") ) return false;
    
    if (_telefono=='' || _telefono=='Teléfono:'){
    	alert ("Debe rellenar el campo Teléfono");
    	frm.telefono.value='';
    	frm.telefono.focus();
        return false;
    }
    
    if (!frm.acuerdo.checked) {
        alert ("Debe aceptar la política de privacidad");
        return false;
    }

    

    //Get params
	
    var _ContactRequestType = '';
    for (var i = 0; i < frm.ContactRequestType.length; i++) {
        if (frm.ContactRequestType[i].checked) {
            _ContactRequestType = frm.ContactRequestType[i].value;
            break;
        }
    }

    //Call ajax to insert data
     $.ajax({
        url: "contact_ajax.php",
        type: "POST",
        dataType: "text",
        data: {nombre: _nombre, apellidos: _apellidos, telefono: _telefono, email: _mail, empresa: _empresa, moreinfo: _moreinfo, ContactRequestType: _ContactRequestType},
        error: function(req, err, obj) {
            //alert(err);
            /*$("#contactform").hide();
            $("#contacterr").show();
            $("#contacterrorcode").html (err + ' ' + req.status);*/
            //document.getElementById('boton_enviar').setAttribute("class","left");
            //document.getElementById('boton_enviar').setAttribute("src","img/img_button_ko.gif");
            $("#boton_enviar").hide();
            $("#boton_enviar_ko").show();
        },
        success: function(txt) {
            if (txt == "OK") {
                //$("#contactform").hide();
               // $("#contactok").show();
               //document.getElementById('boton_enviar').setAttribute("class","left");
               //document.getElementById('boton_enviar').setAttribute("src","img/img_button_ok.gif");
               
               $("#boton_enviar").hide();
               $("#boton_enviar_ok").show();
            } else {
               // $("#contactform").hide();
                //$("#contacterr").show();
               // $("#contacterrorcode").html (txt);
               //document.getElementById('boton_enviar').setAttribute("class","left");
               //document.getElementById('boton_enviar').setAttribute("src","img/img_button_ko.gif");
               $("#boton_enviar").hide();
               $("#'boton_enviar_ko").show();
            }
        }

    }); 

    return false;
}

function delValue(nombre,campo){
	
	if (nombre == document.getElementById(campo).value)
		document.getElementById(campo).value='';
	return false;
}

function recValue(nombre,campo){
	if (document.getElementById(campo).value=='')
		document.getElementById(campo).value=nombre;
	return false;
}
//rollover image --------------------------------- end


