﻿function changeCommentClickEvent() {
    var MyPage = document.getElementsByTagName('body')[0].innerHTML;
    document.getElementsByTagName('body')[0].innerHTML = MyPage.replace("return ekcommentvalidate", "return NVekcommentvalidate");
}
function NVekcommentvalidate(uniqueid) {
    var sName = 'ekcommentname' + uniqueid;
    var sEmail = 'ekcommentemail' + uniqueid;
    var sText = 'ekcommenttext' + uniqueid;
    var sHidden = 'ekcommenttext_hidden' + uniqueid;
    var sBlogID = 'ekcommentpostid' + uniqueid;
    
    var sNameValue = document.getElementById(sName).value;
    var sEmailValue = document.getElementById(sEmail).value;
    var sCommentsValue = document.getElementById(sText).value;
    var nBlogID = document.getElementById(sBlogID).value;

    var sURL = 'http://www.eurodad.org/blog/sendCommentEmail.aspx?';
    var sQS = 'n=' + URLEncode(sNameValue) + '&e=' + URLEncode(sEmailValue) + '&m=' + URLEncode(sCommentsValue) + '&b=' + URLEncode(nBlogID) + '';
        
    if (ekcommentvalidate(uniqueid)) {
        var ret = pingUrl(sURL + sQS);
        return true;
    }
    return false;
}

function getHttpRequestObject() {
    var xmlhttp = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    @end@*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

function pingUrl(target) {
    var xmlHttp = getHttpRequestObject();
    if (xmlHttp) {
        xmlHttp.open("GET", target, true);
        xmlHttp.setRequestHeader("Man", "GET" + " " + target + " HTTP/1.1");
        xmlHttp.send(null);
        return xmlHttp.responseText;
    }
    else {
        return "No action done!";
    }
}

function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}

