﻿function HideReactieButton(el) {
    if (el.parentNode.childNodes[2].style == null)
        el.parentNode.childNodes[3].style.display = "none";
    else
        el.parentNode.childNodes[2].style.display = "none";
}


function ShowReactieButton(el) {
    if (el.parentNode.childNodes[2].style == null) {
        el.parentNode.childNodes[3].style.display = "block";
    }
    else
        el.parentNode.childNodes[2].style.display = "block";
}

function OnClickGBInput(css, txt, el) {
    if (el.value == txt) {
        el.value = '';
    }
    el.className = css;
}

function OnBlurGBInput(css, txt, el) {
    if (el.value == '') {
        el.value = txt;
        el.className = css;
    }
}

function OnClickReactieInput(el) {
    if (el.value == 'Wat vindt jij?') {
        el.value = '';
        ShowReactieButton(el);
    }
    el.className = 'inputactive';
}

function OnBlurReactieInput(el) {
    if (el.value == '') {
        el.value = 'Wat vindt jij?';
        el.className = 'inputinactive';
        HideReactieButton(el);
    }
}

function OnSendReactie(el) {
    alert("Verstuur reactie: " + el.parentNode.childNodes[0].value);
}

function OnClickWUDInput(el) {
    if (el.value == 'Wist u dat...') {
        el.value = '';
        ShowReactieButton(el);
    }

    el.className = 'inputactive';
}

function OnBlurWUDInput(el) {
    if (el.value == '') {
        el.value = 'Wist u dat...';
        el.className = 'inputinactive';
        HideReactieButton(el);
    }
}

function OnSendWUD(el) {
    alert("Verstuur reactie: " + el.parentNode.childNodes[0].value);
}


var _curArtikelID = null;
var _curFotoID = null;
var _curTBID = null;
var _curBtnEl = null;

function AddReactie(artikelID, fotoID, albumID, txtElID, btnEl) {

    if (isIngelogd) {
        _curBtnEl = btnEl;
        _curArtikelID = artikelID;
        _curFotoID = fotoID;
        _curTBID = txtElID;
        _curBtnEl.style.display = "none";
        var el = document.getElementById(txtElID);
        el.disabled = true;
        BVRooi.Site.webservices.UI.InsertReactie(artikelID, fotoID, albumID, el.value, OnReactieSuccess, OnWSError, null);
    }
    else {
        alert('Je moet aangemeld zijn om te kunnen reageren!');
    }
}

function ToonAlleReacties(artikelID, fotoID) {
    _curArtikelID = artikelID;
    _curFotoID = fotoID;
    BVRooi.Site.webservices.UI.ToonAlleReacties(artikelID, fotoID, OnAlleReactiesSuccess, OnWSError, null);
}

function OnReactieSuccess(result) {
    var el = null;
    _curBtnEl.style.display = "block";

    if (_curArtikelID != null)
        el = document.getElementById('reacties_a' + _curArtikelID);
    else
        el = document.getElementById('reacties_f_' + _curFotoID);

    var el2 = document.getElementById(_curTBID);
    el2.disabled = false;
    el2.value = '';

    OnBlurReactieInput(el2);
    el.innerHTML = result;
}

function OnAlleReactiesSuccess(result) {

    var el = null;
    if (_curArtikelID != null)
        el = document.getElementById('reacties_a' + _curArtikelID);
    else
        el = document.getElementById('reacties_f_' + _curFotoID);
        
    el.innerHTML = result;
}

function OnWSError(result) {
    alert(result.get_message());
}

var _curElID = null;

function AddWUD(elID, txtElID) {
    if (isIngelogd) {
        _curElID = elID;
        _curTBID = txtElID;
        var el = document.getElementById(txtElID);
        BVRooi.Site.webservices.UI.InsertWUD(el.value, OnWUDSuccess, OnWSError, null);
    }
    else {
        alert('Je moet aangemeld zijn om te kunnen reageren!');
    }
}

function OnWUDSuccess(result) {
    var el = document.getElementById('wud_' + _curElID);
    var el2 = document.getElementById(_curTBID);
    el2.value = '';

    OnBlurWUDInput(el2);
    el.innerHTML = result;
}
