﻿// AJAX Functionality

function DoAjaxRequest(strURL, strQS, returnFunction) {
    var xmlHttpReq = false;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.setRequestHeader('currenturl', document.location.href);
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
            // Call complete, call the return function
            eval(returnFunction+"(xmlHttpReq.responseText);");
        }
    }
    xmlHttpReq.send(strQS);
}

// Execute any code between <script></script> tags returned from AJAX call
function Ajax_CheckScriptTags(intext) {
    var sText = new String(intext);
    var idx = sText.indexOf("<script>", 0);
    if (idx >= 0) {
        do {
            // Move offset for '<script>' length to just get inner code
            idx+=8;     
            // Find next close script tag
            var ide = sText.indexOf("</script>");
            // get script content between the tags
            var tCmd = sText.substring(idx, ide);
            // execute it
            eval(tCmd);
            // look for next match
            idx = sText.indexOf("<script>", ide);
        } while (idx >= 0 && idx < sText.length);
    }
}