﻿ function loadDataAtItsPlace(url,id) {
     
        if (window.XMLHttpRequest)
            xmlhttp=new XMLHttpRequest();
        else
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                var value = xmlhttp.responseText;
                     document.getElementById(id).innerHTML = value;
            }
            else {
                document.getElementById(id).innerHTML = "<div style=\"text-align:center;\"><img src='../Images/ajax-loader.gif'  alt='Loading....'/></div>";
            }
        }
        xmlhttp.open("GET",url,false);
        xmlhttp.send(null);
    }


    function authenticateUser(user) 
    {
    
        if (window.XMLHttpRequest)
            xmlhttp = new XMLHttpRequest();
        else
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
//            alert("second call");
                var value = xmlhttp.responseText;

                if (value == "Username / password incorrect. Please try again.") {
                    document.getElementById('message').innerHTML ="Responce from server:<br />"+ value;
                }
                else {
                    var s = value.split('*');
                    window.location = s[1];
                }
            }
            else {
                document.getElementById('message').innerHTML = "Authenticating...";
            }
        }
        xmlhttp.open("GET", "authenticateUser.aspx?details=" + user, false);
        xmlhttp.send(null);
       
    }

   
    
    
    function RemoveJobs(id)
    {
    if (window.XMLHttpRequest)
            xmlhttp=new XMLHttpRequest();
        else
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

        xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) 
            {
                loadDataAtItsPlace('getJobsHTML.aspx', 'jobsDataInDivisionByAjax');
            }
            else 
            {
             document.getElementById('jobsDataInDivisionByAjax').innerHTML = "<div style=\"text-align:center;\"><img src='../Images/ajax-loader.gif'  alt='Loading....'/></div>";
            }

        }
        xmlhttp.open("GET","removeJobsById.aspx?jobId="+id ,true);
        xmlhttp.send(null);
    }
