﻿

/*change the class of a object */
function changecssClass(objDivID, newclass) {
    var el = document.getElementById(objDivID);
    el.className = newclass
}


function noBack() {
    window.history.forward();
    initnoback();
}

function initnoback() {
    window.onpageshow = function(evt) {
        if (evt.persisted) noBack();
    }
    window.onunload = function() {
        void (0);
    }
}

/* swap a style class of two object(s) */
function swapcssClass(objDivID1, objDivID2) {
    var el1 = document.getElementById(objDivID1);
    var el2 = document.getElementById(objDivID2);
    var style = el1.className;
    el1.className = el2.className;
    el2.className = style;
}


// hide expanded fields onLoad...
function init() {
    noBack();
    addExpand('uitlegLink', 'faqcomplaint');
    initAutoPostBackControls();
    setPageHeight();
    HideBtns();
}




function addExpand(_clickClass, _containerClass) {
    $('.' + _clickClass, '.' + _containerClass).each(
    function() {

        var _questionLink = $(this).children('a');
        $(_questionLink).click(function() {
            $(this).parent().parent().parent().children('div').toggleClass('expanded');
        });
    });
    window.setTimeout('setPageHeight();', 500);
}

function placeExpandChar(_questionId) {
    var test = $(_questionId).down(1);
    if ((test.className = 'expand_blok') || (test.className = 'voorwaarden_expand_blok')) {
        if (test.up(2).className.match('expanded')) {
            test.innerHTML = '&#0709;';
        }
        else {
            test.innerHTML = '&#0707; ';
        }
    }
}


function onlineInvullen(elementId, valueToSet) {
    var toCheckId = elementId + '-' + valueToSet;
    var toCheck = document.getElementById(toCheckId);
    if (toCheck) {
        toCheck.checked = true;
        ClickNextBtn();
    }
}

function setSelectValue(selectBox, valueItem) {
    var selectList = document.getElementById(selectBox);
    if (selectList) {
        var i;
        for (i = 0; i < selectList.options.length; i++) {
            var toMatch = selectList.options[i].value;

            if (toMatch == valueItem) {
                selectList.selectedIndex = i;
            }
        }
    }
}


function setSelectWidth(vraagId) {
    var vraag = $(vraagId);
    vraag.style.width = 640 + 'px';
    //alert(vraag.style.width);

}

/* hide elements met opgegevens class*/
function hideElement(elementClass) {
    var toHide = $$('.' + elementClass);
    if (toHide) {
        toHide.each(
     function(_element) {
         _element.hide();
     }
     );
    }
}

function resetWidth(vraagElement) {
    // vraagElement.style.width= 440+'px'; 
    vraagElement.focus();
    alert(vraagElement);
}


function setPageHeight() {
    var contentElHeight = document.getElementById('middlecolumn').clientHeight;
    if (contentElHeight == null) { contentElHeight = document.body.clientHeight; }
    // alert(contentElHeight);
    var toSet = $('.frame');
    //  alert(toSet);
    if ((contentElHeight != null) && (toSet != null)) {
        toSet[0].style.height = contentElHeight + 200 + 'px';
    }
}


/* for ie : expand width of selectbox if it is clicked....  */

function expand_selectBox() {
    var toHide = $('OIA_Label_onlineInvullen-J');
    if (toHide) {
        HideNextBtn();
    }
}

function showDefinitie(term) {

    var termHolder = document.getElementById(term);
    if (termHolder != null) {
        var content = termHolder.innerHTML;
        var str = term + '_sp';
        var contentHolder = document.getElementById(str);

        if (contentHolder != null) {
            contentHolder.innerHTML = content;
        }

    }
}

function removeSpan(term) {
    var str = term + '_sp';
    var contentHolder = document.getElementById(str);
    if (contentHolder != null) {
        contentHolder.innerHTML = '';
    }
}


function initAutoPostBackControls() {
    $('input', '.dialogcomplaintradiobtnitem').each(
    function() {
        $(this).click(function() {
            setTimeout('postBackToBi()', 0);
        });
    });
    $('input', '.dialogcomplaintcheckitem').each(
    function() {
        $(this).click(function() {
            setTimeout('postBackToBi()', 0);
        });
    });    
}

//versie1
function doAjaxPostback() {
    //    $('aspnetForm').writeAttribute('action', 'ComplaintDialog.aspx');
    var serdata = $("#aspnetForm").find("input,textarea,select,hidden").not("#__VIEWSTATE,#__EVENTVALIDATION").serialize();

    $("body").css("cursor", "progress"); 
 
    $.ajax({
        type: "post",
        url: "ComplaintDialog.aspx",
        data: serdata,
        success: AjaxSucceeded,
        error: AjaxFailed
    });

}



function AjaxSucceeded(result) {
    if ($("status", result).text() != 0) {
        // something is not right
        alert($("message", response).text());
    }
    else {
        var myHtml = $("rawhtml", result).text();
        $("#dialogcontainer").html(myHtml);
        $("#dialogresult").html("");
        HideBtns();
    }
    setPageHeight();
    $("body").css("cursor", "auto");
}

function AjaxFailed(result) {
    $("body").css("cursor", "auto");
    alert("Probleem verkrijgen resultaat" + result.status + " " + result.statusText);
}

function postBackToBi() {
    doAjaxPostback();
}

//versie 2
function doAjaxPostback2() {
    //    $('aspnetForm').writeAttribute('action', 'ComplaintDialog.aspx');
    var serdata = $("#aspnetForm").find("input,textarea,select,hidden").not("#__VIEWSTATE,#__EVENTVALIDATION").serialize();

    $("body").css("cursor", "progress");

    $.ajax({
        type: "post",
        url: "ComplaintDialog.aspx?result=true",
        data: serdata,
        success: AjaxSucceeded2,
        error: AjaxFailed
    });

}

function AjaxSucceeded2(result) {
    if ($("status", result).text() != 0) 
    {
        // something is not right
        alert($("message", response).text());
    }
    else 
    {
        var myHtml = $("rawhtml", result).text();
        if (myHtml != "Er is geen afleiding gevonden") 
        {
            $("#dialogresult").html(myHtml);
            ShowBtns();
        }
        else 
        {
            $("#dialogresult").html("");
            HideBtns();
        }
    }
        
    setPageHeight();        
    $("body").css("cursor", "auto");   
}

function postBackToBi2() {
    doAjaxPostback2();
}



/**** ICONEN START *****/

function tooltip(tooltip_element, classname) {
    $(tooltip_element).each(function(i) {
        $("body").append("<div class='" + classname + "' id='" + classname + i + "'><p>" + $(this).attr('title') + "</p></div>");
        var img_tooltip = $("#" + classname + i);

        if ($(this).attr("title") != "" && $(this).attr("title") != "undefined") {

            $(this).removeAttr("title").mouseover(function() {
                /*img_tooltip.css({ opacity: 0.8, display: "none" }).fadeIn(800); */
                img_tooltip.css({ display: "none" }).fadeTo(1300, 0.8);
            }).mousemove(function(kmouse) {
                var border_top = $(window).scrollTop();
                var border_right = $(window).width();
                var left_pos;
                var top_pos;
                var offsetx = 5;
                var offsety = -40;
                if (border_right - (offsetx * 2) >= img_tooltip.width() + kmouse.pageX) {
                    left_pos = kmouse.pageX + offsetx;
                } else {
                    left_pos = border_right - img_tooltip.width() - offsetx;
                }

                if (border_top + (offsety * 0) >= kmouse.pageY - img_tooltip.height()) {
                    top_pos = border_top + offsety;
                } else {
                    top_pos = kmouse.pageY - img_tooltip.height() - offsety;
                }

                img_tooltip.css({ left: left_pos, top: top_pos });
            }).mouseout(function() {
                img_tooltip.css({ left: "-9999px" });
            });

        }

    });
}

function RestorePosition(element) {
    var xpos = element.attr('xorg') - 1;
    var ypos = element.attr('yorg') - 1;
    xpos = xpos * 59 + 2;
    ypos = ypos * 70 + 2;
    xpos = xpos + $("#iconselectsource1").offset().left
    ypos = ypos + $("#iconselectsource1").offset().top
    element.css("position", "relative")
    element.offset({ top: ypos, left: xpos })
}

function SwitchToText() {
    $("#tekstonlyversion").show();
    $("#selectwithicons").hide();
}

function SwitchToIcons() {
    //FIRST VISIBLE
    $("#selectwithicons").show();
    ClearIconPossition();
    setTimeout('postBackToBi()', 0);
    $("#tekstonlyversion").hide();
}

function ClearIconPossition() {
    $('input', '#tekstonlyversion').each(
            function() {
                $(this).removeAttr('checked');
            });

    $('.icondrag').each(function() {
        RestorePosition($(this));
    });
}

function initfirstpage() {
    //hide current text
    SwitchToIcons();

    $(".icondrag").draggable({
        revert: 'invalid'
    });

    tooltip("img", "draggablemouseovertooltip");

    $(".iconselect").droppable({
        activeClass: 'ui-state-hover',
        hoverClass: 'ui-state-active',
        drop: function(event, ui) {
            var source = ui.draggable
            var sourcid = $(source).attr('cbid');
            $('input[id=' + sourcid + ']').removeAttr('checked');
            RestorePosition(ui.draggable);
            setTimeout('postBackToBi()', 0);
        }
    });

    $(".iconselectdestination").droppable({
        activeClass: 'ui-state-hover',
        hoverClass: 'ui-state-active',
        drop: function(event, ui) {
            var source = ui.draggable
            var sourcid = $(source).attr('cbid');
            $('input[id=' + sourcid + ']').attr('checked', true);
            setTimeout('postBackToBi()', 0);
        }
    });

    setTimeout("ClearIconPossition();", 100);
    setTimeout("ClearIconPossition();", 500);
}







