

function bodyOnload()
{
  // HIGHLIGHT COOKIE INFO
  new Effect.Highlight('cookie_info', {startcolor:'#EAEBED', endcolor:'#FAFB90'});
  // SHOW COLUMNS
  refreshLatest();
  refreshPositive();
  refreshNegative();
  refreshPopular();
  window.setInterval("refreshLatest()", 10000);
  window.setInterval("refreshPositive()", 20000);
  window.setInterval("refreshNegative()", 20000);
  window.setInterval("refreshPopular()", 20000);
  // PRELOAD NEEDED IMAGES
  var img1 = new Image();
  img1.src = 'images/biglietto-with-shadow-eng-trans.png';
  var img2 = new Image();
  img2.src = 'images/pannello_background-eng-trans.png';   
}function createXMLHttpRequest() 
{
  var xmlHttp; 
  if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
  if (window.ActiveXObject) xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
  return xmlHttp;
}

function hideCookie() {
$('biglietto').style.backgroundImage = 'url(images/biglietto-eng.gif)';
new Effect.Fade('biglietto', {duration: 0.6});
} function highlightStars(star) {

var lastStar = star;

for (var i =5; i >= lastStar; i--) {
$('star' + i).src="images/star_off-trans.png";
} 


for (var i =1; i <= lastStar; i++) {
$('star' + i).src="images/star_on-trans.png";
} 

}
function markInappropriate(cookie_id) {

var xmlHttp = createXMLHttpRequest();

var url = "back-end/ajax/inappropriate.php?timestamp=" + new Date().getTime();
var queryString;

queryString = "cookie_id=" + cookie_id;
queryString += '&lang=eng';

xmlHttp.open('POST', url, true);
xmlHttp.onreadystatechange = function() {
                                          if (xmlHttp.readyState == 4) {
                                            if (xmlHttp.status == 200) {
                                              if (xmlHttp.responseText == 'true') {
                                              alert('Thanks for reporting this!');
                                              }
                                              else alert(xmlHttp.responseText);
                                            }
                                          
                                          }
                                          };
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xmlHttp.send(queryString);

}

function markNegative(cookie_id) {

var xmlHttp = createXMLHttpRequest();

var url = "back-end/ajax/negative.php?timestamp=" + new Date().getTime();
var queryString;

var text = $('text').value;
queryString = "cookie_id=" + cookie_id;
queryString += '&lang=eng';

xmlHttp.open('POST', url, true);
xmlHttp.onreadystatechange = function() {
                                          if (xmlHttp.readyState == 4) {
                                            if (xmlHttp.status == 200) {
                                              if (xmlHttp.responseText == 'true') {
                                              alert('Thanks, fortune marked as negative!');
                                              new Effect.BlindUp('pannello', {duration: 0.8});
                                              pannello_visible = false;
                                              $('text').value="";
                                              }
                                              else alert(xmlHttp.responseText);
                                            }
                                          
                                          }
                                          };
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xmlHttp.send(queryString);

}

function markPositive(cookie_id) {

var xmlHttp = createXMLHttpRequest();

var url = "back-end/ajax/positive.php?timestamp=" + new Date().getTime();
var queryString;

var text = $('text').value;
queryString = "cookie_id=" + cookie_id;
queryString += '&lang=eng';

xmlHttp.open('POST', url, true);
xmlHttp.onreadystatechange = function() {
                                          if (xmlHttp.readyState == 4) {
                                            if (xmlHttp.status == 200) {
                                              if (xmlHttp.responseText == 'true') {
                                              alert('Thanks, fortune marked as positive!');
                                              new Effect.BlindUp('pannello', {duration: 0.8});
                                              pannello_visible = false;
                                              $('text').value="";
                                              }
                                              else alert(xmlHttp.responseText);
                                            }
                                          
                                          }
                                          };
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xmlHttp.send(queryString);

} 
function refreshLatest() {
  var xmlHttp = createXMLHttpRequest();
  var url = "back-end/ajax/refresh_latest.php?timestamp=" + new Date().getTime();
  var queryString;
  var text = $('text').value;
  queryString += '&lang=eng';
  xmlHttp.open('POST', url, true);
  xmlHttp.onreadystatechange = function() {
                                            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                                              $('column0').innerHTML = xmlHttp.responseText;
                                              return;
                                            }                                      
                                          };
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send(queryString);
}
function refreshNegative() {
  var xmlHttp = createXMLHttpRequest();
  var url = "back-end/ajax/refresh_negative.php?timestamp=" + new Date().getTime();
  var queryString;
  var text = $('text').value;
  queryString += '&lang=eng';
  xmlHttp.open('POST', url, true);
  xmlHttp.onreadystatechange = function() {
                                            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                                              $('column2').innerHTML = xmlHttp.responseText;
                                              return;
                                            }                                      
                                          };
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send(queryString);
}

function refreshPopular() {
  var xmlHttp = createXMLHttpRequest();
  var url = "back-end/ajax/refresh_popular.php?timestamp=" + new Date().getTime();
  var queryString;
  var text = $('text').value;
  queryString += '&lang=eng';
  xmlHttp.open('POST', url, true);
  xmlHttp.onreadystatechange = function() {
                                            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                                              $('column3').innerHTML = xmlHttp.responseText;
                                              return;
                                            }                                      
                                          };
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send(queryString);
}

function refreshPositive() {
  var xmlHttp = createXMLHttpRequest();
  var url = "back-end/ajax/refresh_positive.php?timestamp=" + new Date().getTime();
  var queryString;
  var text = $('text').value;
  queryString += '&lang=eng';
  xmlHttp.open('POST', url, true);
  xmlHttp.onreadystatechange = function() {
                                            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                                              $('column1').innerHTML = xmlHttp.responseText;
                                              return;
                                            }                                      
                                          };
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send(queryString);
}function resetStars() {

$('star1').src="images/star_off-trans.png";
$('star2').src="images/star_off-trans.png";
$('star3').src="images/star_off-trans.png";
$('star4').src="images/star_off-trans.png";
$('star5').src="images/star_off-trans.png";

}

function scrivi() {

var xmlHttp = createXMLHttpRequest();

var url = "back-end/ajax/scrivi.php?timestamp=" + new Date().getTime();
var queryString;

var text = $('text').value;
queryString = "text=" + text;
queryString += '&lang=eng';

 function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 } 

xmlHttp.open('POST', url, true);
xmlHttp.onreadystatechange = function() {
                                          if (xmlHttp.readyState == 4) {
                                            if (xmlHttp.status == 200) {
                                              if (isInt(xmlHttp.responseText)) {
                                              if (confirm('Thanks, your fortune was made! Would you like to see it?')) window.location = '?cookie=' + xmlHttp.responseText;
                                          else {
                                                new Effect.BlindUp('pannello', {duration: 0.8});
                                                pannello_visible = false;
                                                $('text').value="";
                                               }
                                              }
                                              else alert(xmlHttp.responseText);
                                            }                                         
                                          }
                                          };
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xmlHttp.send(queryString);

}
function showCookie() {
  var temp = navigator.appVersion.split('MSIE');
  var isIE6 = parseInt(temp[1]) <= 6 ? 1 : 0;
  new Effect.Appear('biglietto', {duration: 0.6});
  // show shadow (right after effect, for IE7)
  if (!isIE6) {
    window.setTimeout("$('biglietto').style.backgroundImage = 'url(images/biglietto-with-shadow-eng-trans.png)'", 600);
  }
}// lang menu
function showMenu() {
// show
if ($('showLangs').style.display == 'none') {
  $('showLangs').style.display='block'; 
  $('langArrow').src='images/change-lang-close-trans.png'; 
  return;
}
// hide
if ($('showLangs').style.display == 'block') {
  $('showLangs').style.display='none'; 
  $('langArrow').src='images/change-lang-trans.png'; 
  return;
}
}

function vote(cookie_id, stars) {

var xmlHttp = createXMLHttpRequest();

var url = "back-end/ajax/vote.php?timestamp=" + new Date().getTime();
var queryString;

queryString = "cookie_id=" + cookie_id + "&stars=" + stars;
queryString += '&lang=eng';

xmlHttp.open('POST', url, true);
xmlHttp.onreadystatechange = function() {
                                          if (xmlHttp.readyState == 4) {
                                            if (xmlHttp.status == 200) {
                                              if (xmlHttp.responseText == 'true') {
                                              $('stars').innerHTML = '<img src="images/thank_you-trans.png">';
                                              }
                                              else alert(xmlHttp.responseText);
                                              }                                        
                                            }
                                          };
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xmlHttp.send(queryString);

}