//plug_cbkarma js

function rate(userid, myid, myip, myname, rate){

	var txt=document.getElementById('bgtext').value;

	if (txt == "Insert your user rating text here." || txt == ""  ) { 
		alert('Add some text here!');
		return false;
	}
//	alert(txt);
	var postVars = "my_id=" + myid + 
			"&user_id=" + userid +
			"&ip=" + myip +
			"&type=" + rate +
			"&my_name=" + myname +
			"&text=" + txt;
	
	document.getElementById('ratebox').innerHTML = "<h3>Loading...</h3>";
			
	new ajax('index2.php?option=com_rating&task=submitrating&no_html=1', {
		postBody: postVars,
		update: $('ratebox'),
		onComplete: function(){
		}
	});
}

function getdetails(userid, myid, myip, page, limit){
 
	var postVars = "my_id=" + myid + 
			"&user_id=" + userid +
			"&ip=" + myip +
			"&page=" + page +
			"&limit=" +limit;
			
	document.getElementById('details').innerHTML = "<h3>Loading...</h3>";
			
	new ajax('index2.php?option=com_rating&task=getdetails&no_html=1', {
		postBody: postVars,
		update: $('details'),
		onComplete: function(){
		}
	});
}

function reply(id, i, e, sendobj ) {

	 if ( document.getElementById )   { 
	 var obj = document.getElementById(id); 
	 document.getElementById('rId').value = e;
	 var cb_tabmain = document.getElementById('cb_tabmain');
	 }
	 else if  ( document.all )  { 
	 obj = document.all.item( id ); 
	 document.all.item( 'rId' ).value = e;
	 cb_tabmain = document.all.item( 'cb_tabmain');
	 }

	cur = findPos(sendobj);
	maintab = findPos(cb_tabmain);

	obj.style.left = ( cur[0] - maintab[0] - parseInt(obj.style.width)) + 50 +'px';
	obj.style.top = ( cur[1] - maintab[1]) + 'px';
	obj.style.position = 'absolute';
	obj.style.zIndex = '100';
	obj.style.visibility = 'visible';

}


function submit_reply(){
	var rtxt=document.getElementById('rtext').value;
	var rId=document.getElementById('rId').value;
		
	document.getElementById('details').innerHTML = "<h3>Loading...</h3>";
			
	new ajax('index2.php?option=com_rating&task=submit_reply&no_html=1', {
		postBody: "rtxt=" + rtxt+ "&rId="+rId,
		update: $('details'),
		onComplete: function(){
		}
	});



}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


