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


function showHideLoadingAnimation(animId){
    var loadAnim = document.getElementById(animId);
    if (loadAnim){
        if (loadAnim.style.display=='none'){
            loadAnim.style.display='inline';
        } else {
            loadAnim.style.display='none';
        }
    }
}

function setAdCreditPerView(adtype,id,credit,loadId){
    showHideLoadingAnimation(loadId);
    // var loadForm = document.getElementById('loginForm');

    var xmlHttp = null;
    xmlHttp  = getXmlHttpObject();
    var url = './app/index/editad/positionBuying.php?from=ajax&adType=' + adtype + '&adId=' + id + '&credit=' + credit;
    var stamp = new Date();
    url = url + '&executionTimeToPreventCaching=' + stamp.getYear()+stamp.getMonth()+stamp.getDay()+stamp.getHours()+stamp.getMinutes()+stamp.getSeconds();
    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4){
                if (xmlHttp.status == 200) {
                    alert(xmlHttp.responseText);
                } else {
                    alert('Error, status: ' + xmlHttp.status +', response text: ' + xmlHttp.responseText);
                }
                showHideLoadingAnimation(loadId);
        }
    }
    xmlHttp.send(null);
}


