/*
 * RoChk App
 *
 * version 1.0
 * last update 2009.04.10
 * 
 * by Davide 'Folletto' Casali <folletto AT gmail DOT com>
 * Copyright (C) 2009. Released under GNU/GPL.
 * 
 */

$(document).ready(function() {
  // nothing for now
});

var rochk = {
  
  doCheck: function() {
    // Main button
    var self = this;
    
    $("#result").html("<h2>Checking...</h2>");
    
    var url = $("#url").val();
    
    $.getJSON("api/check/googlebot/different-content", { url: url },
      function(data) {
        self.resultOneShot(data);
      }
    );
  },
  
  doKeyDown: function(e) {
    if (window.event) key = window.event.keyCode; // IE
  	else if (e) key = e.which; // Fx & more
  	else key = null;
    
  	if (key == 13) { // Enter key
  		this.doCheck();
  		return false; // avoids enter propagation
  	}
  },
  
  resultOneShot: function(data) {
    var result = "the two responses seem different...";
    if (data.result == "ok") {
      result = "the two responses seem ok."
    }
    $("#result").html('<h2>Result: <strong class="' + data.result + '">' + result + '</strong></h2> <small>' + Date() + '</small>' + '<div class="data"></div>');
    $("#result .data").html(data.data);
  }
}