$(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);
	});

	$("#sendcontactform").click (sendForm);
});

function sendForm() {
    var frm = document.contactform;
    if (!frm.acuerdo.checked) {
        alert (_dic_mustaccept);
        return false;
    }
    if (!wbValidateFormL (frm, _lang) ) return false;

    //Get params
	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 _webempresa = frm.web.value; 
    var _cargo = frm.cargo.value; 
    var _motivo = frm.motivo.options[frm.motivo.selectedIndex].value;
    var _pagina = frm.pagina.options[frm.pagina.selectedIndex].value;

    //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, web: _webempresa, cargo: _cargo, motivo: _motivo, pagina: _pagina},
        error: function(req, err, obj) {
            //alert(err);
            $("#contactform").hide();
            $("#contacterr").show();
            $("#contacterrorcode").html (err + ' ' + req.status);
        },
        success: function(txt) {
            if (txt == "OK") {
                $("#contactform").hide();
                $("#contactok").show();
            } else {
                $("#contactform").hide();
                $("#contacterr").show();
                $("#contacterrorcode").html (txt);
            }
        }

    }); 

    return false;
}

