var xmlHttp
function rating(value){var image_id=document.getElementById("image_id").value;var rating=value;if(rating!=parseInt(rating)||rating<1||rating>10){document.getElementById("actionResult").innerHTML="<span style=\"color:red\">Rating must be 1 to 10</span>";return;}
xmlHttp=GetXmlHttpObject();if(xmlHttp==null){alert("Browser does not support HTTP Request")
return}
try{var url="/postRating.php"
url=url+"?image_id="+image_id+"&rating="+rating;xmlHttp.onreadystatechange=ratingState
xmlHttp.open("GET",url,true)
xmlHttp.send(null)}
catch(e){document.getElementById("actionResult").innerHTML="<span style=\"color:red\">Error: "+ e+"</span>";}}
function favorite_add(){var image_id=document.getElementById("image_id").value;xmlHttp=GetXmlHttpObject();if(xmlHttp==null){alert("Browser does not support HTTP Request")
return}
try{var url="/favoriteActionNew.php"
url=url+"?image_id="+image_id+"&action=add";xmlHttp.onreadystatechange=favoriteStateAdd
xmlHttp.open("GET",url,true)
xmlHttp.send(null)}
catch(e){document.getElementById("actionResult").innerHTML="<span style=\"color:red\">Error: "+ e+"</span>";}}
function favorite_delete(){var image_id=document.getElementById("image_id").value;xmlHttp=GetXmlHttpObject();if(xmlHttp==null){alert("Browser does not support HTTP Request")
return}
try{var url="/favoriteActionNew.php"
url=url+"?image_id="+image_id+"&action=delete";xmlHttp.onreadystatechange=favoriteStateDelete
xmlHttp.open("GET",url,true)
xmlHttp.send(null)}
catch(e){document.getElementById("actionResult").innerHTML="<span style=\"color:red\">Error: "+ e+"</span>";}}
function add_tag(){var image_id=document.getElementById("image_id").value;var tag=document.getElementById("tag").value;xmlHttp=GetXmlHttpObject();if(xmlHttp==null){alert("Browser does not support HTTP Request")
return}
try{var url="/addTag.php"
url=url+"?image_id="+image_id+"&tag="+tag
xmlHttp.onreadystatechange=taggingState
xmlHttp.open("GET",url,true)
xmlHttp.send(null)}
catch(e){document.getElementById("actionResult").innerHTML="<span style=\"color:red\">Error: "+ e+"</span>";}}
function updateRating(){$('avgRatingValue').innerHTML=$('newAvgRating').innerHTML;$('rateImageValue').innerHTML=$('newRateImageValue').innerHTML;}
function updateTags(){var output=document.getElementById("newTagSection").innerHTML;document.getElementById("tagSection").innerHTML=output;document.getElementById("imageTagBox").style.display='none';document.getElementById("tag").value="";}
function updateFavoriteAdded(){var output='<div class="imageActionBox" style="background: url(http://www.theanimegallery.com/img/icons/favourite_remove.png) 0 0px no-repeat;">';output+='<a href="#" onclick="favorite_delete();">Remove from favs</a></div>';document.getElementById("favoriteAction").innerHTML=output;}
function updateFavoriteDeleted(){var output='<div class="imageActionBox" style="background: url(http://www.theanimegallery.com/img/icons/favourite_add.png) 0 0px no-repeat;">';output+='<a href="#" onclick="favorite_add();">Add to favorites</a></div>';document.getElementById("favoriteAction").innerHTML=output;}
function favoriteStateAdd()
{if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){document.getElementById("actionResult").innerHTML=xmlHttp.responseText;if(xmlHttp.responseText.indexOf("Success")>=0){updateFavoriteAdded();}}
else{document.getElementById("actionResult").innerHTML="Performing actions ..."}}
function favoriteStateDelete()
{if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){document.getElementById("actionResult").innerHTML=xmlHttp.responseText;if(xmlHttp.responseText.indexOf("Success")>=0){updateFavoriteDeleted();}}
else{document.getElementById("actionResult").innerHTML="Performing actions ..."}}
function ratingState()
{if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){document.getElementById("actionResult").innerHTML=xmlHttp.responseText;if(xmlHttp.responseText.indexOf("Success")>=0){updateRating();}}
else{document.getElementById("actionResult").innerHTML="Posting rating ..."}}
function taggingState()
{if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){document.getElementById("actionResult").innerHTML=xmlHttp.responseText;if(xmlHttp.responseText.indexOf("Success")>=0){updateTags();}}
else{document.getElementById("actionResult").innerHTML="Adding new tag ..."}}
function GetXmlHttpObject()
{var xmlHttp=null;try{xmlHttp=new XMLHttpRequest();}
catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}
return xmlHttp;}
