/* 
 * @version		1.5.0
 * @package		sobi2_plugin_ajax_rating_stand_alone
 * @author 		DreamWorks Studios
 * @author mail	admin[at]dwtutorials.com
 * @link		http://www.dwtutorials.com
 * @copyright	Copyright (C) 2009 DreamWorks Studios - All rights reserved.
 * @license		GNU/GPL
*/
function AjaxRatingSA(id_num,suffix,units,unitwidth,vote,vote_count,vote_total,fileName,ip,juri_base){
	var lsXmlHttp;
	//alert(id_num+','+suffix+','+units+','+unitwidth+','+vote+','+vote_count+','+vote_total+','+fileName+','+ip+','+juri_base);
	var textDivSA = document.getElementById('ajaxratingsa'+id_num+suffix);
	textDivSA.innerHTML='<img name="loading" src="'+juri_base+'/components/com_sobi2/plugins/ajaxratingsa/loading_images/'+fileName+'" border="0" align="absmiddle" alt="loading"/> Updating...';
	try	{
			lsXmlHttp=new XMLHttpRequest();
		} catch (e) {
			try	{ lsXmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try { lsXmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					alert("Your browser does not support AJAX!");
				}
			}
		}
	lsXmlHttp.onreadystatechange=function() {
		if(lsXmlHttp.readyState==4){
			setTimeout(function(){ 
				//alert(lsXmlHttp.responseText);
				if(lsXmlHttp.responseText==1){textDivSA.innerHTML='Thank You!';}
				else if(lsXmlHttp.responseText==2){textDivSA.innerHTML='Vote Unsuccessful!';}
				else if(lsXmlHttp.responseText==3){textDivSA.innerHTML='You Have Already Voted Today!';}
				else if(lsXmlHttp.responseText==4){textDivSA.innerHTML='You Have Already Voted!';}
				else if(lsXmlHttp.responseText==5){textDivSA.innerHTML='You Must Log in to Vote!';}
				else {textDivSA.innerHTML='Unknown Error';}
			},500);
			setTimeout(function(){
				if(lsXmlHttp.responseText==1){
					var newcount = vote_count+1;
					var newtotal = vote_total + vote;
					var newavg = newtotal/newcount;
					if(newcount!=1)	{textDivSA.innerHTML='('+(newcount)+' '+'Votes'+')';}
					else {textDivSA.innerHTML='('+(newcount)+' '+'Vote'+')';}
					var current = newavg*unitwidth;
					document.getElementById('ratingsa'+id_num+suffix).style.width=current+'px';
				} else {
					if(vote_count!=1){	textDivSA.innerHTML='('+(vote_count)+' '+'Votes'+')';}
					else {textDivSA.innerHTML='('+(vote_count)+' '+'Vote'+')';}
				}
			},2000);
		}
	}			
	lsXmlHttp.open("GET",juri_base+'/index.php?option=com_sobi2&sobi2Task=saveVoteSA&id='+id_num+'&u='+units+'&v='+vote+'&ip='+ip,true);
	lsXmlHttp.send(null);
}