function getCookie(name) {
    var nameEQ = name + "=",
        ca = document.cookie.split(';'),
        s = "",
        i, j,
        item,
        objCookie = [];
    for(i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') {
            c = c.substring(1,c.length);
        }
	if (c.indexOf(nameEQ) == 0) {
            s = c.substring(nameEQ.length,c.length);
            s = s.split(/&/);
            for (j = 0; j < s.length; j++) {
                item = s[j].split(/=/);
                objCookie[item[0]] = item[1];
            }
            return objCookie;
        }
    }
    return null;
}
function wfg_is_valid_onlinefoglalas_nev(el){if(el.toString().match(/^.{4,}$/i)){return true;}return false;}
function wfg_is_valid_onlinefoglalas_telefonszam(el){if(el.toString().match(/^[\d.\/() \-+]{7,}$/i)){return true;}return false;}
function wfg_is_valid_onlinefoglalas_email(el){if(el.toString().match(/^[-\w@\._]+\.[\w]{2,6}$/i)){return true;}return false;}
function wfg_is_valid_onlinefoglalas_erkezesdatuma(el){if(el.toString().match(/^.+$/i)){return true;}return false;}
function wfg_is_valid_onlinefoglalas_tavozasdatuma(el){if(el.toString().match(/^.+$/i)){return true;}return false;}
function wfg_is_valid_onlinefoglalas_felnottekszama(el){if(el.toString().match(/^.+$/i)){return true;}return false;}
function wfg_onlinefoglalas_form_submit(e){var error=false;document.getElementById('onlinefoglalas_nev_block').className='valid';
if(!wfg_is_valid_onlinefoglalas_nev(document.getElementById('onlinefoglalas_nev').value)){document.getElementById('onlinefoglalas_nev_block').className='error';error=true;}document.getElementById('onlinefoglalas_telefonszam_block').className='valid';
if(!wfg_is_valid_onlinefoglalas_telefonszam(document.getElementById('onlinefoglalas_telefonszam').value)){document.getElementById('onlinefoglalas_telefonszam_block').className='error';error=true;}document.getElementById('onlinefoglalas_email_block').className='valid';
if(!wfg_is_valid_onlinefoglalas_email(document.getElementById('onlinefoglalas_email').value)){document.getElementById('onlinefoglalas_email_block').className='error';error=true;}document.getElementById('onlinefoglalas_erkezesdatuma_block').className='valid';
if(!wfg_is_valid_onlinefoglalas_erkezesdatuma(document.getElementById('onlinefoglalas_erkezesdatuma').value)){document.getElementById('onlinefoglalas_erkezesdatuma_block').className='error';error=true;}document.getElementById('onlinefoglalas_tavozasdatuma_block').className='valid';
if(!wfg_is_valid_onlinefoglalas_tavozasdatuma(document.getElementById('onlinefoglalas_tavozasdatuma').value)){document.getElementById('onlinefoglalas_tavozasdatuma_block').className='error';error=true;}document.getElementById('onlinefoglalas_felnottekszama_block').className='valid';
if(!wfg_is_valid_onlinefoglalas_felnottekszama(document.getElementById('onlinefoglalas_felnottekszama').value)){document.getElementById('onlinefoglalas_felnottekszama_block').className='error';error=true;}if(error){alert('Kérem, töltsön ki minden csillaggal (*) jelőlt mezőt.');if(e&&e.preventDefault){ e.preventDefault();}return false;}document.getElementById('onlinefoglalas_form').submit();}
function addEvent(obj,evType,fn){if(obj.addEventListener){obj.addEventListener(evType,fn,false);return true;}else if(obj.attachEvent){return obj.attachEvent('on'+evType,fn);}return false;}
function wfg_onlinefoglalas_load_events(){
    addEvent(document.getElementById('onlinefoglalas_submit'),'click',wfg_onlinefoglalas_form_submit);
    var data = getCookie('venus_miniform');
    // We have to wait here a while to let `dojo.parser.parse()` to run before we fill
    // input field values.
    setTimeout(function() {
        if (!!data) {
            document.getElementById('onlinefoglalas_nev').value = data['nev'];
            document.getElementById('onlinefoglalas_email').value = data['email'];
            document.getElementById('onlinefoglalas_erkezesdatuma').value = data['erkezes'];
            document.getElementById('onlinefoglalas_tavozasdatuma').value = data['tavozas'];
        }
    }, 1000);
}
addEvent(window,'load',wfg_onlinefoglalas_load_events);
