function createXMLRequest()
{
        var xmlHttp;
        try
        {
                // Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
        }
        catch (e)
        {
                // Internet Explorer
                try
                {
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (f)
                {
                        try
                        {
                                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (g)
                        {
                                alert("Your browser does not support AJAX!");
                                return false;
                        }
                }
        }
        return xmlHttp;
}

function POSTRequest(obj) {
    var xmlHttp = createXMLRequest();

    var url = "http://www.machovideo.com/comments/include.php";
    var comment = obj.form.comment.value;
    var query = "page=&save=Submit+Comment&comment=" + encodeURI(comment);

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("comments");
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);
}

function POSTRequestId(obj, id) {
    var xmlHttp = createXMLRequest();

    var url = "http://www.machovideo.com/comments/include-articles.php";
    var comment = "";
    for(i=0;i<obj.form.elements.length;i++){ 
      if(obj.form.elements[i].name=="comment_" + id){ 
        comment= obj.form.elements[i].value; 
    }}
    var query = "page=&save=Submit+Comment&comment=" + encodeURI(comment) + "&articleid=" + encodeURI(id);

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("comments_" + id);
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);
}

function POSTLogin(obj) {
    var xmlHttp = createXMLRequest();

    var url = "http://www.machovideo.com/comments/login.php";
    var username = obj.form.username.value;
    var password = obj.form.password.value;
    var query = "username=" + encodeURI(username) + "&password=" + encodeURI(password);

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("comments");
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);
}

function POSTLoginId(obj, id) {
    var xmlHttp = createXMLRequest();

    var url = "http://www.machovideo.com/comments/login.php";
    var username = obj.form.username.value;
    var password = obj.form.password.value;
    var query = "username=" + encodeURI(username) + "&password=" + encodeURI(password) + "&articleid=" + encodeURI(id);

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("comments_" + id);
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);
}

function POSTRegister(obj) {
    var xmlHttp = createXMLRequest();

    var url = "http://www.machovideo.com/comments/newuser.php";
    var username = obj.form.new_username.value;
    var password1 = obj.form.password1.value;
    var password2 = obj.form.password2.value;
    var email = obj.form.email.value;
    var homepage = obj.form.homepage.value;
    var query = "username=" + encodeURI(username) + "&password1=" + encodeURI(password1) + "&password2=" + encodeURI(password2) + "&email=" + encodeURI(email) + "&homepage=" + encodeURI(homepage);

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("comments");
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);
}

function POSTRegisterId(obj, id) {
    var xmlHttp = createXMLRequest();

    var url = "http://www.machovideo.com/comments/newuser.php";
    var username = obj.form.new_username.value;
    var password1 = obj.form.password1.value;
    var password2 = obj.form.password2.value;
    var email = obj.form.email.value;
    var homepage = obj.form.homepage.value;
    var query = "username=" + encodeURI(username) + "&password1=" + encodeURI(password1) + "&password2=" + encodeURI(password2) + "&email=" + encodeURI(email) + "&homepage=" + encodeURI(homepage) + "&articleid=" + encodeURI(id);

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("comments_" + id);
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);
}

function showComments()
{
        var xmlHttp = createXMLRequest();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==4)
                {
                        var container = document.getElementById("comments");
                        container.innerHTML=xmlHttp.responseText;
                }
        };

        xmlHttp.open("GET","http://www.machovideo.com/comments/include.php",true);
        xmlHttp.send(null);
}

function getComments(id)
{
        var xmlHttp = createXMLRequest();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==4)
                {
                        var container = document.getElementById("comments_" + id);
                        container.innerHTML = xmlHttp.responseText;
                }
        };
        xmlHttp.open("GET","http://www.machovideo.com/comments/include-articles.php?articleid=" + id, true);
        xmlHttp.send(null);
}

function commentBanner()
{
        var xmlHttp = createXMLRequest();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==4)
                {
                        var container = document.getElementById("comments");
                        container.innerHTML=xmlHttp.responseText;
                }
        };

        xmlHttp.open("GET","http://www.machovideo.com/comments/commentbanner.php",true);
        xmlHttp.send(null);
}


function showLogin(id)
{
        var xmlHttp = createXMLRequest();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==4)
                {
                        var box = document.getElementById('commentall');
                        box.innerHTML = xmlHttp.responseText;
                }
        };
        xmlHttp.open("GET","http://www.machovideo.com/comment_login.php?article=" + id,true);
        xmlHttp.send(null);
}

function getRelatedPage(id, page)
{
        var xmlHttp = createXMLRequest();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==4)
                {
                        var container = document.getElementById("c3_b1_relatedvideos_result");
                        container.innerHTML = xmlHttp.responseText;
                }
        };
        xmlHttp.open("GET","http://www.machovideo.com/getrelated-own.php?articleid=" + id + "&page=" + page,true);
        xmlHttp.send(null);
}

function getCommentPage(id, page)
{
        var xmlHttp = createXMLRequest();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==4)
                {
                        var container = document.getElementById("commentsbox");
                        container.innerHTML = xmlHttp.responseText;
                }
        };
        xmlHttp.open("GET","http://www.machovideo.com/getcomments2.php?articleid=" + id + "&page=" + page,true);
        xmlHttp.send(null);
}

function postCommentToLoginV2(obj)
{
    var xmlHttp = createXMLRequest();

    var id = document.getElementById('article').value;
    var text = document.getElementById('comment_text').value;
    var url = "http://www.machovideo.com/comment_login.php";
    var query  = "article=" + encodeURI(id) + "&text=" + encodeURI(text);
	
    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("commentbox");
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);


}

function postLoginV2(obj) {
    var xmlHttp = createXMLRequest();

    var url = "http://www.machovideo.com/login.php";
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    var id = document.getElementById('article').value;
    var text = document.getElementById('comment_text').value;
    var query = "username=" + encodeURI(username) + "&password=" + encodeURI(password) + "&article=" + encodeURI(id) + "&text=" + encodeURI(text);

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("commentall");
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);
}

function postComment() {
    var xmlHttp = createXMLRequest();

    var url = "http://www.machovideo.com/comment_post.php";
    var id = document.getElementById('article').value;
    var text = document.getElementById('comment_text').value;
    var captcha = document.getElementById('captcha').value;
    var name = document.getElementById('name').value;
    var website = document.getElementById('website').value;
    var ref = document.getElementById('ref').value;
    var query = "id=" + encodeURI(id) + "&text=" + encodeURI(text) + "&article=" + encodeURI(id) + "&captcha=" + encodeURI(captcha) + "&name=" + encodeURI(name) + "&website=" + encodeURI(website) + "&ref=" + encodeURI(ref);

    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = function()
    {
            if(xmlHttp.readyState==4)
            {
                    var container = document.getElementById("commentbox");
                    container.innerHTML=xmlHttp.responseText;
            }
    };
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(query);
}

function refreshComments(id) {
        var xmlHttp = createXMLRequest();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==4)
                {
                        var container = document.getElementById("commentsbox");
                        container.innerHTML = xmlHttp.responseText;
                }
        };
        xmlHttp.open("GET","http://www.machovideo.com/getcomments.php?articleid=" + id,true);
        xmlHttp.send(null);

}

function doLogout(id) {
        var xmlHttp = createXMLRequest();
        xmlHttp.onreadystatechange=function()
        {
                if(xmlHttp.readyState==4)
                {
                        var container = document.getElementById("commentall");
                        container.innerHTML = xmlHttp.responseText;
                }
        };
        xmlHttp.open("GET","http://www.machovideo.com/comment.php?action=logout&articleid=" + id,true);
        xmlHttp.send(null);

}

function showCommentsPopup(id)
{
        window = window.open('http://www.machovideo.com/commentpopup.php?articleid=' + id, 'Comments', 'width=471, height=500, resizable=no, menubar=no, scrollbars=yes, status=no, toolbar=no');
}

