var xmlHttp = xmlHttpRequest(); 

function rate_file_form (fileId) {
	document.getElementById('rate_file').innerHTML = '<form action="javascript:ratefile(' + fileId + ')" method="post" name="ratefile"><select name="rating"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select><input type="submit" value="Rate"/></form>';
}

function make_favourite(fileId, favourite_action) {
  if (xmlHttp == null) {
    return;
  }
  if (favourite_action == 'make') {
	xmlHttp.open('GET', 'http://www.isuc.net/file.php?a=make_favourite&f=' + fileId, true);
  } else {
    xmlHttp.open('GET', 'http://www.isuc.net/file.php?a=remove_favourite&f=' + fileId, true);
    document.getElementById("favourite_message").style.visibility = "hidden";
	document.getElementById("favourite_message").style.display = "none";
  }
  xmlHttp.onreadystatechange = process_make_favourite;
  xmlHttp.send(null);
}

function process_make_favourite() { 
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { 
    document.getElementById("make_favourite").innerHTML = xmlHttp.responseText;
  } 
}

function ratefile(fileId) {
  if (xmlHttp == null) {
    return;
  }
  
  xmlHttp.open('GET', 'http://www.isuc.net/file.php?f=' + fileId +'&action=rate&r=' + document.ratefile.rating.value, true);
  xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { 
      document.getElementById("rate_file").innerHTML = 'Thank You!';
    } 
  }
  xmlHttp.send(null);
}

function xmlHttpRequest() {
  var xmlHttp=null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}