﻿var xmlhttp, flag = true;

function retrieveURL(url) {
    //debugger;
    if (window.XMLHttpRequest) // Non-IE browsers
    {
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = managestatechange;
        try {
            xmlhttp.open("GET", url, true);
        }
        catch (err) {
            alert(err);
        }
        xmlhttp.send(null);
    }
    else if (window.ActiveXObject)// IE
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp) {
            xmlhttp.onreadystatechange = managestatechange;
            xmlhttp.open("GET", url, true);
            xmlhttp.send();
        }
    }
}

var txt_obj, action_code;
function validate(txtobj, checkvalue_id, checkid_id, url, actioncode) {
    try {
        //debugger;
        txt_obj = txtobj;
        action_code = actioncode;
        var checkid = document.getElementById(txtobj.id.replace(checkvalue_id, checkid_id));
        var url = url + "?checkvalue=" + txtobj.value + "&checkid=" + checkid.innerHTML + "&actioncode=" + actioncode;
        retrieveURL(url);
        return flag;
    }
    catch (err) {

    }
}

function managestatechange() {
    //debugger;
    switch (xmlhttp.readyState) {
        case 2, 3:
            // Display a progress indicator of some kind, informing the
            // user that you are checking to see if the UserID exists
            //document.all.item("divProgress").style.display = "block";
            break;

        case 4:
            if (xmlhttp.responseText == "exist") {
                if (action_code == parseInt(1)) {
                    alert("Email ID already exist");
                }
                else if (action_code == parseInt(2)) {
                    alert("Username already exist");
                }
                else if (action_code == parseInt(3)) {
                    alert("Article Title already exist");
                }
                flag = false;
                return flag;
                //document.all.item("divProgress").style.display = "none";
            }
            break;
    }
}


