﻿//    function checkLength() {
//        var test = $(

//        if (document.getElementById('<%= txtSearchKeyword.ClientID %>').value.length < 3) {
//            return false;
//        }
//        document.forms[0].action = '/risultati-ricerca';
//        return true;
//    }
//    
//    function myDoPostBack() {
//        if (checkLength()) { 
//            document.forms[0].submit();
//            return false 
//        }
//    }




$(function () {

        $('#ricercaProd input.search').click(function (e) {
            var testo = $('#ricercaProd input.text').val();

            if (testo.length < 3) {
                e.preventDefault();
            }

        });


        $('#loginSubmit').click(function (e) {
            var usr, pwd, errMess;
            usr = $('#usr').val().replace(' ', '');
            pwd = $('#pwd').val().replace(' ', '');
            errMess = '';

            if (!usr || usr == 'login') {
                errMess += '- Inserire il nome utente \n';
            }
            else if (!usr.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)) {
                errMess += '- Inserire l\'indirizzo email di registrazione \n';
            }

            if (!pwd || pwd == 'password') {
                errMess += "- Inserire la password \n";
            }

            if (errMess) {
                alert(errMess);
                e.preventDefault();
            }
            else {
                //__doPostBack('loginSubmit');
            }

        });


        $('#ricercaProd input.text')
            .keydown(function (e) {
                if (e.keyCode == 13)
                {
                    e.preventDefault();
                }
            })
            .keyup(function (e) {
                if (e.keyCode == 13) {
                    $('#ricercaProd input.search').trigger('click');
                }
            });


        // FOCUS IN E OUT SUI CAMPI DI LOGIN
        $('#usr, #pwd')
            .focus(function () {
                if ($(this).val() == $(this).attr('title')) {
                    $(this).val('');
                }
            })
            .focusout(function () {
                if ($(this).val() == '') {
                    $(this).val($(this).attr('title'));
                }
            })
            .keydown(function (e) {
                if (e.keyCode == 13) {
                    e.preventDefault();
                }
            })
            .keyup(function (e) {
                if (e.keyCode == 13) {
                    $(this).blur();
                    $('#loginSubmit').trigger('click');
                }
            });


    });
