function sndReq(vote,loc_id,type_id) {
	var theUL = document.getElementById('unit_ul'+loc_id); // the UL
	
	// switch UL with a loading div
	theUL.innerHTML = '<div class="loading"></div>';	
	
	advAJAX.get({url: 'rate-ajax.php?v='+vote+'&i='+loc_id+'&t='+type_id, onSuccess : function(obj) {
    var response= obj.responseText;
    var update = new Array();
      if(response.indexOf('|') != -1) {
        update = response.split('|');
        changeText(update[0], update[1]);
      }
      }
  });
}

function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"
    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all[div2show].innerHTML = text;
    }
}

/* =============================================================== */
var ratingAction = {
		'a.rater' : function(element){
			element.onclick = function(){

			var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5');
			var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5');
			var parameterList = new Array();

			for (j = 0; j < parameterTokens.length; j++) {
				var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j
				var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1
				parameterList[parameterName] = parameterValue;
			}
			var theID = parameterList['i'];
			var theVote = parameterList['v'];
			var theType = parameterList['t'];
			
			//for testing	alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false;
			sndReq(theVote,theID,theType); return false;		
			}
		}
		
	};
Behaviour.register(ratingAction);
