/* Autocompleter code */

function rc_formatItem(row) {
	return row[0];
}

function rc_formatResult(row) {
	return row[0].replace(/(<.+?>)/gi, '');
}

/*
 * autocompleter for edit
 */
function smsAutoCompleter(_elem, _id, _key, _mdbtid) {
	$(_elem).autocomplete('scripts.php?script=predictiveSearch&cat=club', {
		width :300,
		max :50,
		minChars :2,
		cacheLength :0,
		multiple :false,
		matchContains :false,
		formatItem :rc_formatItem,
		formatResult :rc_formatResult
	});

	$(_elem).result( function(event, data, formatted) {
		var _name 	= data[0];
		var _type 	= data[1];
		var _id 	= data[2];
		
		/* populate dropdown */
		if (_id){
			$('#club_id').val(_id);
			//alert("fff");
			smsFindTeams(_id,_mdbtid);
		}
		//console.log(data);
	});
};


/* 
 * Get the team dropdown for the selected club  
 */
function smsFindTeams(_id,_tid){
	$.ajax({
		type: 	'POST',
		url: 	'scripts.php?script=getClubTeams',
		data:	'club_id='+_id+'&mdb=1&mdbtid='+_tid,
		success: function(html){
			$('#team_selector').html(html);
		}
	});
};


function ShowSmsModal(_id,_name,_tid) {
	if(!_id)_id='';
	if(!_name)_name='';
	if(!_tid)_tid='';
	
	var _this = this;
//	alert(_url);
	$('#notify_content').html("<IFRAME src='/sms?canvas&clubid="+_id+"&club="+_name+"&mdbtid="+_tid+"' width='380px' height='440px' frameborder=0></IFRAME>");
	modal_base.init("error", "SMS alerts", "#notification", "OK", null,null,3);
	//alert(modal_base.init);
	$('#facebox.body').width("380");
	$('#facebox.body').height("450");

//alert($(window).width());

	$('#facebox').css('left', $(window).width()/3);
}





