function addBookmark() 
{
	var bookmarkURL = window.document.URL;
	var bookmarkTitle = window.document.title;

	// IE
	if (window.external)
	{
		window.external.AddFavorite(bookmarkURL, bookmarkTitle);
	}
	// Opera
	else if (navigator.userAgent.indexOf('Opera') != -1)
	{
		alert(bookmarkNetscape.replace(/\{0\}/, "CTRL + T"));
	}
	// IE Mac
	else if (document.all && (navigator.userAgent.indexOf('Win') < 0))
	{
		alert(bookmarkNetscape.replace(/\{0\}/, "COMMAND + B"));
	}
	// Netscape / Mozilla
	else
	{
		alert(bookmarkNetscape.replace(/\{0\}/, "CTRL + D"));
	}
}

function loadurl(dest) {
 
 try {
  
   xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
  
 }
 catch (e) {
   // browser doesn't support ajax. handle however you want
 }
 
  if(dest == 'scripts/submit.php'){
	xmlhttp.onreadystatechange = triggered;
  }
  if(dest == 'scripts/form.php'){
	xmlhttp.onreadystatechange = triggered2;
  }

  if(dest == 'scripts/flag.php'){
	xmlhttp.onreadystatechange = triggered3;
  }
 
 // open takes in the HTTP method and url.
 xmlhttp.open("GET", dest);
 
 // send the request. if this is a POST request we would have
 // sent post variables: send("name=aleem&gender=male)
 // Moz is fine with just send(); but
 // IE expects a value here, hence we do send(null);
 xmlhttp.send(null);
 
}

function triggered() {
 
  // if the readyState code is 4 (Completed)
  // and http status is 200 (OK) we go ahead and get the responseText
  // other readyState codes:
  // 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
  if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
  
      // xmlhttp.responseText object contains the response.
      document.getElementById("submitholder").innerHTML =
  				xmlhttp.responseText;
   }
 
}

function triggered2() {
 
  if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
  
      // xmlhttp.responseText object contains the response.
      document.getElementById("outputholder").innerHTML =
  				xmlhttp.responseText;
   }
 
}

function triggered3() {
 
 if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
  
      // xmlhttp.responseText object contains the response.
      document.getElementById("flagholder").innerHTML =
  				xmlhttp.responseText;
   }
 
}

var http_request = false;
   
function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

	if(url == 'php/emaildone.php'){
		http_request.onreadystatechange = alertContents1;
	}
	if(url == 'php/submitdone.php'){
		http_request.onreadystatechange = alertContents2;
	}
	if(url == 'php/flagdone.php'){
		http_request.onreadystatechange = alertContents3;
	}
      
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

function alertContents1() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('outputholderholder').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

function alertContents2() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('submitholderholder').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

function alertContents3() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('flagholderholder').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get1(obj) {
      var poststr = "email=" + encodeURI( document.getElementById("email").value );
      
      makePOSTRequest('php/emaildone.php', poststr);
   }

   function get2(obj) {
      var poststr = "code=" + encodeURI( document.getElementById("code").value );
 	  poststr = poststr + "&artist=" + encodeURI( document.getElementById("artist").value );
  	  poststr = poststr + "&song=" + encodeURI( document.getElementById("song").value );
	  poststr = poststr + "&genre=" + encodeURI( document.getElementById("genre").value );

      makePOSTRequest('php/submitdone.php', poststr);
   }

   function get3(obj) {
      var poststr = "reason=" + encodeURI( document.getElementById("reason").value );

      makePOSTRequest('php/flagdone.php', poststr);
   }