/*
 * Testowanie formularzy
 * @version 1.20
 * 
 */


var formService = {
    delOK : true,
    changeOK : true,
	
    onDel : function(komunikat) {
        this.delOK = confirm(komunikat);
    },

    onChange : function(komunikat) {
        this.changeOK = alert(komunikat);
    },

    trim : function(s) {
        var str = s.value;
        //        str = this.xmlCode(str);
        var n;
        for (n = 0; str.charAt(n)==" " && n < str.length; n++){};
        str = str.substring(n);
        //	var start = n;
		
        for (n = str.length -1; str.charAt(n)==" " && n > 0; n--){};
        var end = n + 1;
        s.value = str.substring(0, end);
		
        return true;
    },
	
    isEmpty : function(s, komunikat) {
        var empty = ((s == null) || (s.length == 0));
        if (empty && komunikat) alert(komunikat);
        return empty;
    },

    checkElement : function(element) {
        return this.trim(element);
    },

    checkAll : function(f) {
        if (!this.delOK) return false;
        return this.check(f)
    },

    check : function(f) {
        alert('Koniecznie ustaw funkcję formService.check = function(formularz)');
        return false;
    },

    check_email : function(e) {
        var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
        for (var i = 0; i < e.length ; i++)
            if (ok.indexOf(e.charAt(i)) < 0) return false;

        var re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        var re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        return (!e.match(re) && e.match(re_two));
    }
}