/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
  var request_type;
  var browser = navigator.appName;
  if(browser == "Microsoft Internet Explorer"){
    request_type = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    request_type = new XMLHttpRequest();
  }
  return request_type;
}

var http = createObject();










function loadContent(page, params, obj) {
    $("#"+obj).load(page + params);
}

function updateRecentLikeList() {
    var nocache = 0;
    nocache = Math.random();
    loadContent('recently_liked.php', '?ajax=true&nocache='+nocache, 'recentlyliked');
}
function updateHeadlines(slots) {
    var nocache = 0;
    nocache = Math.random();
    loadContent('headlines.php', '?ajax=true&slots='+slots+'&nocache='+nocache, 'headlines');
}
function updateRandomGamer() {
    var nocache = 0;
    nocache = Math.random();
    loadContent('randomgamer.php', '?ajax=true&nocache='+nocache, 'randomgamer');
}
function updateFeedList() {
    var nocache = 0;
    nocache = Math.random();
    loadContent('displayfeeds.php', '?ajax=true&nocache='+nocache, 'feedlist');
}
function updateTwitterList() {
    var nocache = 0;
    nocache = Math.random();
    loadContent('displaytwitters.php', '?ajax=true&nocache='+nocache, 'twitterlist');
}




//CODE TO DELETE POST ON SITE
function deletecomment(commentid) {
  var nocache = 0;
  nocache = Math.random();
  http.open('get', 'deletecomment.php?id='+commentid+'&nocache='+nocache);
  http.send(null);
}

//CODE TO UPDATE HEADLINES
function updatearticle(articleid,articletxt) {
  var nocache = 0;
  nocache = Math.random();
  http.open('get', 'updatearticle.php?articleid='+articleid+'&articletxt='+articletxt+'&nocache = '+nocache);
  http.send(null);
}

//CODE TO UPDATE LIKELIST
function deletelike(userid, topicid, like) {
  var nocache = 0;
  nocache = Math.random();
  http.open('get', 'unlike.php?userid='+userid+'&topicid=' +topicid+'&nocache='+nocache);
  http.onreadystatechange = deleteReply;
  http.send(null);
  if(document.getElementById('like'+topicid)) { document.getElementById('like'+topicid).style.display='inline'; }
  if(document.getElementById('liked'+topicid)) { document.getElementById('liked'+topicid).style.display='none'; }
  if(document.getElementById('reclike'+topicid)) { document.getElementById('reclike'+topicid).style.display='inline'; }
  if(document.getElementById('recliked'+topicid)) { document.getElementById('recliked'+topicid).style.display='none'; }
  if(document.getElementById('lllike'+topicid)) { document.getElementById('lllike'+topicid).style.display='inline'; }
  if(document.getElementById('llliked'+topicid)) { document.getElementById('llliked'+topicid).style.display='none'; }
}

//CODE TO UPDATE LIKELIST
function insert(userid, topicid, like) {
  var nocache = 0;
  nocache = Math.random();
  http.open('get', 'like.php?userid='+userid+'&topicid=' +topicid+'&nocache='+nocache);
  http.onreadystatechange = insertReply;
  http.send(null);
  if(document.getElementById('like'+topicid)) { document.getElementById('like'+topicid).style.display='none'; }
  if(document.getElementById('liked'+topicid)) { document.getElementById('liked'+topicid).style.display='inline'; }
  if(document.getElementById('reclike'+topicid)) { document.getElementById('reclike'+topicid).style.display='none'; }
  if(document.getElementById('recliked'+topicid)) { document.getElementById('recliked'+topicid).style.display='inline'; }
  if(document.getElementById('lllike'+topicid)) { document.getElementById('lllike'+topicid).style.display='none'; }
  if(document.getElementById('llliked'+topicid)) { document.getElementById('llliked'+topicid).style.display='inline'; }
  if(like == 1) {
    //jah('recentlyliked.php?ajax=true', 'recentlyliked');
  }
}
function insertReply() {
  if(http.readyState == 4){
    var response = http.responseText;
    document.getElementById('insert_response').style.display='block';
  }
}
function deleteReply() {
}



//CODE TO ADD TO FEED LIST
function addfeed(title,url) {
  var nocache = 0;
  nocache = Math.random();
  http.open('get', 'addfeed.php?title='+title+'&url='+url+'&nocache='+nocache);
  http.send(null);
}

//CODE TO ADD TO TWITTER LIST
function addtwitter(username) {
  var nocache = 0;
  nocache = Math.random();
  http.open('get', 'addtwitter.php?username='+username+'&nocache='+nocache);
  http.send(null);
}


function toggle(obj) {
    if(document.getElementById(obj).style.display == "none") {
        document.getElementById(obj).style.display = "block";
    } else if(document.getElementById(obj).style.display == "block") {
        document.getElementById(obj).style.display = "none";
    }
}
function toggleinl(obj) {
    if(document.getElementById(obj).style.display == "none") {
        document.getElementById(obj).style.display = "inline";
    } else if(document.getElementById(obj).style.display == "inline") {
        document.getElementById(obj).style.display = "none";
    }
}
