/**********************************************************************/
/**********************************************************************/
/*********************** DRAG DROP LIBRARY ****************************/
/**********************************************************************/
/**********************************************************************/
var Dragger = "var eve=arguments.length?arguments[0]:event;" +
              "Drag.ox=eve.clientX-this.offsetLeft;" +
              "Drag.oy=eve.clientY-this.offsetTop;" +
              "this.fire=Drag.fire;this.fire();false;";
var Drag = {
    ox: 0, oy: 0,
    minx: null, maxx: null, miny: null, maxy: null,
    mode: 0,
    affine: null,
    initer: null,

    init: function(node, mode, minx, miny, maxx, maxy)
    {
        var retstr = "with(Drag) mode=" + mode + ",minx=" + minx + ",maxx=" + maxx
  			+ ",miny=" + miny + ",maxy=" + maxy + ";Drag.initer=1;" + Dragger;
        node.onmousedown = new Function("e", "return eval(\"" + retstr + "\")");
        return (Drag.initer = retstr);
    },
    add: function(node) { node.out = Drag.out; node.out(null); },
    fire: function()
    {
        var that = this;
        that.run = Drag.run;
        that.out = Drag.out;
        that.style.position = "absolute";
        that.onmousedown = null;
        that.onmouseup = function(e) { return that.out(e); };
        document.onmouseup = function(e) { return that.out(e); };
        document.onmousemove = function(e) { return that.run(e); };
        document.onmouseout = function(e)
        {
            var eve = e ? e : event;
            if (!eve.fromElement)
                eve.fromElement = eve.target, eve.toElement = eve.relatedTarget;
            if (!eve.toElement) that.out(e); return false;
        }; return false;
    },
    run: function(e)
    {
        repositionAfterDrag();
        var eve = e ? e : event;
        var nx = eve.clientX - Drag.ox;
        var ny = eve.clientY - Drag.oy;
        with (Drag)
        {
            if (minx) if (nx < minx) nx = minx;
            if (maxx) if (nx > maxx) nx = maxx;
            if (miny) if (ny < miny) ny = miny;
            if (maxy) if (ny > maxy) ny = maxy;
        } if (this.parentNode.style.position == "absolute")
        {
            nx = nx - this.parentNode.offsetLeft;
            ny = ny - this.parentNode.offsetTop;
        }
        if (Drag.mode < 2) this.style.left = nx + "px";
        if (!(Drag.mode % 2)) this.style.top = ny + "px";
        if (Drag.mode == 3 && Drag.affine)
            Drag.affine(this, nx, ny);
        repositionAfterDrag();
        return false;
    },

    out: function(e)
    {
        var invoker = null;
        document.onmousemove = null;
        document.onmouseup = null;
        document.onmouseout = null;
        this.onmouseup = null;
        with (Drag) { invoker = mode + "," + minx + "," + miny + "," + maxx + "," + maxy; }
        this.onmousedown = new Function("e", "return eval("
  			+ (Drag.initer ? "Drag.init(this," + invoker + ")" : "Dragger") + ")");
        with (Drag) { mode = 0, minx = null, maxx = null, miny = null, maxy = null; initer = null }
        return false;
    }
};


/**********************************************************************
**********************************************************************
*********************** START AISE LIBRARY ***************************
**********************************************************************
**********************************************************************/

//var globalStateForDragStorage = 1;

var elitechAise = function()
{
    this.state = 1;           /* default status */
    this.frame1 = "";          /* default waarde frame 1 */
    this.frame2 = "";          /* default waarde frame 2 */
    this.frame3 = "";          /* default waarde frame 3 */
    this.useIframeIEfix = false;       /* in IE liggen selectboxen en flash etc. altijd met de hoogste z-index. als deze optie op true wordt gezet, wordt achter de divs een iframe geplaatst. Dit iframe kan wel over deze controls heen worden gelegd. */
    this.loadingHTML = "... ..."    /* Tekst wordt getoond tijdens het laden */
    this.showDivSources = false;       /* voor debug/design true zetten */
    this.doPagePush = true;        /* aanzetten pagepush optie. Handig om uit te zetten tijdens ontwikkelfase */
    this.beoordeling = '0';            /* beoordeling goed is de defaultwaarde */
    this.handigeVragen = false;        /* maak gebruik van handige vragen */
    this.toonvraag = true;        /* De vraag herhalen in aise responsediv */
    this.pagepushiframe = false;       /* De pagepush uitvoeren naar een achtergrond frame (in geval van demo|testen) */

    this.lastReceived_uid = "";
    this.lastReceived_antwoord = "";
    this.lastReceived_recnr = "";
    this.lastReceived_html = "";
    this.lastReceived_category = "";
    this.lastQuestion = "";
    this.testing = false;
    this.feedbacktestfase = false;
    this.testing = false;
	this.StandaardTekst = "";
    this.defaultvraag = new Array();
    this.callback = "me.putXMLhere();";
    this.callbackFaqs = "me.fillFaqBox();";
    this.oScript = "";
    this.oScriptFaq = "";
    var me = this;
    //	this.Unanswered			=	"";

    this.convertTo = function()
    {
        me.lastReceived_antwoord = me.lastReceived_antwoord.replace(/&#/gi, "SPECIAL_SIGN");
        me.lastReceived_antwoord = me.lastReceived_antwoord.replace(/;/gi, "PUNT_KOMMA");
        //		me.Unanswered = me.Unanswered.replace(/&#/gi, "SPECIAL_SIGN");
        // 	me.Unanswered = me.Unanswered.replace(/;/gi, "PUNT_KOMMA");
    }
    this.convertFrom = function(value)
    {
        value = value.replace(/SPECIAL_SIGN/gi, "&#");
        value = value.replace(/PUNT_KOMMA/gi, ";");
        return value;
    }
    this.storeAllData = function()
    {
        me.convertTo();
        var aise = document.getElementById('tscs_status1div');
        top.window.name = "AISE -!-" + aise.style.top + ";" + aise.style.left + ";" + me.state + ";" + me.lastQuestion + ";" + me.lastReceived_antwoord // + ";" + me.Unanswered;
    }
    this.repositionFromStorage = function()
    {
        /*
        Zet aise op de juiste top en left.
        Zet status van de aise (1, 2 of 3)
        Zet vraag en antwoord
        */
        var aise = document.getElementById('tscs_status1div');
        var wname = top.window.name.split("-!-");
        if (wname[1])
        {
            var storage = wname[1].split(";");

            aise.style.top = storage[0];
            aise.style.left = storage[1];
            this.state = storage[2];
            this.lastQuestion = this.convertFrom(storage[3]);
            this.lastReceived_antwoord = this.convertFrom(storage[4]);
            //this.Unanswered            = this.convertFrom(storage[5]);

            //if (this.Unanswered != "") {
            //	document.getElementById('question').value = this.Unanswered;
            //	this.sendQuestion();
            //	return;
            //} else {
            //document.getElementById('tscs_question').value = this.lastQuestion;
            //document.getElementById('tscs_aiseResponseDiv').innerHTML = this.lastReceived_antwoord;
            if (this.toonvraag == true)
            {
                document.getElementById('tscs_aiseResponseDiv').innerHTML = "<strong>" + this.lastQuestion + "</strong><br /><div id='tscs_space'></div>" + this.lastReceived_antwoord;
            } else
            {
                document.getElementById('tscs_aiseResponseDiv').innerHTML = antwoord;
            }

            //}
            //document.getElementById('tscs_aiseResponseDiv').innerHTML = this.lastReceived_antwoord;
        }
        else
        {
            aise.style.top = this.defaultFromtop;
            aise.style.left = this.defaultFromLeft;
        }
        this.changeState();
        return true
    }
    this.changeState = function()
    {
        if (this.state == 1)
        {
            //document.getElementById('headerImageA').style.display='inline';
            //document.getElementById('headerImageB').style.display='none';
            document.getElementById('tscs_status1div').style.display = 'block';
            document.getElementById('tscs_status2div').style.display = 'none';
            document.getElementById('tscs_status3div').style.display = 'none';
            if (this.useIframeIEfix)
            {
                document.getElementById('tscs_status1frame').style.display = 'block';
                document.getElementById('tscs_status2frame').style.display = 'none';
                document.getElementById('tscs_status3frame').style.display = 'none';
            }
        }
        if (this.state == 2)
        {
            //document.getElementById('headerImageA').style.display='inline';
            //document.getElementById('headerImageB').style.display='inline';
            document.getElementById('tscs_status1div').style.display = 'block';
            document.getElementById('tscs_status2div').style.display = 'none';
            document.getElementById('tscs_status3div').style.display = 'none';
            if (this.useIframeIEfix)
            {
                document.getElementById('tscs_status1frame').style.display = 'block';
                document.getElementById('tscs_status2frame').style.display = 'none';
                document.getElementById('tscs_status3frame').style.display = 'none';
            }
            if (document.getElementById('tscs_aiseResponseDiv').innerHTML == '')
            {
                this.sendQuestionInit();
                return;
            }
            document.getElementById('tscs_question').focus();
        }
        if (this.state == 3)
        {
            //document.getElementById('headerImageA').style.display='inline';
            //document.getElementById('headerImageB').style.display='inline';
            document.getElementById('tscs_status1div').style.display = 'block';
            document.getElementById('tscs_status2div').style.display = 'block';
            document.getElementById('tscs_status3div').style.display = 'block'; // TONEN VOOR TEST_DIALOOG wordt dan display='';   verbergen =>  display='none';
            if (this.useIframeIEfix)
            {
                document.getElementById('tscs_status1frame').style.display = 'block';
                document.getElementById('tscs_status2frame').style.display = 'block';
                document.getElementById('tscs_status3frame').style.display = 'block';
            }
        }
    }
    this.changeStateFromTopDiv = function()
    {
        if ((this.state == 2) || (this.state == 3))
        {
            this.state = 1;
        } else
        {
            this.state = 2;
        }
        this.changeState();
    }
    this.parse = function()
    {
        document.write('<link rel="stylesheet" type="text/css" href="' + this.css + '">');
        if (this.showDivSources)
        {
            document.write('<textarea style="font-family: Verdana; font-size:11px;width:100%;height:33%">' + this.frame1 + "</textarea>");
            document.write('<textarea style="font-family: Verdana; font-size:11px;width:100%;height:33%">' + this.frame2 + "</textarea>");
            document.write('<textarea style="font-family: Verdana; font-size:11px;width:100%;height:33%">' + this.frame3 + "</textarea>");
        }
        document.write(this.frame1);
        document.write(this.frame2);
        document.write(this.frame3);
        var BROWSER_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
        if (!isGeldigeIE()) { this.useIframeIEfix = false; }
        if (this.useIframeIEfix)
        {
            var status1div = document.getElementById('tscs_status1div');
            document.write("<iframe name='tscs_status1frame' id='tscs_status1frame' frameborder='0' style='moz-opacity:.5;filter:alpha(opacity=0);display:none;z-index:900;position:absolute;' width='" + status1div.style.width + "' height='" + status1div.style.height + "'></iframe>");
            //var status2div = document.getElementById('status2div');
            //document.write("<iframe name='status2frame' id='status2frame' frameborder='0' style='moz-opacity:.5;filter:alpha(opacity=0);display:none;z-index:900;position:absolute;' width='" + status2div.style.width + "' height='" + status2div.style.height + "'></iframe>");
            //var status3div = document.getElementById('status3div');
            //document.write("<iframe name='status3frame' id='status3frame' frameborder='0' style='moz-opacity:.5;filter:alpha(opacity=0);display:none;z-index:900;position:absolute;' width='" + status3div.style.width + "' height='" + status3div.style.height + "'></iframe>");
        }
        window.onload = this.positionAiseOnLoadHandler;  // Na het laden aise initialiseren
        window.onunload = this.storeAllData;              // Opslaan positie, vraag en antwoord
        //window.onresize = "";
    }
    this.positionAiseOnLoadHandler = function()
    {
        /* initialiseer AISE onload */
        if (me.repositionFromStorage())
        {
            //repositionAfterDrag();
            //if (me.handigeVragen) {
            //}
        }
    }

    this.getFAQsFromDatabase = function()
    {
        //alert("show spinning loading image");
        document.getElementById('tscs_faq').innerHTML = this.loadingHTML;

        this.oScriptFaq = document.getElementById("ScriptTagID");
        var head = document.getElementsByTagName("head").item(0);
        if (this.oScriptFaq)
        {
            head.removeChild(this.oScriptFaq);
        }
        // Create object
        this.oScriptFaq = document.createElement("script");

        var catid = this.lastReceived_category;
        if (custom_welcome_ask)
        {
            catid = "0";
        }
        var callURL = this.faqProxyServer + '?cat=' + catid + '&count=' + 3;
        this.oScriptFaq.setAttribute("src", callURL);

        head.appendChild(this.oScriptFaq);
        var BROWSER_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
        if (BROWSER_IS_IE)
        {
            if (this.oScriptFaq.readyState == "loaded")
            {
                eval(this.callbackFaqs);
                this.oScriptFaq.onreadystatechange = null;
            } else
            {
                this.oScriptFaq.onreadystatechange = this.CheckFaqAgain;
            }
        } else
        {
            this.mozCheckLoops = 0;
            aise.mozCheckForFaq();
        }
    }

    this.mozCheckForFaq = function()
    {

        var chk = typeof (arrQA);
        if (typeof (arrQA) == "object")
        {
            if (arrQA.length == 0)
            {
                // Als antwoorden verwerkt zijn word deze variabele weer leeggemaakt t.b.v. deze controle.
                // Stop the loop after 5 seccons. 
                this.mozCheckLoops++;
                if (this.mozCheckLoops <= 5)
                {
                    //alert("Moz loop. this.mozCheckLoops: " + this.mozCheckLoops);
                    window.setTimeout("aise.mozCheckForFaq()", 1000);
                }
                else
                {
                    aise.fillFaqBox();
                }
            } else
            {
                aise.fillFaqBox();
            }
        } else
        {
            // Stop the loop after 5 seccons. 
            this.mozCheckLoops++;
            if (this.mozCheckLoops <= 5)
            {
                //alert("Moz loop. this.mozCheckLoops: " + this.mozCheckLoops);
                window.setTimeout("aise.mozCheckForFaq()", 1000);
            }
            else
            {
                aise.fillFaqBox();
            }
        }
    }

    this.CheckFaqAgain = function()
    {
        if (me.oScriptFaq.readyState == "loaded")
        {
            eval(me.callbackFaqs);
            me.oScriptFaq.onreadystatechange = null;
        }
    }
    this.fillFaqBox = function()
    {
        var table = "";
        var tableRows = "";
        for (var q = 0; q < arrQA.length; q++)
        {
            if (me.lastReceived_recnr + "" != arrQA[q][1] + "")
            {
                tableRows += "<tr>";
                tableRows += "   <td><img src='" + me.pagerBullet + "'></td>";
                tableRows += "   <td><a href='#' onClick='" + this.instanceName + ".sendQuestionSilently(\"" + arrQA[q][1] + "\", \"" + arrQA[q][0] + "\")'>" + arrQA[q][0] + "</a></td>";
                tableRows += "</tr>";
            }
        }

        if (tableRows == "")
        {
            // Get default questions
            for (var loop = 0; loop < this.defaultvraag.length; loop++)
            {
                tableRows += "<tr>";
                //tableRows += "   <td><font style='color: silver;'>.</font><img src='" + me.pagerBullet + "'></td>"; // for debugging - shows when you get default questions
                tableRows += "   <td><img src='" + me.pagerBullet + "'></td>";
                tableRows += "   <td><a href='#' onClick='" + this.instanceName + ".placeQuestionInInputBox(\"" + this.defaultvraag[loop] + "\")'>" + this.defaultvraag[loop] + "</a></td>";
                tableRows += "</tr>";
            }
            if (tableRows == "")
            {
                tableRows = ".";
            }
        }
        table = "<table border=0 cellpadding=3 cellspacing=0>" + tableRows + "</table>";
        var faqDiv = document.getElementById('tscs_faq');
        faqDiv.innerHTML = table;
    }

    this.placeQuestionInInputBox = function(question)
    {
        document.getElementById('tscs_question').value = question;
        this.sendQuestion();
    }

    this.vraagHandigeVraag = function(vraag)
    {
        document.getElementById('tscs_question').value = vraag;
        this.sendQuestion();
    }
    /*
    this.verwerkHandigeVragen = function(hvragen) {
    var faqDiv = document.getElementById('tscs_faq');
    alert('length=' + hvragen.length);

        if (hvragen.length > 0) {
    faqDiv.innerHTML = "";
    for (var loop = 0; loop < hvragen.length; loop++) {
    faqDiv.innerHTML = faqDiv.innerHTML + "<img style='cursor:pointer;' src='" + basicurl + "/img/pijl_vbvr.gif' border='0' /> <a href='#' onClick=\"" + this.instanceName + ".vraagHandigeVraag('" + hvragen[loop] + "')\">" + hvragen[loop] + '</a><br />'
    }
    }
    if (hvragen.length == 0) {
    for (var loop = 0; loop < this.defaultvraag.length; loop++) {
    faqDiv.innerHTML = faqDiv.innerHTML + "<img style='cursor:pointer;' src='" + basicurl + "/img/pijl_vbvr.gif' border='0' /> <a href='#' onClick=\"" + this.instanceName + ".vraagHandigeVraag('" + this.defaultvraag[loop] + "')\">" + this.defaultvraag[loop] + '</a><br />'
    }
    }

        if (faqDiv.innerHTML == "")
    faqDiv.innerHTML = "----------------- empty 2 ----------------";
    }
    */
    this.getDataFromServer = function(id, url, vraag)
    {
        this.oScript = document.getElementById(id);
        var head = document.getElementsByTagName("head").item(0);
        if (this.oScript)
        {
            // Destory object
            head.removeChild(this.oScript);
        }
        // Create object 
        this.oScript = document.createElement("script");
        var callURL = url + '?projectCode=' + this.projectCode + '&projectID=' + this.projectID + '&uid=' + this.lastReceived_uid + '&vraag=' + escape(vraag);
        this.oScript.setAttribute("src", callURL);

        head.appendChild(this.oScript);
        var antwoord = '';
        var BROWSER_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
        if (BROWSER_IS_IE)
        {
            if (this.oScript.readyState == "loaded")
            {
                eval(this.callback);
                this.oScript.onreadystatechange = null;
            } else
            {
                this.oScript.onreadystatechange = this.CheckAgain;
            }
        } else
        {
            //eval(this.callback); // <= zou moeten werken maar de waarden zijn dan toch nog niet geladen. timeout ingebouwd die iedere seconde opnieuw kijkt of het antwoord binnen is..
            aise.mozCheckAgain();
        }
    }
    this.mozCheckAgain = function()
    {
        var chk = typeof (antwoord);
        if (typeof (antwoord) == "string")
        {
            if (antwoord == "")
            {
                // Als antwoorden verwerkt zijn word deze variabele weer leeggemaakt t.b.v. deze controle.
                window.setTimeout("aise.mozCheckAgain()", 1000);
            } else
            {
                aise.putXMLhere()
            }
        } else
        {
            window.setTimeout("aise.mozCheckAgain()", 1000);
        }
    }
    this.CheckAgain = function()
    {
        if (me.oScript.readyState == "loaded")
        {
            eval(me.callback);
            me.oScript.onreadystatechange = null;
        }
    }
    var custom_welcome_ask = false;
    this.sendQuestion = function()
    {
        var q = document.getElementById('tscs_question').value;
        if (q.length > 160)
        {
            document.getElementById('tscs_aiseResponseDiv').innerHTML = "De vraag die u stelt is erg lang. Kunt u uw vraag korter en bondiger stellen, maximaal 160 characters, dan kan ik u beter helpen.";
        }
        else
        {
            document.getElementById('tscs_aiseResponseDiv').innerHTML = this.loadingHTML;
            custom_welcome_ask = false;
			var vrg = RemoveXSS(q);
			if (vrg != "" && vrg != this.StandaardTekst)
			{
				this.getDataFromServer("ScriptTagID", this.proxyServer, vrg);
			}
        }
    }

    this.sendQuestionSilently = function(questionID, question)
    {
        document.getElementById('tscs_question').value = RemoveXSS(question);
        document.getElementById('tscs_aiseResponseDiv').innerHTML = this.loadingHTML;
        custom_welcome_ask = false;
		this.getDataFromServer("ScriptTagID", this.proxyServer, "cs:" + questionID);
    }

    this.sendQuestionInit = function()
    {
        document.getElementById('tscs_aiseResponseDiv').innerHTML = this.loadingHTML;
        custom_welcome_ask = true;
        this.getDataFromServer("ScriptTagID", this.proxyServer, 'custom_welcome');
    }
    this.putXMLhere = function()
    {
        //this.Unanswered 		= 	"";
        this.lastReceived_uid = uid;
        this.lastReceived_antwoord = antwoord;
        this.lastReceived_recnr = recnr;
        this.lastReceived_html = html;
        this.lastReceived_category = category;
        this.lastQuestion = RemoveXSS(document.getElementById('tscs_question').value);

        if (this.toonvraag == true && this.lastQuestion != this.StandaardTekst)
        {
            document.getElementById('tscs_aiseResponseDiv').innerHTML = "<strong>" + this.lastQuestion + "</strong><br /><div id='tscs_space'></div>" + antwoord;
        } else
        {
            document.getElementById('tscs_aiseResponseDiv').innerHTML = antwoord;
        }
        // Get the FAQs
        this.getFAQsFromDatabase();
        //if (this.handigeVragen) {
        //   this.verwerkHandigeVragen(hvragen);
        //}
        if (html != "")
        {
            if (this.doPagePush)
            {
                if (this.pagepushiframe == true)
                {
                    if (document.getElementById("frame"))
                    {
                        document.getElementById("frame").src = html;
                    }
                } else
                {
                    document.location.href = html;
                }
            } else
            {
                document.getElementById('tscs_aiseResponseDiv').innerHTML += '<br /><br /><a href=' + html + '>Meer info</a>'
            }
        }

        /* Opmerkingen uitklappen na ontvangen van een antwoord */
        if (custom_welcome_ask == true)
        {
            //this.state = 2; 
        } else
        {
            if (this.testing)
            {
                this.state = 3;
            } else
            {
                this.state = 2;
            }
        }
        this.changeState();
        if (this.state > 1)
        {
            if (this.toonvraag == true)
            {
                document.getElementById('tscs_question').value = this.StandaardTekst;
				document.getElementById('tscs_question').className = "tscs_tekstinput_start";
                document.getElementById('tscs_question').focus();
            } else
            {
                document.getElementById('tscs_question').focus();
                document.getElementById('tscs_question').select();
            }
        }
        antwoord = ""; // Leegmaken ivm firefox wait <- Deze controlleerd of antwoord gezet is.
    }
    var bedankt_teller = 0;
    this.SendOpmerking = function()
    {
        //bedankt message 
        var checkboxJa = document.getElementById("tscs_beoordelingJa").checked;
        var checkboxNee = document.getElementById("tscs_beoordelingNee").checked;

        if ((!checkboxJa) && (!checkboxNee))
        {
            //melding tonen dat er ja of nee geklikt moet worden
            document.getElementById('tscs_div_warning').style.display = 'block';
        }
        else
        {
            var rsIframe = document.getElementById("RSIFrameOpmerking");
            var beoordeling = document.getElementsByName('tscs_beoordeling');

            var tmpuid = this.lastReceived_uid; tmpuid = tmpuid.replace(/\'/g, "`");
            var tmpant = this.lastReceived_antwoord; tmpant = tmpant.replace(/\'/g, "`"); tmpant = tmpant.replace(/\&\#/g, "|"); tmpant = tmpant.replace(/\&/g, " en ");
            var tmprec = this.lastReceived_recnr; tmprec = tmprec.replace(/\'/g, "`");
            var tmphtm = this.lastReceived_html; tmphtm = tmphtm.replace(/\'/g, "`");
            var tmpcat = this.lastReceived_category; tmpcat = tmpcat.replace(/\'/g, "`");
            var tmpque = this.lastQuestion; tmpque = tmpque.replace(/\'/g, "`"); tmpque = tmpque.replace(/\&\#/g, "|"); tmpque = tmpque.replace(/\&/g, " en ");
            var tmpopm = document.getElementById("tscs_invoerOpmerking").value; tmpopm = tmpopm.replace(/\'/g, "`"); tmpopm = tmpopm.replace(/\&/g, " en ");
            var tmptestfase = (me.feedbacktestfase == true) ? '1' : '0';

            var tmpscore = "";
            if (this.beoordeling == '0') { tmpscore = 'Ja' };
            if (this.beoordeling == '1') { tmpscore = 'Nee' };

            //BERT PROJECTID TOEVOEGEN
            //var url = this.opmerkingUrl + '?uid=' + tmpuid + '&vraag=' + tmpque + '&antwoord=' + tmpant + '&score=' + tmpscore + '&commentaar=' + tmpopm + '&pro=' + this.projectID;
            //var url = this.opmerkingUrl + '?uid=' + tmpuid + '&vraag=' + tmpque + '&antwoord=' + tmpant + '&commentaar=' + tmpopm + '&score=' + this.beoordeling + '&rec=' + tmprec + '&cat=' + tmpcat + '&pro=' + this.projectID;
            var url = this.opmerkingUrl +
			'?pro=' + this.projectID +
			'&uid=' + tmpuid +
			'&vraag=' + tmpque +
			'&antwoord=' + tmpant +
			'&rec=' + tmprec +
			'&cat=' + tmpcat +
			'&commentaar=' + tmpopm +
			'&score=' + this.beoordeling +
			'&testfase=' + tmptestfase;
            url = url.replace(/</g, "<_");

            if (rsIframe == null)
            {
                var iframe = document.createElement("iframe");
                iframe.setAttribute("src", url);
                iframe.setAttribute("id", "RSIFrameOpmerking");
                iframe.setAttribute("scrolling", "no");
                iframe.setAttribute("frameBorder", "5");
                iframe.setAttribute("width", "0");
                iframe.setAttribute("height", "0");
                document.body.appendChild(iframe);
            } else
            {
                rsIframe.src = url;
            }
            //document.getElementById('tscs_divInvoerOpmerking').style.display = 'none';
            //document.getElementById('tscs_opmerkingtitel').style.display = 'none';
            if (bedankt_teller > 1)
            {
                this.SendOpmerking2();
            }
            else
            {
                bedankt_teller = 1;
                bedankt_teller = bedankt_teller + 1;
                document.getElementById('tscs_div_bedankt').style.display = 'block';
                document.getElementById('tscs_div_warning').style.display = 'none';
                window.setTimeout("aise.SendOpmerking2()", 2000)
            }
        }
    }
    this.SendOpmerking2 = function()
    {
        this.state = 2;
        this.changeState();
        document.getElementById("tscs_beoordelingJa").checked = false;
        document.getElementById("tscs_beoordelingNee").checked = false;
        document.getElementsByName('tscs_beoordeling')[0].checked = false;
        document.getElementsByName('tscs_beoordeling')[1].checked = false;
        document.getElementById('tscs_invoerOpmerking').value = "";
        document.getElementById('tscs_div_bedankt').style.display = 'none';
        document.getElementById('tscs_div_warning').style.display = 'none';
    }
    this.changeBeoordeling = function(newValue)
    {
        this.beoordeling = newValue;
        if (this.beoordeling == '0')
        {
            //document.getElementById('divInvoerOpmerking').style.display = '';
            //document.getElementById('invoerOpmerking').innerHTML = "Ik ben goed geholpen omdat, ";
        } else
        {
            //document.getElementById('divInvoerOpmerking').style.display='';
            //if (this.beoordeling==1) {
            //	document.getElementById("invoerOpmerking").innerHTML = "Ik ben niet goed geholpen omdat, ";
            //}
        }
    }
}

/**********************************************************************/
/**********************************************************************/
/*********************** EINDE AISE LIBRARY ***************************/
/**********************************************************************/
/**********************************************************************/

function repositionAfterDrag()
{
    /* Positioneren van alle DIV's en iframeS relatief aan de div "status1div" */
    var MainDiv = document.getElementById('tscs_status1div');
    var MainPosLeft = MainDiv.style.left.replace('px', '');
    var MainPosTop = MainDiv.style.top.replace('px', '');
    var MainHeight = MainDiv.style.height.replace('px', '') * 1;
    var MainWidth = MainDiv.style.width.replace('px', '') * 1;
    /*
    var status2div        = document.getElementById('status2div');
    status2div.style.left = MainPosLeft + "px";
    status2div.style.top  = (MainPosTop*1)+MainHeight+1;

	var status3div        = document.getElementById('status3div');
    status3div.style.left = ((MainPosLeft - status3div.style.width.replace('px','') * 1) + 29) + "px";
    status3div.style.top  = (MainPosTop*1)+MainHeight;
    */
    if (aise.useIframeIEfix)
    {
        document.getElementById('tscs_status1frame').style.top = MainDiv.style.top;
        document.getElementById('tscs_status1frame').style.left = MainDiv.style.left;
        //document.getElementById('status2frame').style.top	= status2div.style.top;
        //document.getElementById('status2frame').style.left	= status2div.style.left;
        //document.getElementById('status3frame').style.top	= status3div.style.top;
        //document.getElementById('status3frame').style.left	= status3div.style.left;
    }
    //if (aise.state>1) {
    document.getElementById('tscs_question').focus();
    document.getElementById('tscs_question').select();
    //}
}

/*********************************************************************
*********************************************************************
*********************************************************************
**********************************************************************/

//var basicurl		= "http://192.168.1.99/";
var serverPath = "http://projecten.elitech.nl";
var basicurl = serverPath + "/zester/js";

var aise = new elitechAise();
aise.projectID 			= 65;         /* AISE projectID in de database*/
aise.instanceName 		= 'aise';     /* deze variabele niet veranderen */
aise.defaultFromtop 	= "0px";    /* startwaarde top van aise */
aise.defaultFromLeft 	= "0px";    /*307 startwaarde left van aise */
aise.defaultvraag[0] 	= "Wanneer ontvang ik het eerste tijdschrift van mijn nieuwe abonnement?";
aise.defaultvraag[1] 	= "Waar kan ik mijn abonnementsnummer vinden?";
aise.handigeVragen 		= true;  	  /* Maak gebruik van handige vragen */
aise.state 				= 2;     	  /* initiële status op klein blokje. */
aise.doPagePush 		= true; 	     /* indien false verschijnt onder het antwoord een link naar de page push pagina */
aise.proxyServer 		= basicurl + "/proxy.asp";
aise.faqProxyServer 	= basicurl + "/proxywebservice.asp";
aise.css 				= basicurl + "/sanna.css";
aise.opmerkingUrl 		= serverPath + "/receiveopmerkingen.aspx";
aise.pagerBullet 		= basicurl + "/img/pijl_vbvr.gif";
aise.loadingHTML 		= "<img src='" + basicurl + "/img/ajax-loader.gif' border='0' alt='Een moment geduld a.u.b.'>"
aise.showDivSources 	= false;      /* Debug only => laat content van de divs in textarea's zien. Handig tijdens opmaak van div's */
aise.useIframeIEfix 	= false;  	  /* aan uitzetten IE fix => wel of geen achterliggende iframes bij de divs. Div kan anders niet over selectboxen en flash heen liggen. */
aise.testing 			= true;      /* Wel of niet weergeven van de beoordelingsdiv na het krijgen van een antwoord; als niet aan, dan dus geen status3div */
aise.feedbacktestfase 	= false;
aise.pagepushiframe 	= false;
aise.toonvraag	 		= true;
aise.StandaardTekst 	= "Stel uw vraag kort en bondig."; //Gebruik voor het beste resultaat een korte vraag.
aise.mozCheckLoops 		= 0;

aise.frame1 += '<div id="tscs_status1div" class="tscs_status1DivStyle" style="display:block;position:relative;z-index:1000;">';
aise.frame1 += '	<div id="tscs_titel">Welkom bij Klantenservice</div><div id="tscs_subtext">Stel uw vraag aan Sanna</div>';
aise.frame1 += '	<div id="tscs_bgsanna">';
aise.frame1 += '		<div id="tscs_invoer">';
aise.frame1 += '			<div id="tscs_subtitel">Sanna beantwoordt al uw algemene vragen over tijdschriften en abonnementen</div>';
aise.frame1 += '			<div id="tscs_bginvoer"><input type="text" id="tscs_question" name="tscs_question" size="22" value="' + aise.StandaardTekst + '" class="tscs_tekstinput_start" onKeyPress="javascript:doTextClick();return checkEnter(event);" /></div>';
aise.frame1 += '			<div id="tscs_buttonstelvraag"><a href="#" class="tscs_stelvraag" onClick="aise.sendQuestion()"><img name="tscs_stelvraag" src="' + basicurl + '/img/stelvraag.gif" border="0" alt="Stel vraag" /></a></div>';
aise.frame1 += '			<div id="tscs_bgresponse"><div id="tscs_aiseResponseDiv"></div></div>';
aise.frame1 += '		</div>';
aise.frame1 += '	</div>';
aise.frame1 += '	<div id="tscs_bgfaq">';
aise.frame1 += '	<div id="tscs_titel2">Veelgestelde vragen</div>';


aise.frame1 += '	<div id="tscs_faq">';
/* Default questions */
aise.frame1 += '    	<table border=0 cellpadding=3 cellspacing=0>';
aise.frame1 += '    	<tr>';
aise.frame1 += "	       <td><img src='" + aise.pagerBullet + "'></td>";
aise.frame1 += "    	   <td><a href='#' onClick='aise.placeQuestionInInputBox(\"Waar kan ik mijn abonnementsnummer vinden?\")'>Waar kan ik mijn abonnementsnummer vinden?</a></td>";
aise.frame1 += '	    </tr>';
aise.frame1 += '    	<tr>';
aise.frame1 += "	       <td><img src='" + aise.pagerBullet + "'></td>";
aise.frame1 += "    	   <td><a href='#' onClick='aise.placeQuestionInInputBox(\"Hoe duur is een cadeauabonnement?\")'>Hoe duur is een cadeauabonnement?</a></td>";
aise.frame1 += '	    </tr>';
aise.frame1 += '	    </table>';
/*  */
aise.frame1 += '	</div>';

aise.frame1 += '	</div>';
aise.frame1 += '</div>';

aise.frame2 += '<div id="tscs_status2div" class="tscs_status2DivStyle" style="border:0px;display:none;position:relative;z-index:1000;top:0px;left:0px;width:0px;height:0px;">';
aise.frame2 += '</div>';

aise.frame3 += '<div id="tscs_status3div" style="position:relative;z-index:1000;display:none;">'; //top:336
aise.frame3 += '	<div id="tscs_bg"><div class="tscs_geholpen">Bent u goed geholpen?</div></div>';
aise.frame3 += '	<div id="tscs_beoordeling">';
aise.frame3 += '		<input type="radio" name="tscs_beoordeling" id="tscs_beoordelingJa" value="Ja" onClick="aise.changeBeoordeling(0)" />Ja<br />';
aise.frame3 += '		<input type="radio" name="tscs_beoordeling" id="tscs_beoordelingNee" value="Nee" onClick="aise.changeBeoordeling(1)" />Nee<br /><br />';
aise.frame3 += '	</div>';
aise.frame3 += '	<div id="tscs_waarombg">';
aise.frame3 += '		<div class="tscs_waarom">Waarom:</div><div class="tscs_optioneel">(optioneel)</div><br />';
aise.frame3 += '			<div id="tscs_invoerfb"><textarea id="tscs_invoerOpmerking" name="invoer" cols="20" rows="4" value=""></textarea></div>';
aise.frame3 += '	</div>';
aise.frame3 += '	<div id="tscs_opslaan"><button class="button" onClick="aise.SendOpmerking();">Opslaan</button></div>';
aise.frame3 += '	<div id="tscs_div_bedankt" style="display:none;"><strong>Bedankt voor uw deelname aan deze enqu&#234;te!</strong></div>';
aise.frame3 += '	<div id="tscs_div_warning" style="display:none;"><strong>Gelieve ja of nee te selecteren!</strong></div>';
aise.frame3 += '</div>';

aise.parse(); /* Start aise */



/**********************************************************************/
/************** zie ook aise.frame1/2/3 variabelen ********************/
/**********************************************************************/
function isIE50()
{
    return isIE5() && !isIE55();
}
function isIE()
{
    return navigator.userAgent.indexOf("MSIE") > -1;
}
function isIE55()
{
    return navigator.userAgent.indexOf("MSIE 5.5") > -1;
}
function isIE5()
{
    return navigator.userAgent.indexOf("MSIE 5") > -1;
}
function isIE6()
{
    return navigator.userAgent.indexOf("MSIE 6") > -1 && navigator.userAgent.indexOf("Opera") == -1;
}
function isIE7()
{
    return navigator.userAgent.indexOf("MSIE 7") > -1;
}
function isGeldigeIE()
{
    return isIE55() || isIE6() || isIE7();
}

function checkEnter(e)
{
    /*versturen van de vraag indien op enter toets wordt gedrukt*/
    var key;

    document.getElementById('tscs_question').className = "tscs_tekstinput";

    if (window.event)
    {
        key = window.event.keyCode; //IE
    } else
    {
        key = e.which;              //firefox
    }
    if (key == 13)
    {
        aise.sendQuestion();
        return false;
    }

}
function move_up()
{
    /* omhoog scrollen in de Faq div */
    document.getElementById('faq').scrollTop = document.getElementById('faq').scrollTop - 15;
}
function move_down()
{
    /* omlaag scrollen in de Faq div */
    document.getElementById('faq').scrollTop = document.getElementById('faq').scrollTop + 15;
}

pagerBulletPreload = new Image(); pagerBulletPreload.src = basicurl + "/img/pijl_vbvr.gif";
loaderPreload = new Image(); loaderPreload.src = basicurl + "/img/ajax-loader.gif";

function swap()
{
    if (document.images)
    {
        for (var x = 0; x < swap.arguments.length; x += 2)
        {
            document[swap.arguments[x]].src = eval(swap.arguments[x + 1] + ".src");
        }
    }
}

function doTextClick()
{
    if (document.getElementById('tscs_question').value == aise.StandaardTekst)
    {
        document.getElementById('tscs_question').value = "";
        document.getElementById('tscs_question').focus();
    }
}
function RemoveXSS(str)
{
	str = str.replace(/>/gi, " ").replace(/</gi, " ");          // '<' en '>'.
	str = str.replace(/%3e/gi, " ").replace(/%3c/gi, " ");      // url-encodering '<' en '>'.
	str = str.replace(/&#60;/gi, " ").replace(/&#62;/gi, " ");  // html-encodering '<' en '>'.
	str = str.replace(/javascript\:/gi, " ");                   // javascript-startstring.
	str = str.replace(/document\.\S/g, " ");                    // document-startstring.
	return str;
}