// AJAX Voting for PhotoRing.org
// Copyright 2008 Tom Hnatovsky (xomax.cz)
// Tested support in browsers: IE 6.0+, Opera 8+, Mozilla based browsers

var divrat;
var ulrat;
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp=false; } }
function myXMLHttpRequest() { var xmlhttplocal; try { xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP") } catch (E) { xmlhttplocal=false; } } if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') { try { var xmlhttplocal = new XMLHttpRequest(); } catch (e) { var xmlhttplocal=false; } } return(xmlhttplocal); }
function photoRate(vote, id_num, box) { var rat = null; divrat = null; ulrat = null; if (box) { rat = box.parentNode.parentNode.parentNode; if (rat) { divrat = rat.getElementsByTagName("div")[0]; divrat.innerHTML = '<img src="http://photoring.org/images/ajax-loader.gif" alt="Loading new stats" />'; ulrat = rat.getElementsByTagName("ul")[0]; } } xmlhttp.open('get', 'http://photoring.org/ajax.php?value='+vote+'&photoid='+id_num); xmlhttp.onreadystatechange = handleResponse; xmlhttp.send(null); return false; }
function handleResponse() { if(xmlhttp.readyState == 4){ if (xmlhttp.status == 200){ var response = xmlhttp.responseText; if (response == "V") { alert ("You have already voted for this picture!"); if (divrat) { divrat.innerHTML = "&times;"; } } else if ( response != "BI" && response != "BV" ) { if (divrat) { divrat.innerHTML = response; if (ulrat) { var rotten = Math.round(80 * response / 5); if (ulrat.childNodes[1]) { ulrat.childNodes[1].style.height = rotten+"px"; } } } } else { if (divrat) { divrat.innerHTML = "&times;"; } } } } return false; }