function getURL()
{
	var myRandom	= parseInt(Math.random()*99999999);
	return "comun/ajax.php?rand=" + myRandom;
}

function saveRecord(preregistro,iframe)
{
	var resultado = false;
	$.ajax({
        timeout: 23000,	
        async:true,
        contentType: "application/x-www-form-urlencoded",
        type: "POST",
        url: getURL(),
        data: $("#registro").serialize(),
		beforeSend: function(objeto)
		{
			$.blockUI({ css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#fff' 
			}
			,message: '<h1>Por favor espere...<br><br>Please wait...</h1>'
			}); 
		    setTimeout($.unblockUI, 26000); 		
		},
        success: function(datos)
        {
			$.unblockUI();
			$("#generatefolio").val(datos);
			$("#registro").submit();
    		resultado = true;
			if (preregistro==1){
				window.location='index.php?confirmacion=1&id='+datos;
			
			}else{
				if (iframe==1) {
				window.location='index.php?loginempresa='+datos;
				}else{
					window.location='index.php?ref='+datos;
				}
				}
        },
        error: function(objeto, quepaso, otroobj){
			alert(quepaso);
            alert("Error al intentar registrar\nError de comunicaci&oacute;n");
    		$("#registro").validationEngine({success : function() { saveRecord(); return false;}});
        }
	});
	return resultado;
}

