﻿
$.datepicker.setDefaults($.datepicker.regional["es"]);

$(document).ready(function() {

    $("input[rel=date]").datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: "1920:2000",
        defaultDate: "-30y"
    }).keydown(function(event) {
        event.preventDefault();
    });

    $(".toggle").each(function() {
        $(this).val($(this).attr("val"));
        $(this).focus(function() {
            if ($(this).val() == $(this).attr("val")) {
                $(this).val("");
            }
        });
        $(this).blur(function() {
            if ($(this).val() == "") {
                $(this).val($(this).attr("val"));
            }
        });
    });

    //ie z-index issue
    function zIndexHack() {
        var zIndexNumber = 1000;
        //$(".cat_links *, .header .holder .float_menu").each(function() {
        $("*").each(function() {
            if (zIndexNumber > 0) {
                $(this).css("zIndex", zIndexNumber);
                zIndexNumber -= 10;
            }
        });
        zIndexNumber = 10000;
        $(".cat_links *").each(function() {
            if (zIndexNumber > 0) {
                $(this).css("zIndex", zIndexNumber);
                zIndexNumber -= 10;
            }
        });
    }
    zIndexHack();
    //ie z-index issue end

});

function showAlert(text) {
    $alert = $(document.createElement("div"));
    $alert.html(text);
    $("body").append($alert);
    $alert.dialog({
        height: 80,
        modal: true,
        draggable: false,
        title: "Atención",
        buttons: {
            "Cerrar": function() {
                $(this).dialog("close");
            }
        }
    });
}

function isInt(x) {
    var y = parseInt(x);
    if (isNaN(y)) return false;
    return x == y && x.toString() == y.toString();
}

function toSearch(str) {
    
    str = str.replace(/^\s+|\s+$/gi,"").toLowerCase();
    str = str.replace(/ /gi, "+")
    str = str.replace(/á/gi, "a")
    str = str.replace(/é/gi, "e")
    str = str.replace(/í/gi, "i")
    str = str.replace(/ó/gi, "o")
    str = str.replace(/ú/gi, "u")
    str = str.replace(/à/gi, "a")
    str = str.replace(/è/gi, "e")
    str = str.replace(/ì/gi, "i")
    str = str.replace(/ò/gi, "o")
    str = str.replace(/ù/gi, "u")
    str = str.replace(/ä/gi, "a")
    str = str.replace(/ë/gi, "e")
    str = str.replace(/ï/gi, "i")
    str = str.replace(/ö/gi, "o")
    str = str.replace(/ü/gi, "u")
    str = str.replace(/ç/gi, "c")
    str = str.replace(/ñ/gi, "n")
    
    sNew = "";
    sPattern = "abcdefghijklmnopqrstuvwxyz+-0123456789";
    for (i = 0; i < str.length; i++) {
        sChar = str.charAt(i);
        if (sPattern.indexOf(sChar) >= 0) {
            sNew += sChar;
        }
    } 
    
    return sNew;  
   
}

function isMail(_email) {   
    var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
    return emailReg.test(_email);
}
