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_szallasfoglalas_fullname(el){if(el.toString().match(/^.{4,}$/i)){return true;}return false;}
function wfg_is_valid_szallasfoglalas_email(el){if(el.toString().match(/^[-\w@\._]+\.[\w]{2,6}$/i)){return true;}return false;}
function wfg_is_valid_szallasfoglalas_arrival(el){if(el.toString().match(/^.+$/i)){return true;}return false;}
function wfg_is_valid_szallasfoglalas_departure(el){if(el.toString().match(/^.+$/i)){return true;}return false;}
function wfg_szallasfoglalas_form_submit(e){
    var error=false;document.getElementById('szallasfoglalas_fullname_block').className='valid';
if(!wfg_is_valid_szallasfoglalas_fullname(document.getElementById('szallasfoglalas_fullname').value)){document.getElementById('szallasfoglalas_fullname_block').className='error';error=true;}document.getElementById('szallasfoglalas_email_block').className='valid';
if(!wfg_is_valid_szallasfoglalas_email(document.getElementById('szallasfoglalas_email').value)){document.getElementById('szallasfoglalas_email_block').className='error';error=true;}document.getElementById('szallasfoglalas_arrival_block').className='valid';
if(!wfg_is_valid_szallasfoglalas_arrival(document.getElementById('szallasfoglalas_arrival').value)){document.getElementById('szallasfoglalas_arrival_block').className='error';error=true;}document.getElementById('szallasfoglalas_departure_block').className='valid';
if(!wfg_is_valid_szallasfoglalas_departure(document.getElementById('szallasfoglalas_departure').value)){document.getElementById('szallasfoglalas_departure_block').className='error';error=true;}if(error){alert('Kérjük valamennyi mezőt kitölteni!');if(e&&e.preventDefault){ e.preventDefault();}return false;}

    document.getElementById('szallasfoglalas_form').elements['szallasfoglalas_arrival'][1].value = document.getElementById('szallasfoglalas_arrival').value;
    document.getElementById('szallasfoglalas_form').elements['szallasfoglalas_departure'][1].value = document.getElementById('szallasfoglalas_departure').value;

    document.getElementById('szallasfoglalas_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_szallasfoglalas_load_events(){
    addEvent(document.getElementById('szallasfoglalas_submit'),'click',wfg_szallasfoglalas_form_submit);
    var data = getCookie('jagello_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('szallasfoglalas_fullname').value = data['nev'];
            document.getElementById('szallasfoglalas_email').value = data['email'];
            document.getElementById('szallasfoglalas_arrival').value = data['erkezes'];
            document.getElementById('szallasfoglalas_departure').value = data['tavozas'];
        }
    }, 1000);

}
addEvent(window,'load',wfg_szallasfoglalas_load_events);
