﻿
//calendar

//var daylength = 24 * 60 * 60 * 1000

//function Navigate(view, addSelectedDate) {
//    var url = window.location.href.split('?')[0]
//    if (/[\?&]lng=(\w\w\w?)/.test(window.location)) url += '?lng=' + RegExp.$1 + '&'; else url += '?'
//    if (addSelectedDate) window.location = url.concat('d=', selectedDate.getUTCDate(), '&m=', selectedDate.getUTCMonth() + 1, '&y=', selectedDate.getUTCFullYear(), '&v=', view)
//    else window.location = url.concat('v=', view)
//}

//function Navigator(view, dchange) 
//{
//    selectedDate.setTime(referenceDate.getTime() + dchange * daylength);
//    Navigate(view, true);
//}

function SetLocation(newlocation) {
    window.location = newlocation;
}

//page part loader:
    function LoadPP(ppID, ppURL, showLoading) 
    {
        if (showLoading)
            $(ppID).innerHTML = "<img src='/images/loading.gif' alt='' />";
        //alert(ppURL);
        new Ajax.Updater(ppID, ppURL, { method: 'post', evalScripts: true });
    }



// query string processing
    function PageQuery(q) {
        if (q.length > 1) this.q = q.substring(1, q.length);
        else this.q = null;
        this.keyValuePairs = new Array();
        if (q) {
            for (var i = 0; i < this.q.split("&").length; i++) {
                this.keyValuePairs[i] = this.q.split("&")[i];
            }
        }
        this.getKeyValuePairs = function() { return this.keyValuePairs; };
        this.getValue = function(s) {
            for (var j = 0; j < this.keyValuePairs.length; j++) {
                if (this.keyValuePairs[j].split("=")[0] == s)
                    return this.keyValuePairs[j].split("=")[1];
            }
            return false;
        };
        this.getParameters = function() {
            var a = new Array(this.getLength());
            for (var j = 0; j < this.keyValuePairs.length; j++) {
                a[j] = this.keyValuePairs[j].split("=")[0];
            }
            return a;
        };
        this.getLength = function() { return this.keyValuePairs.length; };
    }
    function queryString(key) {
        var page = new PageQuery(window.location.search);
        return unescape(page.getValue(key));
    }

    function OnAddProviderToFavorites (pid) {
        LoadPP("divAddProviderToFavorites", "/MyPP/PPMyFavoritesAdd.aspx?pid=" + pid, true);
    }
    function OnAddServiceToFavorites(serviceid) {
        LoadPP("divAddServiceToFavorites", "/MyPP/PPMyFavoritesAdd.aspx?serviceid=" + serviceid, true);
    }

    function OnMyMenuOver(obj) {
        $(obj).addClassName("mymenu_active");
    }
    function OnMyMenuOut(obj) {
        $(obj).removeClassName("mymenu_active");
    }
    function OnTopNavOver(obj) {
        $(obj).addClassName("topnav_active");
    }
    function OnTopNavOut(obj) {
        $(obj).removeClassName("topnav_active");
    }
    function OnCommandOver(obj) {
        $(obj).className = "commandOver";
    }
    function OnCommandOut(obj) {
        $(obj).className = "commandOut";
    }

    function OnButtonOver(obj) {
        $(obj).className = "buttonOver";
    }
    function OnButtonOut(obj) {
        $(obj).className = "buttonOut";
    }

    function OnRowOver(obj) {
        $(obj).className = "rowOver";
    }
    function OnRowOut(obj) {
        $(obj).className = "rowOut";
    }

function validateEmail(strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
    var objRegExp  = /^([a-z0-9]([a-z0-9_\.\-]*)@([a-z0-9_\.\-]*)([.][a-z0-9]{2,3})$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}

function validateNumeric( strValue ) {
/*****************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
******************************************************************/
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}

function validateInteger( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid integer number.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
**************************************************/
  var objRegExp  = /(^-?\d\d*$)/;

  //check for integer characters
  return objRegExp.test(strValue);
}

function validateNotEmpty( strValue ) {
/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }
   return false;
}

function validateDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 4 digit year, 2 digit month,
    2 digit day. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. yyyy/mm/dd or yyyy-mm-dd or yyyy.mm.dd

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{4}(\-|\/|\.)\d{2}\1\d{2}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(4,5) 
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[2],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true; //found in lookup table, good date
    }
    
    //check for February
    var intMonth = parseInt(arrayDate[1],10);
    if (intMonth == 2) { 
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         var intYear = parseInt(arrayDate[0]);
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}


function validateTime( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid time, HH:MM or HH:MM:SS or HH:MM:SS.mmm.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
**************************************************/
  var objRegExp  = /^([0-2][1-9]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/;

  //check for time characters
  return objRegExp.test(strValue);
}

function rightTrim( strValue ) {
/************************************************
DESCRIPTION: Trims trailing whitespace chars.

PARAMETERS:
   strValue - String to be trimmed.

RETURNS:
   Source string with right whitespaces removed.
*************************************************/
var objRegExp = /^([\w\W]*)(\b\s*)$/;

      if(objRegExp.test(strValue)) {
       //remove trailing a whitespace characters
       strValue = strValue.replace(objRegExp, '$1');
    }
  return strValue;
}

function leftTrim( strValue ) {
/************************************************
DESCRIPTION: Trims leading whitespace chars.

PARAMETERS:
   strValue - String to be trimmed

RETURNS:
   Source string with left whitespaces removed.
*************************************************/
var objRegExp = /^(\s*)(\b[\w\W]*)$/;

      if(objRegExp.test(strValue)) {
       //remove leading a whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}



// Cross Fade Images
CrossFadeImages = function() {
    this.fadenow = false;
    this.newactive = 1;
    this.active = 1;
    this.container = $(CrossFadeImages.arguments[0]);
    this.containerlegend = $(CrossFadeImages.arguments[0] + "legend");
    this.containername = CrossFadeImages.arguments[0];
    this.images = CrossFadeImages.arguments.length - 1;
    for (i = 1; i != CrossFadeImages.arguments.length; i++) {
        el = document.createElement('IMG');
        el.id = this.containername + '_' + i;
        el.src = CrossFadeImages.arguments[i];
        if (i == 1) this.setOpacity(el, 100); else this.setOpacity(el, 0);
        el.style.position = 'absolute';
        this.container.appendChild(el);
        // legend:
//        lel = document.createElement('span');
//        lel.id = this.containername + "legend_span" + i;
//        this.containerlegend.appendChild(lel);
//        if (i == 1)
//            $(this.containername + "legend_span" + i).innerHTML = "<img src=\"/images/fadelegend_" + i + "a.gif\" id=\"" + this.containername + "legend_" + i + "\" onclick=\"OnLegendClicked(" + i + ",'" + this.containername + "')\" />";
//        else
//            $(this.containername + "legend_span" + i).innerHTML = "<img src=\"/images/fadelegend_" + i + ".gif\" id=\"" + this.containername + "legend_" + i + "\" onclick=\"OnLegendClicked(" + i + ",'" + this.containername + "')\" />";
    }
//    lel = document.createElement('span');
//    lel.id = this.containername + "legend_spspan";
//    lel.setAttribute("status", "S");
//    this.containerlegend.appendChild(lel);
//    $(this.containername + "legend_spspan").innerHTML = "<img src=\"/images/fadelegend_p.gif\" id=\"" + this.containername + "legend_sp\" onclick=\"OnCrossFadeLegendControlClicked('" + this.containername + "');\" />";

    this.fpe = new PeriodicalExecuter(this.startFade.bind(this), 5);
    return this;
}

CrossFadeImages.prototype.setOpacity = function(el, o) {
    el.style.opacity = (o / 101);
    el.style.MozOpacity = (o / 100);
    el.style.KhtmlOpacity = (o / 100);
    el.style.filter = "alpha(opacity=" + o + ")";
}

CrossFadeImages.prototype.startFade = function() {
    if (this.fadenow == true) {
        i = this.newactive;
        this.fadenow = false;
    }
    else {
        i = (this.active + 1 > this.images) ? 1 : this.active + 1;
    }
    //$(this.containername + 'legend_' + this.active).src = "/images/fadelegend_" + this.active + ".gif";
    //$(this.containername + 'legend_' + i).src = "/images/fadelegend_" + i + "a.gif";
    this.current = $(this.containername + '_' + this.active);
    this.next = $(this.containername + '_' + i);
    this.currentopacity = 100;
    this.nextopacity = 0;
    this.pe = new PeriodicalExecuter(this.fade.bind(this), 0.01);
    this.active = i;
}

CrossFadeImages.prototype.fade = function() {
    this.currentopacity -= 2;
    this.nextopacity += 2;
    this.setOpacity(this.current, this.currentopacity);
    this.setOpacity(this.next, this.nextopacity);
    if (this.currentopacity == 0)
        this.pe.stop();
}

OnCrossFadeLegendControlClicked = function(containerID) {
    if ($(containerID + "legend_spspan").getAttribute("status") == "S") {
        $(containerID + "legend_spspan").setAttribute("status", "P");
        $(containerID + "legend_sp").src = "/images/fadelegend_s.gif";
        crossFader.fpe.stop();
    }
    else {
        $(containerID + "legend_spspan").setAttribute("status", "S");
        $(containerID + "legend_sp").src = "/images/fadelegend_p.gif";
        crossFader.fpe = new PeriodicalExecuter(crossFader.startFade.bind(crossFader), 5);
    }
}

function OnLegendClicked(i, containerID) {
    $(containerID + "legend_spspan").setAttribute("status", "P");
    $(containerID + "legend_sp").src = "/images/fadelegend_s.gif";
    crossFader.fpe.stop();
    crossFader.newactive = i;
    crossFader.fadenow = true;
    crossFader.startFade();
}

// ***********************************
// MODAL BOX
// ***********************************
function DisplayModalBox(sizeX, sizeY) {
    messageObj = new DHTMLSuite.modalMessage(); // We only create one object of this class
    messageObj.setWaitMessage('Betöltés - kérlek várj ...');
    messageObj.setShadowOffset(5); // Large shadow
    messageObj.setSource(false);
    messageObj.setCssClassMessageBox(false);
    messageObj.setSize(sizeX, sizeY);
    messageObj.setShadowDivVisible(true); // Enable shadow for these boxes
    messageObj.display();
}

function CloseModalBox() {
    messageObj.close();
    $('DHTMLSuite_modalBox_contentDiv').innerHTML = "";
}
function LoadModalBox(url, sizeX, sizeY) {
    DisplayModalBox(sizeX, sizeY);
    LoadPP("DHTMLSuite_modalBox_contentDiv", url, true);
}
// ***********************************
// EDIT TEXT
// ***********************************
function TextEdit(code) {
    LoadModalBox("/PageParts/PPTextEditForm.aspx?code=" + code, 700, 500)
}
function OnTextEditSave() {
    var result = valid.validate();
    if (result) {
        LoadPP("divTextEditResult", "/PageParts/PPTextEditSave.aspx?desc=" + encodeURI($('textboxTextDescription').value) +
                "&code=" + encodeURI($('hiddenTextCode').value), true);
    }
}
function OnTextEditSaved() {
    CloseModalBox();
    window.location = window.location;
}

// ***********************************
// Nifty
// ***********************************

function NiftyCheck() {
    if (!document.getElementById || !document.createElement)
        return (false);
    var b = navigator.userAgent.toLowerCase();
    if (b.indexOf("msie 5") > 0 && b.indexOf("opera") == -1)
        return (false);
    return (true);
}

function Rounded(selector, bk, color, size) {
    var i;
    var v = getElementsBySelector(selector);
    var l = v.length;
    for (i = 0; i < l; i++) {
        AddTop(v[i], bk, color, size);
        AddBottom(v[i], bk, color, size);
    }
}

function RoundedTop(selector, bk, color, size) {
    var i;
    var v = getElementsBySelector(selector);
    for (i = 0; i < v.length; i++)
        AddTop(v[i], bk, color, size);
}

function RoundedBottom(selector, bk, color, size) {
    var i;
    var v = getElementsBySelector(selector);
    for (i = 0; i < v.length; i++)
        AddBottom(v[i], bk, color, size);
}

function AddTop(el, bk, color, size) {
    var i;
    var d = document.createElement("b");
    var cn = "r";
    var lim = 4;
    if (size && size == "small") { cn = "rs"; lim = 2 }
    d.className = "rtop";
    d.style.backgroundColor = bk;
    for (i = 1; i <= lim; i++) {
        var x = document.createElement("b");
        x.className = cn + i;
        x.style.backgroundColor = color;
        d.appendChild(x);
    }
    el.insertBefore(d, el.firstChild);
}

function AddBottom(el, bk, color, size) {
    var i;
    var d = document.createElement("b");
    var cn = "r";
    var lim = 4;
    if (size && size == "small") { cn = "rs"; lim = 2 }
    d.className = "rbottom";
    d.style.backgroundColor = bk;
    for (i = lim; i > 0; i--) {
        var x = document.createElement("b");
        x.className = cn + i;
        x.style.backgroundColor = color;
        d.appendChild(x);
    }
    el.appendChild(d, el.firstChild);
}

function getElementsBySelector(selector) {
    var i;
    var s = [];
    var selid = "";
    var selclass = "";
    var tag = selector;
    var objlist = [];
    if (selector.indexOf(" ") > 0) {  //descendant selector like "tag#id tag"
        s = selector.split(" ");
        var fs = s[0].split("#");
        if (fs.length == 1) return (objlist);
        return (document.getElementById(fs[1]).getElementsByTagName(s[1]));
    }
    if (selector.indexOf("#") > 0) { //id selector like "tag#id"
        s = selector.split("#");
        tag = s[0];
        selid = s[1];
    }
    if (selid != "") {
        objlist.push(document.getElementById(selid));
        return (objlist);
    }
    if (selector.indexOf(".") > 0) {  //class selector like "tag.class"
        s = selector.split(".");
        tag = s[0];
        selclass = s[1];
    }
    var v = document.getElementsByTagName(tag);  // tag selector like "tag"
    if (selclass == "")
        return (v);
    for (i = 0; i < v.length; i++) {
        if (v[i].className == selclass) {
            objlist.push(v[i]);
        }
    }
    return (objlist);
}

// ***********************************
// Validation
// ***********************************

/*
* Really easy field validation with Prototype
* http://tetlaw.id.au/view/javascript/really-easy-field-validation
* Andrew Tetlaw
* Version 1.5.4.1 (2007-01-05)
* 
* Copyright (c) 2007 Andrew Tetlaw
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* 
*/
var Validator = Class.create();

Validator.prototype = {
    initialize: function(className, error, test, options) {
        if (typeof test === 'function') {
            this.options = $H(options);
            this._test = test;
        } else {
            this.options = $H(test);
            this._test = function() { return true; };
        }
        this.error = error || 'Validation failed.';
        this.className = className;
    },
    test: function(v, elm) {
        return (this._test(v, elm) && this.options.all(function(p) {
            return Validator.methods[p.key] ? Validator.methods[p.key](v, elm, p.value) : true;
        }));
    }
};
Validator.methods = {
    pattern: function(v, elm, opt) { return Validation.get('IsEmpty').test(v) || opt.test(v); },
    minLength: function(v, elm, opt) { return v.length >= opt; },
    maxLength: function(v, elm, opt) { return v.length <= opt; },
    min: function(v, elm, opt) { return v >= parseFloat(opt); },
    max: function(v, elm, opt) { return v <= parseFloat(opt); },
    notOneOf: function(v, elm, opt) {
        return $A(opt).all(function(value) {
            return v !== value;
        });
    },
    oneOf: function(v, elm, opt) {
        return $A(opt).any(function(value) {
            return v === value;
        });
    },
    'is': function(v, elm, opt) { return v === opt; },
    isNot: function(v, elm, opt) { return v !== opt; },
    equalToField: function(v, elm, opt) { return v === $F(opt); },
    notEqualToField: function(v, elm, opt) { return v !== $F(opt); },
    include: function(v, elm, opt) {
        return $A(opt).all(function(value) {
            return Validation.get(value).test(v, elm);
        });
    }
};

var Validation = Class.create();

Validation.prototype = {
    initialize: function(form, options) {
        this.options = Object.extend({
            onSubmit: true,
            stopOnFirst: false,
            immediate: false,
            focusOnError: true,
            useTitles: false,
            onFormValidate: function(result, form) { },
            onElementValidate: function(result, elm) { }
        }, options || {});
        this.form = $(form);
        if (this.options.onSubmit) { Event.observe(this.form, 'submit', this.onSubmit.bind(this), false); }
        if (this.options.immediate) {
            var useTitles = this.options.useTitles;
            var callback = this.options.onElementValidate;
            Form.getElements(this.form).each(function(input) { // Thanks Mike!
                Event.observe(input, 'blur', function(ev) { Validation.validate(Event.element(ev), { useTitle: useTitles, onElementValidate: callback }); });
            });
        }
    },
    onSubmit: function(ev) {
        if (!this.validate()) { Event.stop(ev); }
    },
    validate: function() {
        var result = false;
        var useTitles = this.options.useTitles;
        var callback = this.options.onElementValidate;
        if (this.options.stopOnFirst) {
            result = Form.getElements(this.form).all(function(elm) { return Validation.validate(elm, { useTitle: useTitles, onElementValidate: callback }); });
        } else {
            result = Form.getElements(this.form).collect(function(elm) { return Validation.validate(elm, { useTitle: useTitles, onElementValidate: callback }); }).all();
        }
        if (!result && this.options.focusOnError) {
            Form.getElements(this.form).findAll(function(elm) { return $(elm).hasClassName('validation-failed'); }).first().focus();
        }
        this.options.onFormValidate(result, this.form);
        return result;
    },
    reset: function() {
        Form.getElements(this.form).each(Validation.reset);
    }
};

Object.extend(Validation, {
    validate: function(elm, options) {
        options = Object.extend({
            useTitle: false,
            onElementValidate: function(result, elm) { }
        }, options || {});
        elm = $(elm);
        var cn = elm.classNames();
        var result = cn.all(function(value) {
            var test = Validation.test(value, elm, options.useTitle);
            options.onElementValidate(test, elm);
            return test;
        });
        return result;
    },
    test: function(name, elm, useTitle) {
        var v = Validation.get(name);
        var prop = '__advice' + name.camelize();
        try {
            if (Validation.isVisible(elm) && !v.test($F(elm), elm)) {
                if (!elm[prop]) {
                    var advice = Validation.getAdvice(name, elm);
                    if (advice === null) {
                        var errorMsg = useTitle ? ((elm && elm.title) ? elm.title : v.error) : v.error;
                        advice = '<div class="validation-advice" id="advice-' + name + '-' + Validation.getElmID(elm) + '" style="display:none">' + errorMsg + '</div>';
                        switch (elm.type.toLowerCase()) {
                            case 'checkbox':
                            case 'radio':
                                var p = elm.parentNode;
                                if (p) {
                                    new Insertion.Bottom(p, advice);
                                } else {
                                    new Insertion.After(elm, advice);
                                }
                                break;
                            default:
                                new Insertion.After(elm, advice);
                        }
                        advice = Validation.getAdvice(name, elm);
                    }
                    if (typeof Effect == 'undefined') {
                        advice.style.display = 'block';
                    } else {
                        new Effect.Appear(advice, { duration: 1 });
                    }
                }
                elm[prop] = true;
                elm.removeClassName('validation-passed');
                elm.addClassName('validation-failed');
                return false;
            } else {
                var advice = Validation.getAdvice(name, elm);
                if (advice != null) { advice.hide(); }
                elm[prop] = '';
                elm.removeClassName('validation-failed');
                elm.addClassName('validation-passed');
                return true;
            }
        } catch (e) {
            throw (e);
        }
    },
    isVisible: function(elm) {
        while (elm.tagName != 'BODY') {
            if (!$(elm).visible()) return false;
            elm = elm.parentNode;
        }
        return true;
    },
    getAdvice: function(name, elm) {
        return $('advice-' + name + '-' + Validation.getElmID(elm)) || $('advice-' + Validation.getElmID(elm));
    },
    getElmID: function(elm) {
        return elm.id ? elm.id : elm.name;
    },
    reset: function(elm) {
        elm = $(elm);
        var cn = elm.classNames();
        cn.each(function(value) {
            var prop = '__advice' + value.camelize();
            if (elm[prop]) {
                var advice = Validation.getAdvice(value, elm);
                advice.hide();
                elm[prop] = '';
            }
            elm.removeClassName('validation-failed');
            elm.removeClassName('validation-passed');
        });
    },
    add: function(className, error, test, options) {
        var nv = {};
        nv[className] = new Validator(className, error, test, options);
        Object.extend(Validation.methods, nv);
    },
    addAllThese: function(validators) {
        var nv = {};
        $A(validators).each(function(value) {
            nv[value[0]] = new Validator(value[0], value[1], value[2], (value.length > 3 ? value[3] : {}));
        });
        Object.extend(Validation.methods, nv);
    },
    get: function(name) {
        return Validation.methods[name] ? Validation.methods[name] : Validation.methods['_LikeNoIDIEverSaw_'];
    },
    methods: {
        '_LikeNoIDIEverSaw_': new Validator('_LikeNoIDIEverSaw_', '', {})
    }
});

Validation.add('IsEmpty', '', function(v) {
    return ((v == null) || (v.length == 0)); // || /^\s+$/.test(v));
});

Validation.addAllThese([
	['required', 'A mező kitöltése kötelező!', function(v) {
	    return !Validation.get('IsEmpty').test(v);
	} ],
	['validate-number', 'Kérlek írj be egy számot.', function(v) {
	    return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v));
	} ],
	['validate-digits', 'Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.', function(v) {
	    return Validation.get('IsEmpty').test(v) || !/[^\d]/.test(v);
	} ],
	['validate-alpha', 'Please use letters only (a-z) in this field.', function(v) {
	    return Validation.get('IsEmpty').test(v) || /^[a-zA-Z]+$/.test(v)
	} ],
	['validate-alphanum', 'Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.', function(v) {
	    return Validation.get('IsEmpty').test(v) || !/\W/.test(v)
	} ],
	['validate-date', 'Please enter a valid date.', function(v) {
	    //var test = new Date(v);
	    //return Validation.get('IsEmpty').test(v) || !isNaN(test);
	    if (Validation.get('IsEmpty').test(v)) { return true; }
	    var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
	    if (!regex.test(v)) { return false; }
	    var d = new Date(v);
	    return (parseInt(RegExp.$2, 10) == (1 + d.getMonth())) &&
							(parseInt(RegExp.$1, 10) == d.getDate()) &&
							(parseInt(RegExp.$3, 10) == d.getFullYear());
	} ],
	['validate-time', 'Az időt óó:pp formában kell megadni.', function(v) {
	    if (Validation.get('IsEmpty').test(v)) { return true; }
	    var regex = /^(\d{2}):(\d{2})$/;
	    if (!regex.test(v)) { return false; }
	    return (parseInt(RegExp.$1, 10) >= 0) && (parseInt(RegExp.$1, 10) < 24) &&
	           (parseInt(RegExp.$2, 10) >= 0) && (parseInt(RegExp.$2, 10) < 60);
	} ],
	['validate-email', 'Kérlek írj be egy valós e-mail címet.', function(v) {
	    return Validation.get('IsEmpty').test(v) || /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)
	} ],
	['validate-url', 'Kérlek írj be egy valós web címet.', function(v) {
	    return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
	} ],
	['validate-date-au', 'Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.', function(v) {
	    if (Validation.get('IsEmpty').test(v)) { return true; }
	    var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
	    if (!regex.test(v)) { return false; }
	    var d = new Date(v.replace(regex, '$2/$1/$3'));
	    return (parseInt(RegExp.$2, 10) == (1 + d.getMonth())) &&
							(parseInt(RegExp.$1, 10) == d.getDate()) &&
							(parseInt(RegExp.$3, 10) == d.getFullYear());
	} ],
	['validate-currency-dollar', 'Please enter a valid $ amount. For example $100.00 .', function(v) {
	    // [$]1[##][,###]+[.##]
	    // [$]1###+[.##]
	    // [$]0.##
	    // [$].##
	    return Validation.get('IsEmpty').test(v) || /^\$?\-?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}\d*(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(v)
	} ],
	['validate-selection', 'Kérlek válassz egyet a listából.', function(v, elm) {
	    return elm.options ? elm.selectedIndex > 0 : !Validation.get('IsEmpty').test(v);
	} ],
	['validate-one-required', 'Please select one of the above options.', function(v, elm) {
	    var p = elm.parentNode;
	    var options = p.getElementsByTagName('INPUT');
	    return $A(options).any(function(elm) {
	        return $F(elm);
	    });
	} ]
]);

// ***********************************
// tooltip
// ***********************************

/************************************************************************************************************
(C) www.dhtmlgoodies.com, October 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

Updated:	April, 6th 2006, Using iframe in IE in order to make the tooltip cover select boxes.

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/
var dhtmlgoodies_tooltip = false;
var dhtmlgoodies_tooltipShadow = false;
var dhtmlgoodies_shadowSize = 4;
var dhtmlgoodies_tooltipMaxWidth = 250;
var dhtmlgoodies_tooltipMinWidth = 100;
var dhtmlgoodies_iframe = false;
var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent.indexOf('opera') == -1 && document.all) ? true : false;
function showTooltip(e, tooltipTxt) {

    var bodyWidth = Math.max(document.body.clientWidth, document.documentElement.clientWidth) - 20;

    if (!dhtmlgoodies_tooltip) {
        dhtmlgoodies_tooltip = document.createElement('DIV');
        dhtmlgoodies_tooltip.id = 'dhtmlgoodies_tooltip';
        dhtmlgoodies_tooltipShadow = document.createElement('DIV');
        dhtmlgoodies_tooltipShadow.id = 'dhtmlgoodies_tooltipShadow';

        document.body.appendChild(dhtmlgoodies_tooltip);
        document.body.appendChild(dhtmlgoodies_tooltipShadow);

        if (tooltip_is_msie) {
            dhtmlgoodies_iframe = document.createElement('IFRAME');
            dhtmlgoodies_iframe.frameborder = '5';
            dhtmlgoodies_iframe.style.backgroundColor = '#FFFFFF';
            dhtmlgoodies_iframe.src = '#';
            dhtmlgoodies_iframe.style.zIndex = 100;
            dhtmlgoodies_iframe.style.position = 'absolute';
            document.body.appendChild(dhtmlgoodies_iframe);
        }

    }

    dhtmlgoodies_tooltip.style.display = 'block';
    dhtmlgoodies_tooltipShadow.style.display = 'block';
    if (tooltip_is_msie) { dhtmlgoodies_iframe.style.display = 'block'; }

    var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
    if (navigator.userAgent.toLowerCase().indexOf('safari') >= 0) { st = 0; }
    var leftPos = e.clientX + 10;

    dhtmlgoodies_tooltip.style.width = null; // Reset style width if it's set 
    dhtmlgoodies_tooltip.innerHTML = tooltipTxt;
    dhtmlgoodies_tooltip.style.left = leftPos + 'px';
    dhtmlgoodies_tooltip.style.top = e.clientY + 10 + st + 'px';


    dhtmlgoodies_tooltipShadow.style.left = leftPos + dhtmlgoodies_shadowSize + 'px';
    dhtmlgoodies_tooltipShadow.style.top = e.clientY + 10 + st + dhtmlgoodies_shadowSize + 'px';

    if (dhtmlgoodies_tooltip.offsetWidth > dhtmlgoodies_tooltipMaxWidth) {	/* Exceeding max width of tooltip ? */
        dhtmlgoodies_tooltip.style.width = dhtmlgoodies_tooltipMaxWidth + 'px';
    }

    var tooltipWidth = dhtmlgoodies_tooltip.offsetWidth;
    if (tooltipWidth < dhtmlgoodies_tooltipMinWidth) { tooltipWidth = dhtmlgoodies_tooltipMinWidth; }


    dhtmlgoodies_tooltip.style.width = tooltipWidth + 'px';
    dhtmlgoodies_tooltipShadow.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
    dhtmlgoodies_tooltipShadow.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';

    if ((leftPos + tooltipWidth) > bodyWidth) {
        dhtmlgoodies_tooltip.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px', '') - ((leftPos + tooltipWidth) - bodyWidth)) + 'px';
        dhtmlgoodies_tooltipShadow.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px', '') - ((leftPos + tooltipWidth) - bodyWidth) + dhtmlgoodies_shadowSize) + 'px';
    }

    if (tooltip_is_msie) {
        dhtmlgoodies_iframe.style.left = dhtmlgoodies_tooltip.style.left;
        dhtmlgoodies_iframe.style.top = dhtmlgoodies_tooltip.style.top;
        dhtmlgoodies_iframe.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
        dhtmlgoodies_iframe.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';

    }

}

function hideTooltip() {
    dhtmlgoodies_tooltip.style.display = 'none';
    dhtmlgoodies_tooltipShadow.style.display = 'none';
    if (tooltip_is_msie) { dhtmlgoodies_iframe.style.display = 'none'; }
}