/*global window */
function refreshMenu(file1) {
    top.CONTENT.location = file1;
}

function addToBookmark(title, url) {
    if (window.sidebar) {
        // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) {
        // IE Favorite
        window.external.AddFavorite(url, title);
    } else if (window.opera && window.print) {
        // Opera Hotlist
        return true;
    }
}

function loadImages() {
    if (document.getElementById) {
        // DOM3 = IE5, NS6
        document.getElementById('hidepage').style.visibility = 'hidden';
    } else {
        if (document.layers) {
            // Netscape 4
            document.hidepage.visibility = 'hidden';
        } else {
            // IE 4
            document.all.hidepage.style.visibility = 'hidden';
        }
    }
}

function popup(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function MM_preloadImages() { //v3.0
    var d = document,
        i = 0,
        j = 0,
        a = null;

    if (d.images) {
        if (!d.MM_p) {
            d.MM_p = [];
        }
        j = d.MM_p.length;
        a = MM_preloadImages['arguments'];
        for (i = 0; i < a.length; i += 1) {
            if (a[i].indexOf("#") !== 0) {
                d.MM_p[j] = new Image();
                d.MM_p[j].src = a[i];
                j += 1;
            }
        }
    }
}

function MM_swapImgRestore() { //v3.0
    var i,
        x,
        a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i += 1) {
        x.src = x.oSrc;
    }
}

function mm_findObj(n, d) { //v4.01
    var p, i, x;
    if (!d) {
        d = document;
    }
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) {
        x = d.all[n];
    }
    for (i = 0; !x && i < d.forms.length; i += 1) {
        x = d.forms[i][n];
    }
    for (i = 0; !x && d.layers && i < d.layers.length; i += 1) {
        x = mm_findObj(n, d.layers[i].document);
    }
    if (!x && d.getElementById) {
        x = d.getElementById(n);
    }
    return x;
}

function MM_swapImage() { //v3.0
    var i,
        j = 0,
        x,
        a = MM_swapImage['arguments'];

    document.MM_sr = [];
    for (i = 0; i < (a.length - 2); i += 3) {
        if ((x = mm_findObj(a[i])) !== null) {
            document.MM_sr[j] = x;
            j += 1;
            if (!x.oSrc) {
                x.oSrc = x.src;
            }
            x.src = a[i + 2];
        }
    }
}


function elkuld(page) {
    var frm    = document.form;
    frm.bejovo.value = page;
    frm.method    = "get";
    frm.target    = "_self";
    frm.action    = "reszletes_kereses.php";
    frm.submit();
}

var selectedvalues = [];
var values = [];
var listak = ['list.1', 'list.2', 'list.3', 'list.4', 'list.5', 'list.6', 'list.7', 'list.8', 'list.9'];
var isIE = (-1 !== navigator.userAgent.indexOf('MSIE'));

function getListCaption(listId, val) {
    return values[listId + "," + val];
}

function getListValue(id) {
    return (selectedvalues[id] ? selectedvalues[id] : "");
}

function togglelist(id, value) {
    var obj = document.getElementById(id);
    if (obj.style.display === "none") {
        obj.style.display = "";
    } else {
        obj.style.display = "none";
    }
    if (value) {
        obj = document.getElementById(id + ".text");
        obj.innerHTML = values[id + ',' + value];
        selectedvalues[id] = value;
    }
}

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else {
        if (obj.attachEvent) {
            var r = obj.attachEvent("on" + evType, fn);
            return r;
        } else {
            return false;
        }
    }
}

function listChecker(evt) {
    var l = null,
        obj = null;

    evt = evt || window.event;
    for (l in listak) {
        if (listak.hasOwnProperty(l)) {
            obj = document.getElementById(listak[l]);
            if (!obj) {
                continue;
            }
            if (obj.style.display === "none") {
                continue;
            }
            if (evt.clientX + (document.all ? document.body.scrollLeft : window.pageXOffset) - 8 < obj.offsetLeft || 
                evt.clientX + (document.all ? document.body.scrollLeft : window.pageXOffset) - 8 > obj.offsetLeft + obj.offsetWidth || 
                evt.clientY + (document.all ? document.body.scrollTop : window.pageYOffset) - 8 < obj.offsetTop - 24 || 
                evt.clientY + (document.all ? document.body.scrollTop : window.pageYOffset) - 8 > obj.offsetTop + obj.offsetHeight) {
                obj.style.display = "none";
            }
        }
    }
}

function filllist() {
    var v = null,
        oTable = null,
        oRow = null,
        oCell = null,
        attr = null,
        v1 = '',
        v2 = '';
    
    addEvent(document.body, 'mousemove', listChecker);
    for (v in values) {
        if (values.hasOwnProperty(v)) {
            v1 = v.split(',')[0];
            v2 = v.split(',')[1];
            oTable = document.createElement("TABLE");
            attr = document.createAttribute("border");
            attr.nodeValue = 0;
            oTable.setAttributeNode(attr);
            attr = document.createAttribute("cellpadding");
            attr.nodeValue = 0;
            oTable.setAttributeNode(attr);
            attr = document.createAttribute("cellspacing");
            attr.nodeValue = 0;
            oTable.setAttributeNode(attr);
            oTable.style.width = document.getElementById(v1).style.width;
            oRow = oTable.insertRow(-1);
            oRow.onmouseover = function () {
                this.style.backgroundColor = '#7ab4f3';
            };
            oRow.onmouseout = function () {
                this.style.backgroundColor = '#ffffff';
            };
            oRow.style.cursor = "pointer";
            oCell = oRow.insertCell(-1);
            oCell.innerHTML = values[v];
            oCell.style.font = "8pt Arial";
            oCell.style.color = "#000000";
            oCell.style.width = "100%";
            oCell.style.paddingLeft = "4px";
            if (isIE) {
                oCell.onclick = new Function( "togglelist('" + v1 + "','" + v2 + "');");
            } else {
                oCell.setAttribute('onclick', "togglelist('" + v1 + "', '" + v2 + "')");
            }
            document.getElementById(v1).appendChild(oTable);
        }
    }
}

function uresCheck(mezo) {
    if (mezo.value !== '') {
        return true;
    }
    return false;
}
function emailCheck(mezo) {
    var szoveg = mezo.value;
    if (!(szoveg.indexOf('@') > 0 && szoveg.indexOf('@') < szoveg.length - 1)) {
        return false;
    }
    return true;
}
function ellenorzes_kapcsolat() {
    if (!uresCheck(document.form1.nev)) {
        window.alert('Просим Вас указать Ваше имя');
        document.form1.nev.focus();
        return false;
    }
    else if (!uresCheck(document.form1.email)) {
        window.alert('Просим , укажите адресс Вашей электронной почты');
        document.form1.email.focus();
        return false;
    }
    else if (!emailCheck(document.form1.email)) {
        window.alert("Неправильный адресс");
        document.form1.email.focus();
        return false;
    }
    else if (!uresCheck(document.form1.kerese)) {
        window.alert('Просим Вас заполнить поле просьбы');
        document.form1.kerese.focus();
        return false;
    }
    return true;
}

function ellenorzes_elado() {
    if (!uresCheck(document.form1.nev)) {
        window.alert('Просим Вас указать Ваше имя');
        document.form1.nev.focus();
        return false;
    }
    else if (!uresCheck(document.form1.telefonszam)) {
        window.alert('Просим указать номер Вашего телефона');
        document.form1.telefonszam.focus();
        return false;
    }
    else if (!uresCheck(document.form1.leiras)) {
        window.alert('Просим заполнить и поле «описание»');
        document.form1.leiras.focus();
        return false;
    }
    return true;
}

function deleteFrom() {
    var frm = document.getElementById("form1");
    frm.nev.value = "";
    frm.email.value = "";
    frm.kerese.value = "";
    return false;
}

var CAPITAL = {};

/**
 * this function replaces the mailto links which have the form (href tag):
 * nospam:account__AT__sub__DOT__domain__DOT__tld
 * and the id: nospam_X
 * where X is a number (starting from 1 and continous)
 * innerHTML will be set to the email address 
 */
CAPITAL.antiSpam = function () {
    var i = 0,
        a = null,
        old = '',
        newHref = '';
    while (true) {
        i += 1;
        a = document.getElementById('nospam_' + i);
        if (!a) {
            return;
        }
        // replace link's href attribute
        old = a.href;
        newHref = old.replace('nospam:', '');
        newHref = newHref.replace(/__AT__/, '@');
        newHref = newHref.replace(/__DOT__/g, '.'); // g --> replace all occurances
        a.href = 'mailto:' + newHref;
        a.innerHTML = newHref;
    }
};


var F = {};
F.slider = null;

F.init = function () {
    if (document.getElementById('slider_div')) {
        // holder div id, speed, width, height
        F.slider = new F.CreateSlideShow('slider_div', 6, 611, 151);
    }
};

//////////////////////////////////////
// Romulo do Nascimento Ferreira    //
//         romulo.nf@gmail.com      //
//////////////////////////////////////
F.CreateSlideShow = function (holder, speed, width, height) {
    var gallery = document.getElementById(holder),
        x = 0,
        my_this = null,
        startShow = null;

    gallery.style.width = width + "px";
    gallery.style.height = height + "px";
    gallery.style.cssFloat = "left";
    this.alphaShow = 0;
    this.alphaFade = 100;
    this.currentImg = 0;
    this.animationSpeed = speed;
    this.images = gallery.getElementsByTagName("img");
    this.galleryLength = this.images.length;
     
    for (x = 0; x < this.galleryLength; x += 1) {
        this.images[x].style.width = width + "px";
        this.images[x].style.height = height + "px";
        this.images[x].style.position = "absolute";
        this.images[x].style.filter = "alpha(opacity=0)";
        this.images[x].style.opacity = "0";
        this.images[x].style.mozOpacity = "0";
    }
     
    my_this = this;
    startShow = window.setInterval(function () {
        my_this.engine();
    }, this.animationSpeed * 30);
};

F.CreateSlideShow.prototype.engine = function () {
    this.nextImage = this.currentImg + 1 < this.galleryLength ? this.currentImg + 1 : 0;
    this.images[this.currentImg].style.filter = "alpha(opacity=" + this.alphaFade + ")";
    this.images[this.currentImg].style.opacity = this.alphaFade < 10 ? "0.0" + this.alphaFade : this.alphaFade >= 10 && this.alphaFade < 100 ? "0." + this.alphaFade : 1.0;
    this.images[this.currentImg].style.mozOpacity = this.alphaFade < 10 ? "0.0" + this.alphaFade : this.alphaFade >= 10 && this.alphaFade < 100 ? "0." + this.alphaFade : 1.0;
    this.images[this.nextImage].style.filter = "alpha(opacity=" + this.alphaShow + ")";
    this.images[this.nextImage].style.opacity = this.alphaShow < 10 ? "0.0" + this.alphaShow : this.alphaShow >= 10 && this.alphaShow < 100 ? "0." + this.alphaShow : 1.0;
    this.images[this.nextImage].style.mozOpacity = this.alphaShow < 10 ? "0.0" + this.alphaShow : this.alphaShow >= 10 && this.alphaShow < 100 ? "0." + this.alphaShow : 1.0;
    this.alphaFade = this.alphaFade - 2;
    this.alphaShow = this.alphaShow + 2;
    if (this.alphaFade === 100 || this.alphaShow === 100) {
        this.alphaFade = 100;
        this.alphaShow = 0;
        this.currentImg = this.currentImg + 1 > this.galleryLength - 1 ? 0 : this.currentImg + 1;
    }
};


CAPITAL.init = function () {
    CAPITAL.antiSpam();
    //F.init();
};


// make the function run when the page is loaded
if (window.addEventListener) {
    window.addEventListener("load", CAPITAL.init, false);
} else {
    if (window.attachEvent) {
        window.attachEvent("onload", CAPITAL.init);
    } else {
        // try to run now
        CAPITAL.init();
    }
}


