/*
//
//+---------------------------------------------------------------+
//|                       RadFORUMS GOLD v1.0                     |
//|                           (May 2010)                          |
//|                  Copyright © 2010 RadScripts.com              |
//|                                                               |
//| File Name:       js-functions.js                              |
//| Email:            support@radscripts.com                      |
//| Website:          http://www.RadScripts.com                   |
//|                                                               |
//| Note: This script is NOT Freeware, and is NOT available for   |
//|     distribution or redistribution by anyone other than       |
//|     RadSCRIPTS.com. All terms, conditions and copyrights as   |
//|     defined in the RadScripts License Agreement WHICH YOU     |
//|     AGREED TO COMPLY WITH when you purchased this software    |
//|     must be adhered to.                                       |
//+---------------------------------------------------------------+
//
*/


function charCounter(idText,idCounter){
	var limit=$(idCounter).html();
	$(idText).bind("keyup mousedown change", function(){
	    if($(idText).val().length>limit){
	        $(idText).val($(idText).val().substring(0,limit));
	    }
	    $(idCounter).html( limit - $(idText).val().length   );
	});
	$(idText).trigger('change');
}


function ajax_addRole(uid,role,scope){
	$.post('index.php?a=ajax',
			{act:'doAddRole',
			 uid:uid,
			 role:role,
			 scope:scope
			},
			function(data){
				ajax_getRole(uid);
			}
	);
}

function ajax_getRole(uid){
	$.getJSON('index.php?a=ajax',
	  {act:'doGetRole',
	   uid: uid
	  },
	  function(data){
		if(data){
			$('#current_roles').html('');
			$.each(data,function(i,item){
				$('#current_roles').append('<li>'+item.role+' @ '+item.scopename
						+' <a href="javascript:void(0);" onclick="ajax_removeRole(\''+uid+'\',\''+item.role+'\',\''+item.scopetype+'\',\''+item.scopeid+'\');" >remove</a></li>');
			})
		}
	});
}

function ajax_removeRole(uid,role,scopetype,scopeid){
	$.post('index.php?a=ajax',
	  {act:'doRemoveRole',
	   uid:uid,
	   role:role,
	   scopetype:scopetype,
	   scopeid:scopeid
	  },
	  function(data){
		  ajax_getRole(uid);
	  });
}

function poll_add_more(c,limit){
    var max=$('#poll_options input:hidden:last').val();
    max=parseInt(max);
    for(var i=max+1;i<=Math.min(max+c,limit);i++){
       $('#poll_options').append(i+': <input type="hidden" class="poll_option_id" value="'+i+'" />')
       $('#poll_options').append('<input size="60" type="text" class="poll_optiion_value" name="polloptions[]" value="" /><br/>');
       if(i==limit)$('#poll_options').parent().find('input[name="add_more"]').hide();
    }


}
