//send ajax request
function sendAjaxRequest(urlquery, elementname, handlername) 
{
    var ajaxHttp; //ajax http object
    var bMozilla = false; //is mozzila
        
    //supports activex
    if (window.ActiveXObject)
    {
        ajaxHttp = new ActiveXObject("Microsoft.XMLHTTP");
        if (ajaxHttp ==  null) { ajaxHttp = new ActiveXObject ("Msxml2.XMLHTTP"); }
    }
    else if (window.XMLHttpRequest)
    {
        ajaxHttp = new XMLHttpRequest(); bMozilla = true;
    }
    else
    {
        //http request not supported
        alert("The XMLHttpRequest nor ActiveXObject object could not be created.");
    }
    
    //prevent caching
    if (urlquery.indexOf("?") > -1) 
    urlquery += "&"; 
    else urlquery += "?";
    urlquery += "timestamp=" + new Date().getTime();
                    
    //handle server response
    ajaxHttp.onreadystatechange = function() {
        if (ajaxHttp.readyState == 4) {
            if (ajaxHttp.status == 200) //response OK
            {
                //set response text by elementname
                if (elementname != "") {
                    //if modal
                    if (elementname.indexOf("modal") > -1) {
                        $(elementname).innerHTML = ajaxHttp.responseText;
                    }
                    else {
                        //create new element
                        currentelement = $(elementname);
                        newelement = document.createElement(currentelement.tagName);
                        newelement.id = currentelement.id;
                        newelement.className = currentelement.className;
                        newelement.innerHTML = ajaxHttp.responseText;

                        //replace
                        currentelement.parentNode.replaceChild(newelement, currentelement);
                    }
                }

                //set response text by handlername
                if (handlername != "") eval(handlername + "(ajaxHttp.responseText)");
            }
        }
    }
    
    // open
    ajaxHttp.open("GET", urlquery, true); //asynchronous
    ajaxHttp.send(null); // send
}

//jobad reminder reload page
function handleJobAdReminder(responseText) {
    window.location.reload();
}

//Handles server's response: jobadrecommendation
function handleServerResponseJobAdRecommendation(responseText)
{    
    //types
    if(responseText.substring(0,1)==1)
     document.getElementById("ajaxjobadrecommendationtype").innerHTML = responseText.substr(1);
    //worktimes
    if(responseText.substring(0,1)==2)
        document.getElementById("ajaxjobadrecommendationworktime").innerHTML = responseText.substr(1);
    //worklocations
    if(responseText.substring(0,1)==3)
        document.getElementById("ajaxjobadrecommendationlocation").innerHTML = responseText.substr(1);
    //educations
    if(responseText.substring(0,1)==4)
        document.getElementById("ajaxjobadrecommendationeducation").innerHTML = responseText.substr(1);
    //workexperience
    if(responseText.substring(0,1)==5)
        document.getElementById("ajaxjobadrecommendationworkexperience").innerHTML = responseText.substr(1);
    //workarea
    if(responseText.substring(0,1)==6)
        document.getElementById("ajaxjobadrecommendationworkarea").innerHTML = responseText.substr(1);

    //hide table if recommendation added
    if(responseText.substr(1).indexOf("arialored11")<1)
        document.getElementById("table"+responseText.substring(0,1)).style.display="none";
}

//handle service type
function handleServiceType(responseText) {
    eval(responseText); //load json

    //set service type pos
    document.getElementById("servicetype" + results.articleid).innerHTML = results.pos;

    //set basket sum amount with tax
    document.getElementById("basket").innerHTML = results.basket;
}