function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
//
function checkPhoneNumber(id){
var phoneValue = $("#"+id).val(); //get current field value
var phoneLength = $("#"+id).val().length; //get current field value length
if(phoneLength == 1){ //if current length is 3, then insert a hyphen
phoneValue += "-";
}else if(phoneLength == 6){ //if current length is 7, then insert a hyphen
phoneValue += "-";
}
//check is_digit for new character; if not, then use substr to get rid of it
var tempValue = phoneValue.replace(/-/g, ""); //assign tempValue with phoneValue, which performs global string replacement (replace "-" with nothing)
if(is_digit(tempValue) == false){ //check if all input characters are digits
phoneValue = (phoneValue.substr(0, phoneLength-1)); //if not, then use substr to get rid of the last entered character
}
//limit the phone value to 12 character
if(phoneLength > 11){
phoneValue = (phoneValue.substr(0, 11)); //if field value length is greater than 12, then use substr to get rid of last character
}
$("#"+id).val(phoneValue);
}
function is_digit(input){
if (isNaN(input)) {
return false;
}else{
return true;
}
}
$(function(){
setTimeout(function(){
$("#cuerpo").change();
$("#rut_login").focus();
},500);
$('#cuerpo , #compania').chosen();
$("#cuerpo").change(function(e){
e.preventDefault();
$.post("./",{
"_ajax_" : "getCompanias",
"padre_id" : $(this).val()
},function(e){
var html = '';
$.each(e,function(id,nombre){
html+='';
})
$("#compania").html(html);
$('#compania').trigger("chosen:updated");
},"json")
return false;
});
$("#msform_actua").submit(function(e){
telefono = $("#celular").val().split("-").join("");
if(telefono.length != 9)
{
alert("El número celular debe tener 9 digitos.");
return false;
}
$.post("./",$("#msform_actua").serializeArray(),function(e){
if(e.msg == "ok")
{
location.href = "./";
}
},"json")
return false;
});
$("#celular").keypress(function(e){ //the "phoneNumber" can be any other input field ID
if(e.keyCode == 8){ //trap the backspace key so that when deleting value, "checkPhoneNumber" will not be called.
//do nothing
}else{
if(e.keyCode >=47 && e.keyCode <=57)
{
checkPhoneNumber("celular"); //call checkPhoneNumber function and put "phoneNumber" field ID as parameter
}
else
{
return false;
}
//checkPhoneNumber("telefono"); //call checkPhoneNumber function and put "phoneNumber" field ID as parameter
}
});
$("#telefono").keypress(function(e){ //the "phoneNumber" can be any other input field ID
if(e.keyCode == 8){ //trap the backspace key so that when deleting value, "checkPhoneNumber" will not be called.
//do nothing
}else{
if(e.keyCode >=47 && e.keyCode <=57)
{
checkPhoneNumber("telefono"); //call checkPhoneNumber function and put "phoneNumber" field ID as parameter
}
else
{
return false;
}
//checkPhoneNumber("telefono"); //call checkPhoneNumber function and put "phoneNumber" field ID as parameter
}
});
$("body").on("blur",".email",function(){
if(!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($(this).val()))
{
if($(this).val()!=""){
$(this).val("");
alert("Email inválido");
}
}
});
$("#login-form").submit(function(e){
e.preventDefault();
$.post("./",$(this).serializeArray(),function(e){
if(e.msg == "ok")
{
location.href = "./";
}else if(e.msg == "form")
{
$("#celular").val(e.celular);
$("#email").val(e.email);
$(".modal_update").modal()
}
else
{
alert(e.msg);
}
},"json");
return false;
})
if(getParameterByName("err") == 1)
{
alert("El usuario se encuentra desactivado.");
}
$(".rut").Rut({
on_error: function(){
alert("Rut no valido");
}
});
})
$('.cerrarmodal').click(function() {
$('#modal_pass').modal('hide');
$('#modal_olvide_pass').modal('hide');
});
$('.recuperar_clave').click(function(e) {
e.preventDefault();
if($("#recupera_rut").val() ==""){
alert("Debe indicar el Rut");
return false;
}
if($("#recupera_email").val() ==""){
alert("Debe indicar el email de recuperación");
return false;
}
var data={
_ajax_:"RecuperarClave",
rut:$("#recupera_rut").val(),
email:$("#recupera_email").val(),
}
$.post("./",data,function(msg){
if(msg.error==1){
alert(msg.msg);
return false;
}
alert(msg.msg);
$('#modal_pass').modal('hide');
$('#modal_olvide_pass').modal('hide');
return false;
},"json");
});
$("#registrar_form").submit(function(e){
e.preventDefault();
// $("#cuerpo").val(2);
if($("#compania").val() =="")
{
alert("Debe indicar la compañia");
return false;
}
$("#registro_botono").hide().prop("disabled",true);
$.post("./",$(this).serializeArray(),function(e){
if(e.error == 1)
{
alert("El rut ya se encuentra registrado, revise con su supervisor a cargo.");
$("#registro_botono").show().prop("disabled",false);
}
else
{
alert("Sus datos han sido enviados al supervisor de campaña para aprobar su registro, se le informara una vez se haya aceptado el registro.");
$('#regustrarse_modal').modal('hide');
location.href="./";
}
},"json");
return false;
});