/*
 * IR Script
 */
function checkAll(t,cl){ 
	$('input.'+cl).attr('checked',$(t).is(':checked')); 
	if($(t).is(':checked')){ 
		$('tr.row').addClass('checked'); 
	}else{
        	$('tr.row').removeClass('checked'); 
	}
}
function checkThis(t){ 
	t = $(t); 
	if(t.is(':checked')){ 
		t.parent().parent().addClass('checked');
	}else{
		t.parent().parent().removeClass('checked'); 
	}
}
function function_exists(function_name){ 
	return (typeof this.window[function_name] == 'function'); 
}
function notify(msg,type){ 


}
function massAction_unflagAccount(ids){ 
	var data = 'action=unflagAccounts&ids='+ids;
	$.ajax({
		data : data, 
		beforeSend:function(){ },
		success : function(data){ 
			ids = ids.split(","); 
			$.each(ids,function(key,value){ 
				$('tr.row#row'+value+' img.red-flag').remove(); 
				$('tr.row#row'+value).removeClass('flagged'); 
			}); 
		}
	}); 

}
function massAction_flagAccount(ids){ 
	var data = 'action=flagAccounts&ids='+ids;
	$.ajax({
		data : data, 
		beforeSend:function(){ },
		success : function(data){ 
			ids = ids.split(","); 
			$.each(ids,function(key,value){ 
				$('tr.row#row'+value).not('.flagged').children('td.affiliate').append('<img src="/images/red-flag.gif" class="red-flag" />'); 
				$('tr.row#row'+value).addClass('flagged'); 

			}); 
		}
	}); 

}
function massAction_createMassEmail(ids){ 
	var data = 'action=createMassEmail&ids='+ids;
	$.ajax({
		type : 'POST',
		url:'/ajax.php',
		data: data,  
		dataType : 'json', 
		error: function(request,textStatus,errorThrown){ 
			alert(textStatus); 
		},
		dataFilter: function(data){ 
		},
		success: function(data){ 
			/*
			 * returned data is the id # of the 
			 * inserted message
			 */ 
			window.location.href="/affiliate-message-detail.html?id="+data.response; 
		}
	}); 
		 
}
function runMassAction(t){ 
	var sel = Array(); 
	var n = 0; 
	$('tr.row.checked').each(function(index){ 
              sel[n++] = $(this).attr('id').substr(3);  
	}); 

	if(sel.length < 1){ 
		alert("You must select atleast one row to perform this action");
		t.options[t.selectedIndex].selected = false; 
		t.selectedIndex = 0;  
		return; 
	}
	ids = sel.join(","); 
	func = 'massAction_'+t.options[t.selectedIndex].value; 
	if(function_exists(func)){ 
		eval(func+'(ids);'); 
	}else{
		alert(func +' does not exist!'); 
	}	

	/*
	 * Return select back to the first (default) option
	 */
	t.selectedIndex = 0;  
}

